diff --git a/Makefile b/Makefile index 2f709ef8a..31f0fab29 100644 --- a/Makefile +++ b/Makefile @@ -17,7 +17,7 @@ MANIFEST_FILE=btp-manager.yaml # Image URL to use all building/pushing image targets IMG_REGISTRY_PORT ?= 5001 IMG_REGISTRY ?= k3d-kyma-registry:$(IMG_REGISTRY_PORT) -IMG ?= $(IMG_REGISTRY)/btp-manager:$(MODULE_VERSION) +IMG ?= europe-docker.pkg.dev/kyma-project/dev/btp-manager:PR-953 COMPONENT_CLI_VERSION ?= latest diff --git a/config/manager/kustomization.yaml b/config/manager/kustomization.yaml index deed35163..f451c44be 100644 --- a/config/manager/kustomization.yaml +++ b/config/manager/kustomization.yaml @@ -4,5 +4,5 @@ apiVersion: kustomize.config.k8s.io/v1beta1 kind: Kustomization images: - name: controller - newName: europe-docker.pkg.dev/kyma-project/prod/btp-manager - newTag: 0.0.23-test + newName: europe-docker.pkg.dev/kyma-project/dev/btp-manager + newTag: PR-953 diff --git a/controllers/btpoperator_controller.go b/controllers/btpoperator_controller.go index 770f22e61..d72228535 100644 --- a/controllers/btpoperator_controller.go +++ b/controllers/btpoperator_controller.go @@ -522,9 +522,9 @@ func (r *BtpOperatorReconciler) reconcileResources(ctx context.Context, managerS operatorSecret := resourcesToApply[secretIndex] operatorConfigMap := resourcesToApply[configMapIndex] - managementNamespace, err := r.resolveManagementNamespace(ctx, managerSecret, &logger) + namespace, err := r.resolveNamesapce(ctx, managerSecret, &logger) if err != nil { - return fmt.Errorf("failed to resolve namespace %s : %w", managementNamespace, err) + return fmt.Errorf("failed to resolve namespace %s : %w", namespace, err) } if err := r.reconcileSecrets(managerSecret, operatorSecret); err != nil { @@ -532,8 +532,8 @@ func (r *BtpOperatorReconciler) reconcileResources(ctx context.Context, managerS return fmt.Errorf("failed to set Secret %s values: %w", btpServiceOperatorSecret, err) } - logger.Info(fmt.Sprintf("propagating %s changes to secret: %s and config map : %s", SecretName, btpServiceOperatorSecret, btpServiceOperatorConfigMap)) - configMapChanged, clusterIdChanged, err := r.propagateManagerSecretChanges(ctx, managementNamespace, managerSecret, operatorConfigMap, &logger) + logger.Info(fmt.Sprintf("propagating %s changes to config map : %s", SecretName, btpServiceOperatorConfigMap)) + configMapChanged, clusterIdChanged, err := r.propagateManagerSecretChanges(ctx, namespace, managerSecret, operatorConfigMap, &logger) logger.Info(fmt.Sprintf("configMapChanged %t", configMapChanged)) if err != nil { logger.Error(err, fmt.Sprintf("propagating %s changes to secret: %s and config map : %s : %s", SecretName, btpServiceOperatorSecret, btpServiceOperatorConfigMap, err.Error())) @@ -541,8 +541,8 @@ func (r *BtpOperatorReconciler) reconcileResources(ctx context.Context, managerS } if configMapChanged { - logger.Info(fmt.Sprintf("setting %s secret namespace to %s", btpServiceOperatorSecret, managementNamespace)) - operatorSecret.SetNamespace(managementNamespace) + logger.Info(fmt.Sprintf("setting %s secret namespace to %s", btpServiceOperatorSecret, namespace)) + operatorSecret.SetNamespace(namespace) } logger.Info(fmt.Sprintf("applying module resources for %d resources", len(resourcesToApply))) @@ -621,7 +621,7 @@ func (r *BtpOperatorReconciler) propagateManagerSecretChanges(ctx context.Contex return namespaceChanged, clusterIdChanged, nil } -func (r *BtpOperatorReconciler) resolveManagementNamespace(ctx context.Context, managerSecret *corev1.Secret, logger *logr.Logger) (string, error) { +func (r *BtpOperatorReconciler) resolveNamesapce(ctx context.Context, managerSecret *corev1.Secret, logger *logr.Logger) (string, error) { managementNamespace := string(managerSecret.Data[managementNamespaceKey]) if managementNamespace == "" || managementNamespace == ChartNamespace { logger.Info(fmt.Sprintf("management namespace not set. using %s", ChartNamespace)) @@ -699,7 +699,7 @@ func (r *BtpOperatorReconciler) restartOperatorDeployment(ctx context.Context, l } labelSelector := metav1.FormatLabelSelector(deployment.Spec.Selector) - pods, err := podClient.List(context.TODO(), metav1.ListOptions{LabelSelector: labelSelector}) + pods, err := podClient.List(ctx, metav1.ListOptions{LabelSelector: labelSelector}) if err != nil { return fmt.Errorf("error listing pods: %v", err) } diff --git a/controllers/btpoperator_controller_secret_customization_test.go b/controllers/btpoperator_controller_secret_customization_test.go index eb31231d8..7b703ef62 100644 --- a/controllers/btpoperator_controller_secret_customization_test.go +++ b/controllers/btpoperator_controller_secret_customization_test.go @@ -2,6 +2,7 @@ package controllers import ( "context" + ctrl "sigs.k8s.io/controller-runtime" "github.com/kyma-project/btp-manager/api/v1alpha1" "github.com/kyma-project/btp-manager/internal/conditions" diff --git a/k3.yaml b/k3.yaml index 289a14966..8a3af3991 100644 --- a/k3.yaml +++ b/k3.yaml @@ -2,8 +2,8 @@ apiVersion: v1 clusters: - cluster: - certificate-authority-data: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUJkakNDQVIyZ0F3SUJBZ0lCQURBS0JnZ3Foa2pPUFFRREFqQWpNU0V3SHdZRFZRUUREQmhyTTNNdGMyVnkKZG1WeUxXTmhRREUzTXpZek5USXlPRGN3SGhjTk1qVXdNVEE0TVRZd05EUTNXaGNOTXpVd01UQTJNVFl3TkRRMwpXakFqTVNFd0h3WURWUVFEREJock0zTXRjMlZ5ZG1WeUxXTmhRREUzTXpZek5USXlPRGN3V1RBVEJnY3Foa2pPClBRSUJCZ2dxaGtqT1BRTUJCd05DQUFSSUxxa1VRM3pTSlBlS2duSWZBeW9BTS9qdktEMHdGS051VStBS0wwck4KUTV5UjZaVmlZNWZHbEl5Y00wRVdSemlWS2kwM1lQS0R0dEtubHVKdHdaYVlvMEl3UURBT0JnTlZIUThCQWY4RQpCQU1DQXFRd0R3WURWUjBUQVFIL0JBVXdBd0VCL3pBZEJnTlZIUTRFRmdRVTVVWEJyNjAvTEtGWVptN0QwWTl0CjM0YmpGUGt3Q2dZSUtvWkl6ajBFQXdJRFJ3QXdSQUlnR0hIMUNVWEUxUTJQakM1cG5XU2pvamRYOHB6MldOVmIKWndZam9oZ1M0ZllDSUZWOW5uNk1yOUpuaFJyMW1jb3YyY0w4bEZZbXdYTlcrbkM2aHFLYkNKWXAKLS0tLS1FTkQgQ0VSVElGSUNBVEUtLS0tLQo= - server: https://0.0.0.0:50324 + certificate-authority-data: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUJkekNDQVIyZ0F3SUJBZ0lCQURBS0JnZ3Foa2pPUFFRREFqQWpNU0V3SHdZRFZRUUREQmhyTTNNdGMyVnkKZG1WeUxXTmhRREUzTXpZME1EQTRNVGt3SGhjTk1qVXdNVEE1TURVek16TTVXaGNOTXpVd01UQTNNRFV6TXpNNQpXakFqTVNFd0h3WURWUVFEREJock0zTXRjMlZ5ZG1WeUxXTmhRREUzTXpZME1EQTRNVGt3V1RBVEJnY3Foa2pPClBRSUJCZ2dxaGtqT1BRTUJCd05DQUFRVlVPMlBsYmoxQ3F5TnlxaWJEZzRQWXAyaXR2ejNYK2Q2WHZ6eDg2cEoKTjAwUWViYnhmOHBuK1dsakptbjdkSEpSWm1XempFSEJhVDI4WE51SHovSHlvMEl3UURBT0JnTlZIUThCQWY4RQpCQU1DQXFRd0R3WURWUjBUQVFIL0JBVXdBd0VCL3pBZEJnTlZIUTRFRmdRVU5kempIWm1Fb29HSnM1YTFDUEhHCm95eDVoMFV3Q2dZSUtvWkl6ajBFQXdJRFNBQXdSUUlnTUw0MHR1WlVSMCs2anBWKytZUjl4TW1BQTNVRjVlejYKYWJOb2tQRkE5eklDSVFEVjYvUXVjdWVrRmxsQkJQYnc1QTlMdGFVTk1jalNFSHZra2dMeUlweFFqUT09Ci0tLS0tRU5EIENFUlRJRklDQVRFLS0tLS0K + server: https://0.0.0.0:59890 name: k3d-test contexts: - context: @@ -16,5 +16,5 @@ preferences: {} users: - name: admin@k3d-test user: - client-certificate-data: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUJrRENDQVRlZ0F3SUJBZ0lJRStuK2pVNlRoME13Q2dZSUtvWkl6ajBFQXdJd0l6RWhNQjhHQTFVRUF3d1kKYXpOekxXTnNhV1Z1ZEMxallVQXhOek0yTXpVeU1qZzNNQjRYRFRJMU1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TQvWVAyTnZCeGpnbVdkd3BCQm95eUFjTWtTaXlmcm1NK3BvOW9rQT09Ci0tLS0tRU5EIENFUlRJRklDQVRFLS0tLS0K + client-key-data: LS0tLS1CRUdJTiBFQyBQUklWQVRFIEtFWS0tLS0tCk1IY0NBUUVFSU9VejJqdStDU0VyWFFwemlGTDU4MDNTNHg5cUpUUUpDMVZvdkM1MlJDbWpvQW9HQ0NxR1NNNDkKQXdFSG9VUURRZ0FFclYwckRDVlJCQ3hDZGVpOGM5WTR4K3Vwd0ZYNElYcWZOMnZMdWlLbmJmVEtCSlZzV2ZjVApOUmptZFhJSWd3ZUE3RThyMHNHNFNRU0NybzVEYTJ3RlF3PT0KLS0tLS1FTkQgRUMgUFJJVkFURSBLRVktLS0tLQo= diff --git a/scripts/testing/install_module.sh b/scripts/testing/install_module.sh index 3e75cdb71..2e0b72983 100755 --- a/scripts/testing/install_module.sh +++ b/scripts/testing/install_module.sh @@ -52,6 +52,11 @@ kubectl apply -f ${YAML_DIR}/e2e-test-btpoperator.yaml while [[ $(kubectl get btpoperators/e2e-test-btpoperator -ojson| jq '.status.conditions[] | select(.type=="Ready") |.status+.reason'|xargs) != "TrueReconcileSucceeded" ]]; do echo -e "\n---Waiting for BTP Operator to be ready and reconciled"; sleep 5; done +while [[ $(kubectl get deployment/sap-btp-operator-controller-manager -n kyma-system -o 'jsonpath={..status.conditions[?(@.type=="Available")].status}') != "True" ]]; +do echo -e "\n---Waiting for deployment to be available"; sleep 5; done + +echo -e "\n---Deployment available" + # verifying whether service instance and service binding custom resources were created echo -e "\n---Checking if serviceinstances and servicebindings CRDs are created" @@ -62,4 +67,4 @@ then exit 1 fi -echo "\n---Module installed successfully" \ No newline at end of file +echo -e "\n---Module installed successfully" \ No newline at end of file diff --git a/tests/btp-manager.yaml b/tests/btp-manager.yaml new file mode 100644 index 000000000..2b7069fed --- /dev/null +++ b/tests/btp-manager.yaml @@ -0,0 +1,301 @@ +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition +metadata: + annotations: + controller-gen.kubebuilder.io/version: v0.16.1 + labels: + app.kubernetes.io/component: btp-manager.kyma-project.io + name: btpoperators.operator.kyma-project.io +spec: + group: operator.kyma-project.io + names: + categories: + - kyma-modules + - kyma-btp-operator + kind: BtpOperator + listKind: BtpOperatorList + plural: btpoperators + singular: btpoperator + scope: Namespaced + versions: + - additionalPrinterColumns: + - jsonPath: .status.state + name: State + type: string + name: v1alpha1 + schema: + openAPIV3Schema: + description: BtpOperator is the Schema for the btpoperators 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: BtpOperatorSpec defines the desired state of BtpOperator + nullable: true + type: object + status: + description: Status defines the observed state of CustomObject. + properties: + conditions: + description: Conditions associated with CustomStatus. + items: + description: Condition contains details for one aspect of the current + state of this API Resource. + properties: + lastTransitionTime: + description: |- + lastTransitionTime is the last time the condition transitioned from one status to another. + This should be when the underlying condition changed. If that is not known, then using the time when the API field changed is acceptable. + format: date-time + type: string + message: + description: |- + message is a human readable message indicating details about the transition. + This may be an empty string. + maxLength: 32768 + type: string + observedGeneration: + description: |- + observedGeneration represents the .metadata.generation that the condition was set based upon. + For instance, if .metadata.generation is currently 12, but the .status.conditions[x].observedGeneration is 9, the condition is out of date + with respect to the current state of the instance. + format: int64 + minimum: 0 + type: integer + reason: + description: |- + reason contains a programmatic identifier indicating the reason for the condition's last transition. + Producers of specific condition types may define expected values and meanings for this field, + and whether the values are considered a guaranteed API. + The value should be a CamelCase string. + This field may not be empty. + maxLength: 1024 + minLength: 1 + pattern: ^[A-Za-z]([A-Za-z0-9_,:]*[A-Za-z0-9_])?$ + type: string + status: + description: status of the condition, one of True, False, Unknown. + enum: + - "True" + - "False" + - Unknown + type: string + type: + description: type of condition in CamelCase or in foo.example.com/CamelCase. + maxLength: 316 + pattern: ^([a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*/)?(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])$ + type: string + required: + - lastTransitionTime + - message + - reason + - status + - type + type: object + type: array + state: + description: |- + State signifies current state of CustomObject. + Value can be one of ("Ready", "Processing", "Error", "Deleting", "Warning"). + enum: + - Processing + - Deleting + - Ready + - Error + - Warning + type: string + required: + - state + type: object + type: object + served: true + storage: true + subresources: + status: {} +--- +apiVersion: v1 +kind: ServiceAccount +metadata: + labels: + app.kubernetes.io/component: btp-manager.kyma-project.io + name: btp-manager-controller-manager + namespace: kyma-system +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: Role +metadata: + labels: + app.kubernetes.io/component: btp-manager.kyma-project.io + name: btp-manager-leader-election-role + namespace: kyma-system +rules: +- apiGroups: + - "" + resources: + - configmaps + verbs: + - get + - list + - watch + - create + - update + - patch + - delete +- apiGroups: + - coordination.k8s.io + resources: + - leases + verbs: + - get + - list + - watch + - create + - update + - patch + - delete +- apiGroups: + - "" + resources: + - events + verbs: + - create + - patch +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRole +metadata: + labels: + app.kubernetes.io/component: btp-manager.kyma-project.io + name: btp-manager-manager-role +rules: +- apiGroups: + - "" + resources: + - configmaps + - secrets + - serviceaccounts + - services + verbs: + - '*' +- apiGroups: + - "" + resources: + - namespaces + verbs: + - get + - list + - watch +- apiGroups: + - admissionregistration.k8s.io + resources: + - mutatingwebhookconfigurations + - validatingwebhookconfigurations + verbs: + - '*' +- apiGroups: + - apiextensions.k8s.io + resources: + - customresourcedefinitions + verbs: + - '*' +- apiGroups: + - apps + resources: + - deployments + verbs: + - '*' +- apiGroups: + - operator.kyma-project.io + resources: + - btpoperators + - btpoperators/status + verbs: + - '*' +- apiGroups: + - rbac.authorization.k8s.io + resources: + - clusterrolebindings + - clusterroles + - rolebindings + - roles + verbs: + - '*' +- apiGroups: + - services.cloud.sap.com + resources: + - servicebindings + - serviceinstances + verbs: + - '*' +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: RoleBinding +metadata: + labels: + app.kubernetes.io/component: btp-manager.kyma-project.io + name: btp-manager-leader-election-rolebinding + namespace: kyma-system +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: Role + name: btp-manager-leader-election-role +subjects: +- kind: ServiceAccount + name: btp-manager-controller-manager + namespace: kyma-system +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRoleBinding +metadata: + labels: + app.kubernetes.io/component: btp-manager.kyma-project.io + name: btp-manager-manager-rolebinding +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: ClusterRole + name: btp-manager-manager-role +subjects: +- kind: ServiceAccount + name: btp-manager-controller-manager + namespace: kyma-system +--- +apiVersion: v1 +kind: Service +metadata: + labels: + app.kubernetes.io/component: btp-manager.kyma-project.io + name: btp-manager-metrics-service + namespace: kyma-system +spec: + ports: + - name: http + port: 8080 + targetPort: http + selector: + app.kubernetes.io/component: btp-manager.kyma-project.io +--- +apiVersion: scheduling.k8s.io/v1 +description: Scheduling priority of the btp-operator module. Must not be blocked by + unschedulable user workloads. +globalDefault: false +kind: PriorityClass +metadata: + labels: + app.kubernetes.io/component: btp-manager.kyma-project.io + name: btp-manager-kyma-priority +value: 2100000 \ No newline at end of file diff --git a/tests/btp-operator-default-cr.yaml b/tests/btp-operator-default-cr.yaml new file mode 100644 index 000000000..f70dfb290 --- /dev/null +++ b/tests/btp-operator-default-cr.yaml @@ -0,0 +1,12 @@ +apiVersion: operator.kyma-project.io/v1alpha1 +kind: BtpOperator +metadata: + labels: + app.kubernetes.io/name: btpoperator + app.kubernetes.io/instance: btpoperator + app.kubernetes.io/part-of: btp-manager + app.kubernetes.io/managed-by: btp-manager + app.kubernetes.io/created-by: btp-manager + name: btpoperator +spec: + # TODO(user): Add fields here diff --git a/tests/test-secret.yaml b/tests/test-secret.yaml new file mode 100644 index 000000000..2549d16ff --- /dev/null +++ b/tests/test-secret.yaml @@ -0,0 +1,14 @@ +apiVersion: v1 +kind: Secret +type: Opaque +metadata: + name: sap-btp-manager + namespace: kyma-system + labels: + app.kubernetes.io/managed-by: kcp-kyma-environment-broker +data: + clientid: dGVzdF9jbGllbnRpZA== + clientsecret: dGVzdF9jbGllbnRzZWNyZXQ= + sm_url: dGVzdF9zbV91cmw= + tokenurl: dGVzdF90b2tlbnVybA== + cluster_id: dGVzdF9jbHVzdGVyX2lk diff --git a/tests/test.sh b/tests/test.sh new file mode 100755 index 000000000..3aa6f63ed --- /dev/null +++ b/tests/test.sh @@ -0,0 +1,50 @@ +#!/bin/bash + +# Function to check if the last command was successful +check_command_success() { + if [ $? -ne 0 ]; then + echo "An error occurred during the last operation. Exiting." + exit 1 + fi +} + +# Check if cluster "test" exists and delete it if found +existingCluster=$(k3d cluster list | grep -w "test") +if [ -n "$existingCluster" ]; then + echo "Deleting existing cluster 'test'..." + k3d cluster delete test + check_command_success +fi + +# Create new cluster +echo "Creating new cluster 'test'..." +k3d cluster create test +check_command_success + +# Wait a moment for the cluster to be ready +echo "Waiting for the cluster to be ready..." +sleep 10 + +# Apply Kubernetes configurations +echo "Applying Kubernetes configurations..." + +# Check if the namespace already exists, create it if not +kubectl get namespace kyma-system >/dev/null 2>&1 +if [ $? -ne 0 ]; then + kubectl create namespace kyma-system + check_command_success +else + echo "Namespace 'kyma-system' already exists. Skipping creation." +fi + +# Apply the manifests +for manifest in test-secret.yaml btp-manager.yaml btp-operator-default-cr.yaml; do + echo "Applying $manifest..." + kubectl apply -f $manifest + check_command_success +done + +echo "Setup completed successfully!" + +cd .. && go run main.go +check_command_success