diff --git a/Makefile b/Makefile index a19aedf37..c0ecbe292 100644 --- a/Makefile +++ b/Makefile @@ -70,55 +70,64 @@ all: build # http://linuxcommand.org/lc3_adv_awk.php .PHONY: help -help: ## Display this help. +help: ## Display this help. @awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST) ##@ Development .PHONY: manifests -manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects. +manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects. $(CONTROLLER_GEN) rbac:roleName=manager-role crd webhook paths="./..." output:crd:artifacts:config=config/crd/bases .PHONY: generate -generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations. +generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations. $(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..." +##@ Test + .PHONY: fmt -fmt: ## Run go fmt against code. +fmt: ## Run go fmt against code. go fmt ./... .PHONY: vet -vet: ## Run go vet against code. +vet: ## Run go vet against code. go vet ./... -.PHONY: test -test: fmt vet envtest ## Run tests. - KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)" go test -v -coverprofile=coverage.out -coverpkg ./... ./... +.PHONY: test-unit +test-unit: ## Run unit tests. + go test -v -coverprofile=coverage.out `go list ./controllers/... ./pkg/... | grep -v ./pkg/mocks` -.PHONY: unit-test-coverage -unit-test-coverage: test +.PHONY: test-coverage +test-coverage: test-unit ## Run unit tests and print code coverage. go tool cover -func coverage.out +.PHONY: test-integration +test-integration: ## Run integration tests. + KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)" go test -v -tags=integration ./... + +.PHONY: test +test: fmt vet envtest test-unit test-integration ## Run all tests (fmt, vet, envtest, unit & integration). + .PHONY: test-docker -test-docker: +test-docker: ## Run all tests (fmt, vet, envtest, unit & integration) inside a Docker container. docker build -t test -f test.Dockerfile . && docker run test ##@ Build .PHONY: build -build: generate fmt vet ## Build manager binary. +build: generate fmt vet ## Build manager binary. go build -o bin/manager main.go .PHONY: run -run: manifests generate fmt vet ## Run a controller from your host. +run: manifests generate fmt vet ## Run a controller from your host. go run ./main.go .PHONY: docker-build -docker-build: ## Build docker image with the manager. +docker-build: ## Build docker image with the manager. docker build -t ${IMG} . .PHONY: docker-push -docker-push: ## Push docker image with the manager. +docker-push: ## Push docker image with the manager. docker push ${IMG} ##@ Deployment @@ -140,36 +149,36 @@ ifndef ignore-not-found endif .PHONY: install -install: manifests kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config. +install: manifests kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config. $(KUSTOMIZE) build config/crd | kubectl apply -f - .PHONY: uninstall -uninstall: manifests kustomize ## Uninstall CRDs from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion. +uninstall: manifests kustomize ## Uninstall CRDs from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion. $(KUSTOMIZE) build config/crd | kubectl delete --ignore-not-found=$(ignore-not-found) -f - .PHONY: deploy -deploy: manifests kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config. +deploy: manifests kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config. cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG} $(KUSTOMIZE) build config/default | kubectl apply -f - .PHONY: undeploy -undeploy: ## Undeploy controller from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion. +undeploy: ## Undeploy controller from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion. $(KUSTOMIZE) build config/default | kubectl delete --ignore-not-found=$(ignore-not-found) -f - CONTROLLER_GEN = $(shell pwd)/bin/controller-gen .PHONY: controller-gen -controller-gen: ## Download controller-gen locally if necessary. +controller-gen: ## Download controller-gen locally if necessary. $(call go-get-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/controller-gen@latest) KUSTOMIZE = $(shell pwd)/bin/kustomize .PHONY: kustomize -kustomize: manifests ## Download kustomize locally if necessary. +kustomize: manifests ## Download kustomize locally if necessary. $(call go-get-tool,$(KUSTOMIZE),sigs.k8s.io/kustomize/kustomize/v3@v3.8.7) kustomize build config/default > deploy/kubeslice-operator.yaml ENVTEST = $(shell pwd)/bin/setup-envtest .PHONY: envtest -envtest: ## Download envtest-setup locally if necessary. +envtest: ## Download envtest-setup locally if necessary. $(call go-get-tool,$(ENVTEST),sigs.k8s.io/controller-runtime/tools/setup-envtest@latest) # go-get-tool will 'go get' any package $2 and install it to $1. @@ -187,23 +196,23 @@ rm -rf $$TMP_DIR ;\ endef .PHONY: bundle -bundle: manifests kustomize ## Generate bundle manifests and metadata, then validate generated files. +bundle: manifests kustomize ## Generate bundle manifests and metadata, then validate generated files. operator-sdk generate kustomize manifests -q cd config/manager && $(KUSTOMIZE) edit set image controller=$(IMG) $(KUSTOMIZE) build config/manifests | operator-sdk generate bundle -q --overwrite --version $(VERSION) $(BUNDLE_METADATA_OPTS) operator-sdk bundle validate ./bundle .PHONY: bundle-build -bundle-build: ## Build the bundle image. +bundle-build: ## Build the bundle image. docker build -f bundle.Dockerfile -t $(BUNDLE_IMG) . .PHONY: bundle-push -bundle-push: ## Push the bundle image. +bundle-push: ## Push the bundle image. $(MAKE) docker-push IMG=$(BUNDLE_IMG) .PHONY: opm OPM = ./bin/opm -opm: ## Download opm locally if necessary. +opm: ## Download opm locally if necessary. ifeq (,$(wildcard $(OPM))) ifeq (,$(shell which opm 2>/dev/null)) @{ \ @@ -234,12 +243,12 @@ endif # This recipe invokes 'opm' in 'semver' bundle add mode. For more information on add modes, see: # https://github.com/operator-framework/community-operators/blob/7f1438c/docs/packaging-operator.md#updating-your-existing-operator .PHONY: catalog-build -catalog-build: opm ## Build a catalog image. +catalog-build: opm ## Build a catalog image. $(OPM) index add --container-tool docker --mode semver --tag $(CATALOG_IMG) --bundles $(BUNDLE_IMGS) $(FROM_INDEX_OPT) # Push the catalog image. .PHONY: catalog-push -catalog-push: ## Push a catalog image. +catalog-push: ## Push a catalog image. $(MAKE) docker-push IMG=$(CATALOG_IMG) # Generate events schema map diff --git a/pkg/hub/controllers/cluster/deregister_unit_test.go b/pkg/hub/controllers/cluster/deregister_test.go similarity index 92% rename from pkg/hub/controllers/cluster/deregister_unit_test.go rename to pkg/hub/controllers/cluster/deregister_test.go index dde36f003..fac642a4b 100644 --- a/pkg/hub/controllers/cluster/deregister_unit_test.go +++ b/pkg/hub/controllers/cluster/deregister_test.go @@ -3,8 +3,6 @@ package cluster import ( "context" "errors" - "reflect" - "runtime/debug" "testing" hubv1alpha1 "github.com/kubeslice/apis/pkg/controller/v1alpha1" @@ -12,6 +10,7 @@ import ( kubeslicev1beta1 "github.com/kubeslice/worker-operator/api/v1beta1" utilmock "github.com/kubeslice/worker-operator/pkg/mocks" "github.com/prometheus/client_golang/prometheus" + "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" batchv1 "k8s.io/api/batch/v1" corev1 "k8s.io/api/core/v1" @@ -87,9 +86,7 @@ func TestGetOperatorClusterRole(t *testing.T) { mock.IsType(&rbacv1.ClusterRole{}), ).Return(nil) _, err := reconciler.getOperatorClusterRole(ctx) - if expected.err != err { - t.Error("Expected error:", expected.err, " but got ", err) - } + assert.ErrorIs(t, expected.err, err) } func TestCreateDeregisterJobPositiveScenarios(t *testing.T) { @@ -194,9 +191,7 @@ func TestCreateDeregisterJobPositiveScenarios(t *testing.T) { mock.IsType([]k8sclient.CreateOption(nil)), ).Return(nil) err := reconciler.createDeregisterJob(ctx, testClusterObj) - if expected.err != err { - t.Error("Expected error:", expected.err, " but got ", err) - } + assert.ErrorIs(t, expected.err, err) } func TestReconcilerFailToUpdateClusterRegistrationStatus(t *testing.T) { @@ -237,9 +232,7 @@ func TestReconcilerFailToUpdateClusterRegistrationStatus(t *testing.T) { ).Return(errors.New("error updating status of deregistration on the controller")) err := reconciler.createDeregisterJob(ctx, testClusterObj) - if expected.errMsg != err.Error() { - t.Error("Expected error:", expected.errMsg, " but got ", err) - } + assert.Equal(t, expected.errMsg, err.Error()) } func TestReconcilerFailToCreateServiceAccount(t *testing.T) { @@ -295,9 +288,7 @@ func TestReconcilerFailToCreateServiceAccount(t *testing.T) { ).Return(errors.New("unable to create service account")) err := reconciler.createDeregisterJob(ctx, testClusterObj) - if expected.errMsg != err.Error() { - t.Error("Expected error:", expected.errMsg, " but got ", err) - } + assert.Equal(t, expected.errMsg, err.Error()) } func TestReconcilerFailToFetchOperatorClusterRole(t *testing.T) { @@ -363,9 +354,7 @@ func TestReconcilerFailToFetchOperatorClusterRole(t *testing.T) { ).Return(errors.New("unable to fetch operator clusterrole")) err := reconciler.createDeregisterJob(ctx, testClusterObj) - if expected.errMsg != err.Error() { - t.Error("Expected error:", expected.errMsg, " but got ", err) - } + assert.Equal(t, expected.errMsg, err.Error()) } func TestReconcilerFailToCreateClusterRole(t *testing.T) { @@ -441,9 +430,7 @@ func TestReconcilerFailToCreateClusterRole(t *testing.T) { ).Return(errors.New("unable to create cluster role")) err := reconciler.createDeregisterJob(ctx, testClusterObj) - if expected.errMsg != err.Error() { - t.Error("Expected error:", expected.errMsg, " but got ", err) - } + assert.Equal(t, expected.errMsg, err.Error()) } func TestReconcilerFailToCreateClusterRoleBinding(t *testing.T) { @@ -524,9 +511,7 @@ func TestReconcilerFailToCreateClusterRoleBinding(t *testing.T) { ).Return(errors.New("unable to create cluster rolebinding")) err := reconciler.createDeregisterJob(ctx, testClusterObj) - if expected.errMsg != err.Error() { - t.Error("Expected error:", expected.errMsg, " but got ", err) - } + assert.Equal(t, expected.errMsg, err.Error()) } func TestReconcilerFailToCreateConfigmap(t *testing.T) { @@ -621,9 +606,7 @@ func TestReconcilerFailToCreateConfigmap(t *testing.T) { mock.IsType([]k8sclient.CreateOption(nil)), ).Return(errors.New("Unable to create configmap")) err := reconciler.createDeregisterJob(ctx, testClusterObj) - if expected.errMsg != err.Error() { - t.Error("Expected error:", expected.errMsg, " but got ", err) - } + assert.Equal(t, expected.errMsg, err.Error()) } func TestReconcilerFailToDeleteJob(t *testing.T) { @@ -729,9 +712,7 @@ func TestReconcilerFailToDeleteJob(t *testing.T) { ).Return(errors.New("Unable to delete deregister job")) err := reconciler.createDeregisterJob(ctx, testClusterObj) - if expected.errMsg != err.Error() { - t.Error("Expected error:", expected.errMsg, " but got ", err) - } + assert.Equal(t, expected.errMsg, err.Error()) } func TestReconcilerFailToCreateDeregisterJob(t *testing.T) { @@ -842,64 +823,42 @@ func TestReconcilerFailToCreateDeregisterJob(t *testing.T) { ).Return(errors.New("Unable to create deregister job")) err := reconciler.createDeregisterJob(ctx, testClusterObj) - if expected.errMsg != err.Error() { - t.Error("Expected error:", expected.errMsg, " but got ", err) - } + assert.Equal(t, expected.errMsg, err.Error()) } func TestGetConfigmapScriptData(t *testing.T) { data, err := getCleanupScript() - AssertNoError(t, err) - if len(data) == 0 { - t.Fatalf("unable to get configmap data") - } + assert.NoError(t, err) + assert.NotZero(t, len(data), "unable to get configmap data") } func TestConstructJobForClusterDeregister(t *testing.T) { job := constructJobForClusterDeregister() - AssertEqual(t, job.Name, deregisterJobName) - AssertEqual(t, job.Namespace, ControlPlaneNamespace) + assert.Equal(t, job.Name, deregisterJobName) + assert.Equal(t, job.Namespace, ControlPlaneNamespace) } func TestConstructServiceAccount(t *testing.T) { sa := constructServiceAccount() - AssertEqual(t, sa.Name, serviceAccountName) - AssertEqual(t, sa.Namespace, ControlPlaneNamespace) + assert.Equal(t, sa.Name, serviceAccountName) + assert.Equal(t, sa.Namespace, ControlPlaneNamespace) } func TestConstructClusterRole(t *testing.T) { cr := constructClusterRole(testOperatorClusterRole, "random-uid") - isEqual := reflect.DeepEqual(cr.Rules, testOperatorClusterRole.Rules) - if !isEqual { - t.Fatalf("got invalid data in clusterrole Rules: got -- %q want -- %q", &cr.Rules[0], &testOperatorClusterRole.Rules[0]) - } + assert.Equal(t, cr.Rules, testOperatorClusterRole.Rules) } func TestConstructClusterRoleBinding(t *testing.T) { crb := constructClusterRoleBinding("random-uid") - AssertEqual(t, crb.Name, clusterRoleBindingName) - AssertEqual(t, crb.RoleRef, testClusterRoleRef) - AssertEqual(t, len(crb.Subjects), 1) - AssertEqual(t, crb.Subjects[0], testClusterRoleBindingSubject[0]) + assert.Equal(t, crb.Name, clusterRoleBindingName) + assert.Equal(t, crb.RoleRef, testClusterRoleRef) + assert.Len(t, crb.Subjects, 1) + assert.Equal(t, crb.Subjects[0], testClusterRoleBindingSubject[0]) } func TestConstructConfigMap(t *testing.T) { data := "this is the data." cm := constructConfigMap(data) - AssertEqual(t, cm.Data["kubeslice-cleanup.sh"], data) -} - -func AssertEqual(t *testing.T, actual interface{}, expected interface{}) { - t.Helper() - if actual != expected { - t.Log("expected --", expected, "actual --", actual) - t.Fail() - } -} - -func AssertNoError(t *testing.T, err error) { - t.Helper() - if err != nil { - t.Errorf("Expected No Error but got %s, Stack:\n%s", err, string(debug.Stack())) - } + assert.Equal(t, cm.Data["kubeslice-cleanup.sh"], data) } diff --git a/pkg/hub/controllers/cluster/reconciler_unit_test.go b/pkg/hub/controllers/cluster/reconciler_test.go similarity index 98% rename from pkg/hub/controllers/cluster/reconciler_unit_test.go rename to pkg/hub/controllers/cluster/reconciler_test.go index 6a98a5371..0d6a454f9 100644 --- a/pkg/hub/controllers/cluster/reconciler_unit_test.go +++ b/pkg/hub/controllers/cluster/reconciler_test.go @@ -178,7 +178,7 @@ func TestReconcilerHandleExternalDependency(t *testing.T) { client.StatusMock.On("Update", mock.IsType(ctx), mock.IsType(&hubv1alpha1.Cluster{}), - mock.IsType([]k8sclient.UpdateOption(nil)), + mock.IsType([]k8sclient.SubResourceUpdateOption(nil)), ).Return(nil) client.On("List", mock.IsType(ctx), @@ -295,7 +295,7 @@ func TestReconcilerToFailWhileCallingCreateDeregisterJob(t *testing.T) { client.StatusMock.On("Update", mock.IsType(ctx), mock.IsType(&hubv1alpha1.Cluster{}), - mock.IsType([]k8sclient.UpdateOption(nil)), + mock.IsType([]k8sclient.SubResourceUpdateOption(nil)), ).Return(errors.New("error updating status of deregistration on the controller")) client.On("Create", mock.IsType(ctx), diff --git a/pkg/hub/controllers/slice_controller_unit_test.go b/pkg/hub/controllers/slice_controller_test.go similarity index 100% rename from pkg/hub/controllers/slice_controller_unit_test.go rename to pkg/hub/controllers/slice_controller_test.go diff --git a/pkg/hub/controllers/vpnkeyrotation/reconciler_unit_test.go b/pkg/hub/controllers/vpnkeyrotation/reconciler_test.go similarity index 99% rename from pkg/hub/controllers/vpnkeyrotation/reconciler_unit_test.go rename to pkg/hub/controllers/vpnkeyrotation/reconciler_test.go index 7006041b0..ab5b11ac2 100644 --- a/pkg/hub/controllers/vpnkeyrotation/reconciler_unit_test.go +++ b/pkg/hub/controllers/vpnkeyrotation/reconciler_test.go @@ -40,6 +40,8 @@ var ( testWorkerNamespace = "kubeslice-system" ) +var k8sClient k8sclient.Client + var testVPNKeyRotationObject = &hubv1alpha1.VpnKeyRotation{ ObjectMeta: metav1.ObjectMeta{ Name: testVPNKeyRotationName, diff --git a/pkg/manifest/manifest_suite_test.go b/pkg/manifest/manifest_suite_test.go deleted file mode 100644 index d710609d0..000000000 --- a/pkg/manifest/manifest_suite_test.go +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (c) 2022 Avesha, Inc. All rights reserved. - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package manifest_test - -import ( - "testing" - - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" -) - -func TestManifest(t *testing.T) { - RegisterFailHandler(Fail) - RunSpecs(t, "Manifest Suite") -} diff --git a/pkg/webhook/pod/pod_suite_test.go b/pkg/webhook/pod/pod_suite_test.go deleted file mode 100644 index bfac1c2eb..000000000 --- a/pkg/webhook/pod/pod_suite_test.go +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (c) 2022 Avesha, Inc. All rights reserved. - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package pod_test - -import ( - "testing" - - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" -) - -func TestDeploy(t *testing.T) { - RegisterFailHandler(Fail) - RunSpecs(t, "Deploy Webhook Suite") -} diff --git a/pkg/hub/controllers/cluster/cluster_controller_test.go b/tests/hub/cluster/cluster_controller_test.go similarity index 100% rename from pkg/hub/controllers/cluster/cluster_controller_test.go rename to tests/hub/cluster/cluster_controller_test.go diff --git a/pkg/hub/controllers/cluster/cluster_suite_test.go b/tests/hub/cluster/cluster_suite_test.go similarity index 96% rename from pkg/hub/controllers/cluster/cluster_suite_test.go rename to tests/hub/cluster/cluster_suite_test.go index c7b140b06..921df5640 100644 --- a/pkg/hub/controllers/cluster/cluster_suite_test.go +++ b/tests/hub/cluster/cluster_suite_test.go @@ -28,6 +28,7 @@ import ( kubeslicev1beta1 "github.com/kubeslice/worker-operator/api/v1beta1" ossEvents "github.com/kubeslice/worker-operator/events" "github.com/kubeslice/worker-operator/pkg/hub/controllers" + "github.com/kubeslice/worker-operator/pkg/hub/controllers/cluster" "github.com/prometheus/client_golang/prometheus" ) @@ -54,7 +55,7 @@ var _ = BeforeSuite(func() { By("bootstrapping test environment") testEnv = &envtest.Environment{ CRDDirectoryPaths: []string{ - filepath.Join("../../../..", "config", "crd", "bases"), + filepath.Join("../../../", "config", "crd", "bases"), filepath.Join("./crds"), }, ErrorIfCRDPathMissing: true, @@ -127,7 +128,7 @@ var _ = BeforeSuite(func() { Component: "worker-operator", Namespace: CONTROL_PLANE_NS, }) - clusterReconciler := NewReconciler( + clusterReconciler := cluster.NewReconciler( k8sClient, k8sClient, &spokeClusterEventRecorder, diff --git a/pkg/hub/controllers/cluster/crds/controller.kubeslice.io_clusters.yaml b/tests/hub/cluster/crds/controller.kubeslice.io_clusters.yaml similarity index 100% rename from pkg/hub/controllers/cluster/crds/controller.kubeslice.io_clusters.yaml rename to tests/hub/cluster/crds/controller.kubeslice.io_clusters.yaml diff --git a/tests/hub/cluster/crds/hub.kubeslice.io_clusters.yaml b/tests/hub/cluster/crds/hub.kubeslice.io_clusters.yaml new file mode 100644 index 000000000..99886028f --- /dev/null +++ b/tests/hub/cluster/crds/hub.kubeslice.io_clusters.yaml @@ -0,0 +1,209 @@ +--- +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition +metadata: + annotations: + controller-gen.kubebuilder.io/version: v0.11.1 + creationTimestamp: null + name: clusters.controller.kubeslice.io +spec: + group: controller.kubeslice.io + names: + kind: Cluster + listKind: ClusterList + plural: clusters + singular: cluster + scope: Namespaced + versions: + - name: v1alpha1 + schema: + openAPIV3Schema: + description: Cluster is the Schema for the clusters API + properties: + apiVersion: + description: 'APIVersion defines the versioned schema of this representation + of an object. Servers should convert recognized schemas to the latest + internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' + type: string + kind: + description: 'Kind is a string value representing the REST resource this + object represents. Servers may infer this from the endpoint the client + submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' + type: string + metadata: + type: object + spec: + description: ClusterSpec defines the desired state of Cluster + properties: + clusterProperty: + description: put in an object + properties: + geoLocation: + description: GeoLocation contains information regarding Geographical + Location of the Cluster + properties: + cloudProvider: + description: CloudProvider is the cloud service provider + type: string + cloudRegion: + description: CloudRegion is the region of the cloud + type: string + latitude: + description: Latitude is the latitude of the cluster + type: string + longitude: + description: Longitude is the longitude of the cluster + type: string + type: object + monitoring: + description: Monitoring contains the Kubernetes Monitoring Dashboard + properties: + kubernetesDashboard: + description: KubernetesDashboard contains the information + regarding Kubernetes Monitoring Dashboard + properties: + accessToken: + description: AccessToken is the Access Token to access + the KubernetesDashboard + type: string + enabled: + description: Enabled is the enable status of the KubernetesDashboard + type: boolean + endpoint: + description: Endpoint is the base endpoint to access the + kubernetes dashboard + type: string + ingressPrefix: + description: IngressPrefix is the prefix of ingress gateway + for KubernetesDashboard + type: string + type: object + type: object + telemetry: + description: Telemetry contains Telemetry information + properties: + enabled: + description: Enabled is the enable status of the Telemetry + type: boolean + endpoint: + description: Endpoint is the Telemetry Endpoint + type: string + telemetryProvider: + description: TelemetryProvider is the Telemetry Provider information + type: string + type: object + type: object + networkInterface: + description: NetworkInterface is the network interface attached with + the cluster. + type: string + nodeIP: + description: NodeIP is the IP address of the Node - deprecated field + use Plural NodeIPs + type: string + nodeIPs: + items: + type: string + type: array + type: object + status: + description: ClusterStatus defines the observed state of Cluster + properties: + clusterHealth: + description: ClusterHealth shows the health of the worker cluster + properties: + clusterHealthStatus: + description: ClusterHealthStatus shows the overall health status + of the cluster + enum: + - Normal + - Warning + type: string + componentStatuses: + description: ComponentStatuses shows the health status of individual + components in the cluster + items: + properties: + component: + description: Component name + type: string + componentHealthStatus: + enum: + - Normal + - Warning + - Error + type: string + required: + - component + - componentHealthStatus + type: object + type: array + lastUpdated: + description: LastUpdated is the timestamp when healthstatus was + updated + format: date-time + type: string + type: object + cniSubnet: + description: CniSubnet is the podip and service ip subnet of CNI + items: + type: string + type: array + isDeregisterInProgress: + description: IsDeregisterInProgress is the flag to check if the cluster + deregister is InProgress + type: boolean + namespaces: + description: Namespaces present in cluster + items: + properties: + name: + type: string + sliceName: + type: string + type: object + type: array + networkPresent: + default: false + description: NetworkPresent denotes if the networking components (NSM, + Spire) are installed on a cluster + type: boolean + nodeIPs: + description: NodeIPs of the gateway node of worker cluster + items: + type: string + type: array + registrationStatus: + description: RegistrationStatus shows the status of cluster registration + enum: + - Pending + - InProgress + - Failed + - Registered + - DeregisterInProgress + - DeregisterFailed + - Deregistered + type: string + secretName: + description: SecretName is the name of the secret for the worker cluster. + type: string + vCPURestriction: + description: VCPURestriction is the restriction on the cluster disabling + the creation of new pods + properties: + enforceRestrictions: + description: EnforceRestrictions is the flag to check if the cluster + is restricted + type: boolean + lastUpdatedTimestamp: + description: LastUpdatedTimestamp is the timestamp when the enforcement + was updated + format: date-time + type: string + type: object + type: object + type: object + served: true + storage: true + subresources: + status: {} diff --git a/pkg/hub/controllers/vpnkeyrotation/crds/controller.kubeslice.io_vpnkeyrotations.yaml b/tests/hub/vpnkeyrotation/crds/controller.kubeslice.io_vpnkeyrotations.yaml similarity index 100% rename from pkg/hub/controllers/vpnkeyrotation/crds/controller.kubeslice.io_vpnkeyrotations.yaml rename to tests/hub/vpnkeyrotation/crds/controller.kubeslice.io_vpnkeyrotations.yaml diff --git a/pkg/hub/controllers/vpnkeyrotation/crds/crd-ns.yaml b/tests/hub/vpnkeyrotation/crds/crd-ns.yaml similarity index 100% rename from pkg/hub/controllers/vpnkeyrotation/crds/crd-ns.yaml rename to tests/hub/vpnkeyrotation/crds/crd-ns.yaml diff --git a/pkg/hub/controllers/vpnkeyrotation/crds/crd-nse.yaml b/tests/hub/vpnkeyrotation/crds/crd-nse.yaml similarity index 100% rename from pkg/hub/controllers/vpnkeyrotation/crds/crd-nse.yaml rename to tests/hub/vpnkeyrotation/crds/crd-nse.yaml diff --git a/pkg/hub/controllers/vpnkeyrotation/crds/crd-workerslicegwrecycler.yaml b/tests/hub/vpnkeyrotation/crds/crd-workerslicegwrecycler.yaml similarity index 100% rename from pkg/hub/controllers/vpnkeyrotation/crds/crd-workerslicegwrecycler.yaml rename to tests/hub/vpnkeyrotation/crds/crd-workerslicegwrecycler.yaml diff --git a/pkg/hub/controllers/vpnkeyrotation/crds/networking.kubeslice.io_slicegateways.yaml b/tests/hub/vpnkeyrotation/crds/networking.kubeslice.io_slicegateways.yaml similarity index 100% rename from pkg/hub/controllers/vpnkeyrotation/crds/networking.kubeslice.io_slicegateways.yaml rename to tests/hub/vpnkeyrotation/crds/networking.kubeslice.io_slicegateways.yaml diff --git a/pkg/hub/controllers/vpnkeyrotation/crds/networking.kubeslice.io_slices.yaml b/tests/hub/vpnkeyrotation/crds/networking.kubeslice.io_slices.yaml similarity index 100% rename from pkg/hub/controllers/vpnkeyrotation/crds/networking.kubeslice.io_slices.yaml rename to tests/hub/vpnkeyrotation/crds/networking.kubeslice.io_slices.yaml diff --git a/pkg/hub/controllers/vpnkeyrotation/vpnrotation_ctrl_test.go b/tests/hub/vpnkeyrotation/vpnrotation_controller_test.go similarity index 98% rename from pkg/hub/controllers/vpnkeyrotation/vpnrotation_ctrl_test.go rename to tests/hub/vpnkeyrotation/vpnrotation_controller_test.go index febd85290..5ada19d6d 100644 --- a/pkg/hub/controllers/vpnkeyrotation/vpnrotation_ctrl_test.go +++ b/tests/hub/vpnkeyrotation/vpnrotation_controller_test.go @@ -11,6 +11,7 @@ import ( kubeslicev1beta1 "github.com/kubeslice/worker-operator/api/v1beta1" ossEvents "github.com/kubeslice/worker-operator/events" + "github.com/kubeslice/worker-operator/pkg/hub/controllers/vpnkeyrotation" nsmv1 "github.com/networkservicemesh/sdk-k8s/pkg/tools/k8s/apis/networkservicemesh.io/v1" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" @@ -75,7 +76,7 @@ var _ = Describe("Hub VPN Key Rotation", func() { ClusterGatewayMapping: map[string][]string{ CLUSTER_NAME: {gws[0]}, }, - Clusters: []string{ClusterName}, + Clusters: []string{vpnkeyrotation.ClusterName}, CertificateCreationTime: &metav1.Time{Time: time.Now()}, }, } @@ -178,7 +179,7 @@ var _ = Describe("Hub VPN Key Rotation", func() { ClusterGatewayMapping: map[string][]string{ CLUSTER_NAME: gws, }, - Clusters: []string{ClusterName}, + Clusters: []string{vpnkeyrotation.ClusterName}, CertificateCreationTime: &metav1.Time{Time: time.Now()}, CertificateExpiryTime: &metav1.Time{Time: time.Now().AddDate(0, 0, 30)}, RotationInterval: 30, @@ -517,7 +518,7 @@ var _ = Describe("Hub VPN Key Rotation", func() { ClusterGatewayMapping: map[string][]string{ CLUSTER_NAME: {gws[0]}, }, - Clusters: []string{ClusterName}, + Clusters: []string{vpnkeyrotation.ClusterName}, CertificateCreationTime: &metav1.Time{Time: time.Now()}, CertificateExpiryTime: &metav1.Time{Time: time.Now().AddDate(0, 0, 30)}, RotationInterval: 30, @@ -745,7 +746,7 @@ var _ = Describe("Hub VPN Key Rotation", func() { ClusterGatewayMapping: map[string][]string{ "worker-1": gws, }, - Clusters: []string{ClusterName}, + Clusters: []string{vpnkeyrotation.ClusterName}, CertificateCreationTime: &metav1.Time{Time: time.Now()}, }, } diff --git a/pkg/hub/controllers/vpnkeyrotation/vpnrotation_suite_test.go b/tests/hub/vpnkeyrotation/vpnrotation_suite_test.go similarity index 97% rename from pkg/hub/controllers/vpnkeyrotation/vpnrotation_suite_test.go rename to tests/hub/vpnkeyrotation/vpnrotation_suite_test.go index 45a027314..355a806f9 100644 --- a/pkg/hub/controllers/vpnkeyrotation/vpnrotation_suite_test.go +++ b/tests/hub/vpnkeyrotation/vpnrotation_suite_test.go @@ -33,6 +33,7 @@ import ( "github.com/kubeslice/worker-operator/controllers/slicegateway" ossEvents "github.com/kubeslice/worker-operator/events" "github.com/kubeslice/worker-operator/pkg/hub/controllers" + "github.com/kubeslice/worker-operator/pkg/hub/controllers/vpnkeyrotation" hub "github.com/kubeslice/worker-operator/pkg/hub/hubclient" hce "github.com/kubeslice/worker-operator/tests/emulator/hubclient" workernetop "github.com/kubeslice/worker-operator/tests/emulator/workerclient/netop" @@ -152,7 +153,7 @@ var _ = BeforeSuite(func() { if err != nil { os.Exit(1) } - rotationReconciler := NewReconciler( + rotationReconciler := vpnkeyrotation.NewReconciler( k8sClient, &hub.HubClientConfig{ Client: k8sClient, @@ -222,7 +223,7 @@ var _ = AfterSuite(func() { func shouldProcessVpnKeyRotation(object client.Object) bool { vpn := object.(*hubv1alpha1.VpnKeyRotation) for _, v := range vpn.Spec.Clusters { - if v == ClusterName { + if v == vpnkeyrotation.ClusterName { return true } } diff --git a/pkg/manifest/file_test.go b/tests/manifests/manifest_test.go similarity index 92% rename from pkg/manifest/file_test.go rename to tests/manifests/manifest_test.go index dd57865c8..a1d712a10 100644 --- a/pkg/manifest/file_test.go +++ b/tests/manifests/manifest_test.go @@ -19,6 +19,8 @@ package manifest_test import ( + "testing" + . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" @@ -26,6 +28,11 @@ import ( appsv1 "k8s.io/api/apps/v1" ) +func TestManifest(t *testing.T) { + RegisterFailHandler(Fail) + RunSpecs(t, "Manifest Suite") +} + var _ = Describe("Manifest File", func() { Context("With k8s deployment manifest", func() { diff --git a/pkg/webhook/pod/webhook_test.go b/tests/webhook/pod/pod_test.go similarity index 97% rename from pkg/webhook/pod/webhook_test.go rename to tests/webhook/pod/pod_test.go index 0ea9332e7..717d53360 100644 --- a/pkg/webhook/pod/webhook_test.go +++ b/tests/webhook/pod/pod_test.go @@ -20,17 +20,23 @@ package pod_test import ( "context" - - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" - "sigs.k8s.io/controller-runtime/pkg/client" + "testing" "github.com/kubeslice/apis/pkg/controller/v1alpha1" "github.com/kubeslice/worker-operator/controllers" "github.com/kubeslice/worker-operator/pkg/webhook/pod" + + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "sigs.k8s.io/controller-runtime/pkg/client" ) +func TestDeploy(t *testing.T) { + RegisterFailHandler(Fail) + RunSpecs(t, "Deploy Webhook Suite") +} + type fakeWebhookClient struct{} func (f fakeWebhookClient) UpdateSliceApplicationNamespaces(ctx context.Context, slice string, namespace string) error {