diff --git a/.github/workflows/ocm.yml b/.github/workflows/ocm.yml index 13000c2cf..23ea4ee3e 100644 --- a/.github/workflows/ocm.yml +++ b/.github/workflows/ocm.yml @@ -5,7 +5,7 @@ on: repository_dispatch: types: [ocm_changes] env: - GO_VERSION: '1.21' + GO_VERSION: '1.22' jobs: e2e-test: diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index dfd39a87f..75dbd4fe6 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -23,6 +23,27 @@ jobs: - name: verify run: make verify + unit-test: + runs-on: ubuntu-latest + env: + GOPATH: /tmp/go + steps: + - name: Set up Go + uses: actions/setup-go@v3 + with: + go-version: ${{ env.GO_VERSION }} + - name: Create GOPATH src directory + run: mkdir -p $GOPATH/src/github.com/open-cluster-management + - name: Check out code + uses: actions/checkout@v3 + with: + fetch-depth: 1 + - name: Copy the code into the GOPATH + run: cp -r . $GOPATH/src/github.com/open-cluster-management/clusteradm + - name: Unit Tests + working-directory: ${{ env.GOPATH }}/src/github.com/open-cluster-management/clusteradm + run: make test + integration-test: runs-on: ubuntu-latest steps: @@ -38,11 +59,9 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - - name: Set up Go uses: actions/setup-go@v3 with: go-version: ${{ env.GO_VERSION }} - - name: E2E Tests run: make test-e2e diff --git a/Makefile b/Makefile index 7cd0d59a6..ff0458590 100644 --- a/Makefile +++ b/Makefile @@ -100,7 +100,7 @@ check-copyright: @build/check-copyright.sh .PHONY: test -test: deps +test: deps ensure-kubebuilder-tools @build/run-unit-tests.sh .PHONY: clean-test diff --git a/pkg/cmd/create/sampleapp/exec_test.go b/pkg/cmd/create/sampleapp/exec_test.go index 167750447..2452684b4 100644 --- a/pkg/cmd/create/sampleapp/exec_test.go +++ b/pkg/cmd/create/sampleapp/exec_test.go @@ -21,20 +21,32 @@ import ( clusterapiv1 "open-cluster-management.io/api/cluster/v1" "open-cluster-management.io/clusteradm/pkg/cmd/addon/enable" - installScenario "open-cluster-management.io/clusteradm/pkg/cmd/install/hubaddon/scenario" + hubaddonscenario "open-cluster-management.io/clusteradm/pkg/cmd/install/hubaddon/scenario" + installscenario "open-cluster-management.io/clusteradm/pkg/cmd/install/hubaddon/scenario" + "open-cluster-management.io/clusteradm/pkg/version" ) // AddonOptions: options used for addon deployment type AddonOptions struct { - values Values -} - -// Values: The values used in the addons deployment template -type Values struct { - hubAddons []string + values hubaddonscenario.Values } var _ = ginkgo.Describe("deploy samepleapp to every managed cluster", func() { + var ( + ocmVersion = version.GetDefaultBundleVersion() + ocmBundleVersion = version.VersionBundle{} + ) + + ginkgo.BeforeEach(func() { + if bundleVersion, ok := os.LookupEnv("OCM_BUNDLE_VERSION"); ok && bundleVersion != "" { + ocmVersion = bundleVersion + } + + var err error + ocmBundleVersion, err = version.GetVersionBundle(ocmVersion) + gomega.Expect(err).ToNot(gomega.HaveOccurred()) + }) + var cluster1Name string var cluster2Name string var err error @@ -120,8 +132,10 @@ var _ = ginkgo.Describe("deploy samepleapp to every managed cluster", func() { ginkgo.By(fmt.Sprintf("installing %s addon", addon)) ao := AddonOptions{ - values: Values{ - hubAddons: []string{addon}, + values: hubaddonscenario.Values{ + HubAddons: []string{addon}, + Namespace: addonNamespace, + BundleVersion: ocmBundleVersion, }, } @@ -144,7 +158,7 @@ var _ = ginkgo.Describe("deploy samepleapp to every managed cluster", func() { files, err := addonPathWalkDir(appDir) gomega.Expect(err).ToNot(gomega.HaveOccurred(), "install addon error") - err = r.Apply(installScenario.Files, ao.values, files...) + err = r.Apply(installscenario.Files, ao.values, files...) gomega.Expect(err).ToNot(gomega.HaveOccurred(), "install addon error") fmt.Fprintf(streams.Out, "Installing built-in %s add-on to namespace %s.\n", addon, addonNamespace) @@ -176,9 +190,10 @@ var _ = ginkgo.Describe("deploy samepleapp to every managed cluster", func() { assertCreatingClusters(cluster2Name) o := Options{ - Streams: streams, - SampleAppName: testSampleAppName, - Namespace: testNamespace, + Streams: streams, + SampleAppName: testSampleAppName, + Namespace: testNamespace, + ClusteradmFlags: clusteradmFlags, } clusters := []string{cluster1Name, cluster2Name} diff --git a/pkg/cmd/create/sampleapp/scenario/sampleapp/placement.yaml b/pkg/cmd/create/sampleapp/scenario/sampleapp/placement.yaml index 62b81a9b2..aa04c3205 100644 --- a/pkg/cmd/create/sampleapp/scenario/sampleapp/placement.yaml +++ b/pkg/cmd/create/sampleapp/scenario/sampleapp/placement.yaml @@ -1,5 +1,5 @@ # Copyright Contributors to the Open Cluster Management project -apiVersion: cluster.open-cluster-management.io/v1alpha1 +apiVersion: cluster.open-cluster-management.io/v1beta1 kind: Placement metadata: name: {{.SampleAppName}}-placement diff --git a/pkg/cmd/create/sampleapp/suite_test.go b/pkg/cmd/create/sampleapp/suite_test.go index 2b585dd46..2bc41085f 100644 --- a/pkg/cmd/create/sampleapp/suite_test.go +++ b/pkg/cmd/create/sampleapp/suite_test.go @@ -5,24 +5,24 @@ import ( "path/filepath" "testing" - "k8s.io/apimachinery/pkg/api/meta" - "k8s.io/client-go/discovery" - "k8s.io/client-go/discovery/cached/memory" - "k8s.io/client-go/restmapper" - "k8s.io/client-go/tools/clientcmd" - clientcmdapi "k8s.io/client-go/tools/clientcmd/api" - "github.com/onsi/ginkgo/v2" "github.com/onsi/gomega" - apiextensionsclient "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset" + "k8s.io/apimachinery/pkg/api/meta" + "k8s.io/client-go/discovery" + "k8s.io/client-go/discovery/cached/memory" "k8s.io/client-go/dynamic" "k8s.io/client-go/kubernetes" "k8s.io/client-go/rest" - "sigs.k8s.io/controller-runtime/pkg/envtest" - + "k8s.io/client-go/restmapper" + "k8s.io/client-go/tools/clientcmd" + clientcmdapi "k8s.io/client-go/tools/clientcmd/api" + cmdutil "k8s.io/kubectl/pkg/cmd/util" addonv1alpha1client "open-cluster-management.io/api/client/addon/clientset/versioned" clusterv1client "open-cluster-management.io/api/client/cluster/clientset/versioned" + "sigs.k8s.io/controller-runtime/pkg/envtest" + + genericclioptionsclusteradm "open-cluster-management.io/clusteradm/pkg/genericclioptions" ) // nolint:deadcode,varcheck @@ -40,6 +40,7 @@ var apiExtensionsClient apiextensionsclient.Interface var dynamicClient dynamic.Interface var clusterClient clusterv1client.Interface var addonClient addonv1alpha1client.Interface +var clusteradmFlags *genericclioptionsclusteradm.ClusteradmFlags func TestIntegrationEnableAddons(t *testing.T) { gomega.RegisterFailHandler(ginkgo.Fail) @@ -54,8 +55,8 @@ var _ = ginkgo.BeforeSuite(func() { ErrorIfCRDPathMissing: true, CRDDirectoryPaths: []string{ filepath.Join("..", "..", "..", "..", "vendor", "open-cluster-management.io", "api", "cluster", "v1"), - filepath.Join("..", "..", "..", "..", "vendor", "open-cluster-management.io", "api", "cluster", "v1alpha1", "0000_03_clusters.open-cluster-management.io_placements.crd.yaml"), filepath.Join("..", "..", "..", "..", "vendor", "open-cluster-management.io", "api", "cluster", "v1beta1"), + filepath.Join("..", "..", "..", "..", "vendor", "open-cluster-management.io", "api", "cluster", "v1beta2"), filepath.Join("..", "..", "..", "..", "vendor", "open-cluster-management.io", "api", "addon", "v1alpha1"), }, } @@ -76,6 +77,10 @@ var _ = ginkgo.BeforeSuite(func() { gomega.Expect(err).NotTo(gomega.HaveOccurred()) restConfig = cfg + + // add clusteradm flags + f := cmdutil.NewFactory(TestClientGetter{cfg: cfg}) + clusteradmFlags = genericclioptionsclusteradm.NewClusteradmFlags(f) }) var _ = ginkgo.AfterSuite(func() { diff --git a/pkg/cmd/join/preflight/checks_test.go b/pkg/cmd/join/preflight/checks_test.go index 758911caa..645a262fb 100644 --- a/pkg/cmd/join/preflight/checks_test.go +++ b/pkg/cmd/join/preflight/checks_test.go @@ -43,7 +43,7 @@ func TestHubKubeconfigCheck(t *testing.T) { wantErrorList: []error{errors.New("--hub-apiserver should start with http:// or https://")}, }, { - name: "ca not validated", + name: "no ca", config: &clientcmdapiv1.Config{ Clusters: []clientcmdapiv1.NamedCluster{ { @@ -54,8 +54,8 @@ func TestHubKubeconfigCheck(t *testing.T) { }, }, }, - wantWarnings: nil, - wantErrorList: []error{errors.New("no ca detected, creating hub kubeconfig without ca")}, + wantWarnings: []string{"no ca detected, creating hub kubeconfig without ca"}, + wantErrorList: nil, }, }