Skip to content

Commit

Permalink
Added a util func for fetching operator version
Browse files Browse the repository at this point in the history
This utility function will be used to determine the installed version of the operator.

Signed-off-by: Ronny Baturov <[email protected]>
  • Loading branch information
rbaturov committed Dec 8, 2024
1 parent 9e664bb commit c477d81
Show file tree
Hide file tree
Showing 45 changed files with 7,242 additions and 3 deletions.
5 changes: 4 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ toolchain go1.22.8

require (
github.com/aquasecurity/go-version v0.0.0-20210121072130-637058cfe492
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2
github.com/drone/envsubst v1.0.3
github.com/go-logr/logr v1.4.2
github.com/google/go-cmp v0.6.0
Expand All @@ -22,6 +23,7 @@ require (
github.com/openshift/cluster-node-tuning-operator v0.0.0-20240611064827-2bd8891ead93
github.com/openshift/hypershift/api v0.0.0-20241115183703-d41904871380
github.com/openshift/machine-config-operator v0.0.1-0.20230724174830-7b54f1dcce4e
github.com/operator-framework/api v0.27.0
github.com/sergi/go-diff v1.1.0
github.com/stretchr/testify v1.9.0
golang.org/x/sync v0.8.0
Expand Down Expand Up @@ -90,13 +92,14 @@ require (
github.com/prometheus/client_model v0.6.1 // indirect
github.com/prometheus/common v0.55.0 // indirect
github.com/prometheus/procfs v0.15.1 // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/spf13/cobra v1.8.1 // indirect
github.com/spf13/pflag v1.0.6-0.20210604193023-d5e0c0615ace // indirect
github.com/stretchr/objx v0.5.2 // indirect
github.com/vincent-petithory/dataurl v1.0.0 // indirect
github.com/x448/float16 v0.8.4 // indirect
go.uber.org/ratelimit v0.2.0 // indirect
golang.org/x/exp v0.0.0-20231006140011-7918f672742d // indirect
golang.org/x/exp v0.0.0-20240213143201-ec583247a57a // indirect
golang.org/x/mod v0.17.0 // indirect
golang.org/x/net v0.30.0 // indirect
golang.org/x/oauth2 v0.21.0 // indirect
Expand Down
8 changes: 7 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1370,6 +1370,8 @@ github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio=
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs=
github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a/go.mod h1:lB+ZfQJz7igIIfQNfa7Ml4HSf2uFQQRzpGGRXenZAgY=
github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d h1:Byv0BzEl3/e6D5CLfI0j/7hiIEtvGVFPCZ7Ei2oq8iQ=
github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d/go.mod h1:WaHUgvxTVq04UNunO+XhnAqY/wQc+bxr74GqbsZ/Jqw=
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
Expand Down Expand Up @@ -1965,6 +1967,8 @@ github.com/openshift/hypershift/api v0.0.0-20241115183703-d41904871380/go.mod h1
github.com/openshift/machine-config-operator v0.0.1-0.20230724174830-7b54f1dcce4e h1:lgQ2Iy0NHk/iBaR9yvqSqROCiOovpkbc8MRYSIpHf+M=
github.com/openshift/machine-config-operator v0.0.1-0.20230724174830-7b54f1dcce4e/go.mod h1:xwAAOZMhwF91Ii8/yfOwp+yH5+GJS7VX90NI39RmSyo=
github.com/opentracing/opentracing-go v1.1.0/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o=
github.com/operator-framework/api v0.27.0 h1:OrVaGKZJvbZo58HTv2guz7aURkhVKYhFqZ/6VpifiXI=
github.com/operator-framework/api v0.27.0/go.mod h1:lg2Xx+S8NQWGYlEOvFwQvH46E5EK5IrAIL7HWfAhciM=
github.com/orisano/pixelmatch v0.0.0-20220722002657-fb0b55479cde/go.mod h1:nZgzbfBr3hhjoZnS66nKrHmduYNpc34ny7RK4z5/HM0=
github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc=
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
Expand Down Expand Up @@ -2058,6 +2062,7 @@ github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPx
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88=
github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
github.com/smartystreets/assertions v1.2.0 h1:42S6lae5dvLc7BrLu/0ugRtcFVjoJNMC/N3yZFZkDFs=
Expand Down Expand Up @@ -2267,8 +2272,9 @@ golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6/go.mod h1:3jZMyOhIsHpP37uCMk
golang.org/x/exp v0.0.0-20220827204233-334a2380cb91/go.mod h1:cyybsKvd6eL0RnXn6p/Grxp8F5bW7iYuBgsNCOHpMYE=
golang.org/x/exp v0.0.0-20230206171751-46f607a40771/go.mod h1:CxIveKay+FTh1D0yPZemJVgC/95VzuuOLq5Qi4xnoYc=
golang.org/x/exp v0.0.0-20230515195305-f3d0a9c9a5cc/go.mod h1:V1LtkGg67GoY2N1AnLN78QLrzxkLyJw7RJb1gzOOz9w=
golang.org/x/exp v0.0.0-20231006140011-7918f672742d h1:jtJma62tbqLibJ5sFQz8bKtEM8rJBtfilJ2qTU199MI=
golang.org/x/exp v0.0.0-20231006140011-7918f672742d/go.mod h1:ldy0pHrwJyGW56pPQzzkH36rKxoZW1tw7ZJpeKx+hdo=
golang.org/x/exp v0.0.0-20240213143201-ec583247a57a h1:HinSgX1tJRX3KsL//Gxynpw5CTOAIPhgL4W8PNiIpVE=
golang.org/x/exp v0.0.0-20240213143201-ec583247a57a/go.mod h1:CxmFvTBINI24O/j8iY7H1xHzx2i4OsyguNBmN/uPtqc=
golang.org/x/image v0.0.0-20180708004352-c73c2afc3b81/go.mod h1:ux5Hcp/YLpHSI86hEcLt0YII63i6oz57MZXIpbrjZUs=
golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
Expand Down
6 changes: 6 additions & 0 deletions test/e2e/upgrade/upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/openshift-kni/numaresources-operator/pkg/objectnames"
e2eclient "github.com/openshift-kni/numaresources-operator/test/utils/clients"
"github.com/openshift-kni/numaresources-operator/test/utils/objects"
"github.com/openshift-kni/numaresources-operator/test/utils/version"
machineconfigv1 "github.com/openshift/machine-config-operator/pkg/apis/machineconfiguration.openshift.io/v1"
)

Expand All @@ -25,6 +26,11 @@ var _ = Describe("Upgrade", Label("upgrade"), func() {
Expect(e2eclient.ClientsEnabled).To(BeTrue(), "failed to create runtime-controller client")
}
initialized = true
operatorVersion, err := version.OfOperator(context.TODO(), e2eclient.Client)
Expect(err).NotTo(HaveOccurred())
if operatorVersion.String() < "4.18" {
Skip("Upgrade suite is only supported on operator versions 4.18 or newer")
}
})

Context("after operator upgrade", func() {
Expand Down
4 changes: 4 additions & 0 deletions test/utils/clients/clients.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (

nropv1 "github.com/openshift-kni/numaresources-operator/api/numaresourcesoperator/v1"
"github.com/openshift-kni/numaresources-operator/test/utils/hypershift"
operatorsv1alpha1 "github.com/operator-framework/api/pkg/operators/v1alpha1"
)

var (
Expand Down Expand Up @@ -69,6 +70,9 @@ func init() {
if err := hypershiftv1beta1.AddToScheme(scheme.Scheme); err != nil {
klog.Exit(err.Error())
}
if err := operatorsv1alpha1.AddToScheme(scheme.Scheme); err != nil {
klog.Exit(err.Error())
}

var err error
Client, err = New()
Expand Down
29 changes: 29 additions & 0 deletions test/utils/version/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package version

import (
"context"
"fmt"

"sigs.k8s.io/controller-runtime/pkg/client"

"github.com/operator-framework/api/pkg/lib/version"
operatorsv1alpha1 "github.com/operator-framework/api/pkg/operators/v1alpha1"
)

var defaultNamespace = "numaresources-operator"

func OfOperator(ctx context.Context, cli client.Client) (*version.OperatorVersion, error) {
csvList := &operatorsv1alpha1.ClusterServiceVersionList{}

err := cli.List(context.TODO(), csvList, &client.ListOptions{
Namespace: defaultNamespace,
})

if err != nil {
return nil, fmt.Errorf("failed to fetch ClusterServiceVersion")
}
if len(csvList.Items) != 1 {
return nil, fmt.Errorf("expect only one CSV object under %s namespace", defaultNamespace)
}
return &csvList.Items[0].Spec.Version, nil
}
201 changes: 201 additions & 0 deletions vendor/github.com/operator-framework/api/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit c477d81

Please sign in to comment.