From b363b96165eb6c294e78d58223898eeaf27ee19c Mon Sep 17 00:00:00 2001 From: skrishnan-sap <139535827+skrishnan-sap@users.noreply.github.com> Date: Tue, 15 Oct 2024 15:43:11 +0200 Subject: [PATCH] [FEAT] add container `args` (#145) CHANGES: - added `args` to containers (includes CRD changes) - added an environment variable `CAPOP_TENANT_MTXS_OPERATION ` for tenant operations to supply the `mtxs` command. All tenant operation related environment variables, including subscription payload, are now available in the corresponding `initContainers` --------- Co-authored-by: Pavan --- crds/sme.sap.com_capapplications.yaml | 2 +- crds/sme.sap.com_capapplicationversions.yaml | 18 +++++-- crds/sme.sap.com_captenantoperations.yaml | 2 +- crds/sme.sap.com_captenantoutputs.yaml | 2 +- crds/sme.sap.com_captenants.yaml | 2 +- .../reconcile-capapplicationversion.go | 2 + .../reconcile-captenantoperation.go | 53 ++++++++++--------- internal/controller/reconcile.go | 1 + .../captenantoperation/ctop-04.expected.yaml | 5 +- .../captenantoperation/ctop-06.expected.yaml | 5 +- .../captenantoperation/ctop-09.expected.yaml | 5 +- .../captenantoperation/ctop-16.expected.yaml | 5 +- .../captenantoperation/ctop-18.expected.yaml | 5 +- .../captenantoperation/ctop-19.expected.yaml | 5 +- .../captenantoperation/ctop-20.expected.yaml | 5 +- .../captenantoperation/ctop-21.expected.yaml | 5 +- .../captenantoperation/ctop-22.expected.yaml | 5 +- .../captenantoperation/ctop-24.expected.yaml | 2 + .../captenantoperation/ctop-26.expected.yaml | 5 +- .../ctop-init.expected.yaml | 19 ++++++- .../ctop-scheduling.expected.yaml | 5 +- .../captenantoperation/ctop-vol.expected.yaml | 5 +- pkg/apis/sme.sap.com/v1alpha1/types.go | 2 + .../v1alpha1/zz_generated.deepcopy.go | 5 ++ .../sme.sap.com/v1alpha1/commondetails.go | 11 ++++ .../sme.sap.com/v1alpha1/deploymentdetails.go | 10 ++++ .../sme.sap.com/v1alpha1/jobdetails.go | 10 ++++ 27 files changed, 155 insertions(+), 46 deletions(-) diff --git a/crds/sme.sap.com_capapplications.yaml b/crds/sme.sap.com_capapplications.yaml index 55611d5..1251078 100644 --- a/crds/sme.sap.com_capapplications.yaml +++ b/crds/sme.sap.com_capapplications.yaml @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: annotations: - controller-gen.kubebuilder.io/version: v0.16.2 + controller-gen.kubebuilder.io/version: v0.16.4 name: capapplications.sme.sap.com spec: group: sme.sap.com diff --git a/crds/sme.sap.com_capapplicationversions.yaml b/crds/sme.sap.com_capapplicationversions.yaml index 2f8c0e9..5e2be37 100644 --- a/crds/sme.sap.com_capapplicationversions.yaml +++ b/crds/sme.sap.com_capapplicationversions.yaml @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: annotations: - controller-gen.kubebuilder.io/version: v0.16.2 + controller-gen.kubebuilder.io/version: v0.16.4 name: capapplicationversions.sme.sap.com spec: group: sme.sap.com @@ -540,6 +540,10 @@ spec: x-kubernetes-list-type: atomic type: object type: object + args: + items: + type: string + type: array command: items: type: string @@ -1379,10 +1383,10 @@ spec: properties: deletionRules: oneOf: - - required: - - metrics - - required: - - expression + - required: + - metrics + - required: + - expression properties: expression: type: string @@ -3044,6 +3048,10 @@ spec: x-kubernetes-list-type: atomic type: object type: object + args: + items: + type: string + type: array backoffLimit: format: int32 type: integer diff --git a/crds/sme.sap.com_captenantoperations.yaml b/crds/sme.sap.com_captenantoperations.yaml index 53671e6..c608d8a 100644 --- a/crds/sme.sap.com_captenantoperations.yaml +++ b/crds/sme.sap.com_captenantoperations.yaml @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: annotations: - controller-gen.kubebuilder.io/version: v0.16.2 + controller-gen.kubebuilder.io/version: v0.16.4 name: captenantoperations.sme.sap.com spec: group: sme.sap.com diff --git a/crds/sme.sap.com_captenantoutputs.yaml b/crds/sme.sap.com_captenantoutputs.yaml index 61c858c..5cf6942 100644 --- a/crds/sme.sap.com_captenantoutputs.yaml +++ b/crds/sme.sap.com_captenantoutputs.yaml @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: annotations: - controller-gen.kubebuilder.io/version: v0.16.2 + controller-gen.kubebuilder.io/version: v0.16.4 name: captenantoutputs.sme.sap.com spec: group: sme.sap.com diff --git a/crds/sme.sap.com_captenants.yaml b/crds/sme.sap.com_captenants.yaml index f86be3e..4ff3f17 100644 --- a/crds/sme.sap.com_captenants.yaml +++ b/crds/sme.sap.com_captenants.yaml @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: annotations: - controller-gen.kubebuilder.io/version: v0.16.2 + controller-gen.kubebuilder.io/version: v0.16.4 name: captenants.sme.sap.com spec: group: sme.sap.com diff --git a/internal/controller/reconcile-capapplicationversion.go b/internal/controller/reconcile-capapplicationversion.go index 2116b5b..7eccbb8 100644 --- a/internal/controller/reconcile-capapplicationversion.go +++ b/internal/controller/reconcile-capapplicationversion.go @@ -313,6 +313,7 @@ func newContentDeploymentJob(cav *v1alpha1.CAPApplicationVersion, workload *v1al Image: workload.JobDefinition.Image, ImagePullPolicy: workload.JobDefinition.ImagePullPolicy, Command: workload.JobDefinition.Command, + Args: workload.JobDefinition.Args, Env: append([]corev1.EnvVar{ {Name: EnvCAPOpAppVersion, Value: cav.Spec.Version}, }, workload.JobDefinition.Env...), @@ -754,6 +755,7 @@ func getContainer(params *DeploymentParameters) []corev1.Container { Image: params.WorkloadDetails.DeploymentDefinition.Image, ImagePullPolicy: params.WorkloadDetails.DeploymentDefinition.ImagePullPolicy, Command: params.WorkloadDetails.DeploymentDefinition.Command, + Args: params.WorkloadDetails.DeploymentDefinition.Args, Env: getEnv(params), EnvFrom: getEnvFrom(params.VCAPSecretName), VolumeMounts: params.WorkloadDetails.DeploymentDefinition.VolumeMounts, diff --git a/internal/controller/reconcile-captenantoperation.go b/internal/controller/reconcile-captenantoperation.go index 017b0e3..2dd0617 100644 --- a/internal/controller/reconcile-captenantoperation.go +++ b/internal/controller/reconcile-captenantoperation.go @@ -35,6 +35,7 @@ type tentantOperationWorkload struct { image string imagePullPolicy corev1.PullPolicy command []string + args []string env []corev1.EnvVar volumeMounts []corev1.VolumeMount volumes []corev1.Volume @@ -484,7 +485,7 @@ func (c *Controller) createTenantOperationJob(ctx context.Context, ctop *v1alpha RestartPolicy: corev1.RestartPolicyNever, ImagePullSecrets: params.imagePullSecrets, Containers: getContainers(ctop, derivedWorkload, workload, params), - InitContainers: *updateInitContainers(derivedWorkload.initContainers, getCTOPEnv(params, ctop), params.vcapSecretName), + InitContainers: *updateInitContainers(derivedWorkload.initContainers, getCTOPEnv(params, ctop, v1alpha1.JobTenantOperation), params.vcapSecretName), Volumes: derivedWorkload.volumes, ServiceAccountName: derivedWorkload.serviceAccountName, SecurityContext: derivedWorkload.podSecurityContext, @@ -508,34 +509,21 @@ func getContainers(ctop *v1alpha1.CAPTenantOperation, derivedWorkload tentantOpe Name: workload.Name, Image: derivedWorkload.image, ImagePullPolicy: derivedWorkload.imagePullPolicy, - Env: append(getCTOPEnv(params, ctop), derivedWorkload.env...), + Env: append(getCTOPEnv(params, ctop, v1alpha1.JobTenantOperation), derivedWorkload.env...), EnvFrom: getEnvFrom(params.vcapSecretName), VolumeMounts: derivedWorkload.volumeMounts, Resources: derivedWorkload.resources, SecurityContext: derivedWorkload.securityContext, } - var operation string - - if ctop.Spec.Operation == v1alpha1.CAPTenantOperationTypeProvisioning { - operation = "subscribe" - } else if ctop.Spec.Operation == v1alpha1.CAPTenantOperationTypeUpgrade { - operation = "upgrade" - } else { // deprovisioning - operation = "unsubscribe" - } - - appendCommand := false if derivedWorkload.command != nil { container.Command = derivedWorkload.command + container.Args = derivedWorkload.args } else { - container.Command = []string{"node", "./node_modules/@sap/cds-mtxs/bin/cds-mtx", operation, ctop.Spec.TenantId} - appendCommand = true - } - if ctop.Spec.Operation == v1alpha1.CAPTenantOperationTypeProvisioning { - container.Env = append(container.Env, corev1.EnvVar{Name: EnvCAPOpSubscriptionPayload, ValueFrom: &corev1.EnvVarSource{SecretKeyRef: &corev1.SecretKeySelector{LocalObjectReference: corev1.LocalObjectReference{Name: ctop.Annotations[AnnotationSubscriptionContextSecret]}, Key: SubscriptionContext}}}) - if appendCommand { - container.Command = append(container.Command, "--body", `$(`+EnvCAPOpSubscriptionPayload+`)`) + container.Command = []string{"node", "./node_modules/@sap/cds-mtxs/bin/cds-mtx"} // Use entrypoint for mtxs as the command + container.Args = []string{`$(` + EnvCAPOpTenantMtxsOperation + `)`, ctop.Spec.TenantId} + if ctop.Spec.Operation == v1alpha1.CAPTenantOperationTypeProvisioning { + container.Args = append(container.Args, "--body", `$(`+EnvCAPOpSubscriptionPayload+`)`) } } @@ -570,6 +558,7 @@ func deriveWorkloadForTenantOperation(workload *v1alpha1.WorkloadDetails) tentan result.image = workload.JobDefinition.Image result.imagePullPolicy = workload.JobDefinition.ImagePullPolicy result.command = workload.JobDefinition.Command + result.args = workload.JobDefinition.Args result.env = workload.JobDefinition.Env result.volumeMounts = workload.JobDefinition.VolumeMounts result.volumes = workload.JobDefinition.Volumes @@ -628,15 +617,16 @@ func (c *Controller) createCustomTenantOperationJob(ctx context.Context, ctop *v Name: workload.Name, Image: workload.JobDefinition.Image, ImagePullPolicy: workload.JobDefinition.ImagePullPolicy, - Env: append(getCTOPEnv(params, ctop), workload.JobDefinition.Env...), + Env: append(getCTOPEnv(params, ctop, v1alpha1.JobCustomTenantOperation), workload.JobDefinition.Env...), EnvFrom: getEnvFrom(params.vcapSecretName), VolumeMounts: workload.JobDefinition.VolumeMounts, Command: workload.JobDefinition.Command, + Args: workload.JobDefinition.Args, Resources: workload.JobDefinition.Resources, SecurityContext: workload.JobDefinition.SecurityContext, }, }, - InitContainers: *updateInitContainers(workload.JobDefinition.InitContainers, getCTOPEnv(params, ctop), params.vcapSecretName), + InitContainers: *updateInitContainers(workload.JobDefinition.InitContainers, getCTOPEnv(params, ctop, v1alpha1.JobCustomTenantOperation), params.vcapSecretName), }, }, }, @@ -677,8 +667,8 @@ func addCAPTenantOperationLabels(ctop *v1alpha1.CAPTenantOperation, cat *v1alpha return updated } -func getCTOPEnv(params *jobCreateParams, ctop *v1alpha1.CAPTenantOperation) []corev1.EnvVar { - return []corev1.EnvVar{ +func getCTOPEnv(params *jobCreateParams, ctop *v1alpha1.CAPTenantOperation, stepType v1alpha1.JobType) []corev1.EnvVar { + env := []corev1.EnvVar{ {Name: EnvCAPOpAppVersion, Value: params.version}, {Name: EnvCAPOpTenantId, Value: ctop.Spec.TenantId}, {Name: EnvCAPOpTenantOperation, Value: string(ctop.Spec.Operation)}, @@ -689,4 +679,19 @@ func getCTOPEnv(params *jobCreateParams, ctop *v1alpha1.CAPTenantOperation) []co {Name: EnvCAPOpProviderTenantId, Value: params.providerTenantId}, {Name: EnvCAPOpProviderSubDomain, Value: params.providerSubdomain}, } + + if stepType == v1alpha1.JobTenantOperation { + var operation string + if ctop.Spec.Operation == v1alpha1.CAPTenantOperationTypeProvisioning { + operation = "subscribe" + env = append(env, corev1.EnvVar{Name: EnvCAPOpSubscriptionPayload, ValueFrom: &corev1.EnvVarSource{SecretKeyRef: &corev1.SecretKeySelector{LocalObjectReference: corev1.LocalObjectReference{Name: ctop.Annotations[AnnotationSubscriptionContextSecret]}, Key: SubscriptionContext}}}) + } else if ctop.Spec.Operation == v1alpha1.CAPTenantOperationTypeUpgrade { + operation = "upgrade" + } else { // deprovisioning + operation = "unsubscribe" + } + env = append(env, corev1.EnvVar{Name: EnvCAPOpTenantMtxsOperation, Value: operation}) + } + + return env } diff --git a/internal/controller/reconcile.go b/internal/controller/reconcile.go index 274cc37..e5ce583 100644 --- a/internal/controller/reconcile.go +++ b/internal/controller/reconcile.go @@ -81,6 +81,7 @@ const ( EnvCAPOpTenantId = "CAPOP_TENANT_ID" EnvCAPOpTenantSubDomain = "CAPOP_TENANT_SUBDOMAIN" EnvCAPOpTenantOperation = "CAPOP_TENANT_OPERATION" + EnvCAPOpTenantMtxsOperation = "CAPOP_TENANT_MTXS_OPERATION" EnvCAPOpTenantType = "CAPOP_TENANT_TYPE" EnvCAPOpAppName = "CAPOP_APP_NAME" EnvCAPOpGlobalAccountId = "CAPOP_GLOBAL_ACCOUNT_ID" diff --git a/internal/controller/testdata/captenantoperation/ctop-04.expected.yaml b/internal/controller/testdata/captenantoperation/ctop-04.expected.yaml index 9574cb5..c4a3a11 100644 --- a/internal/controller/testdata/captenantoperation/ctop-04.expected.yaml +++ b/internal/controller/testdata/captenantoperation/ctop-04.expected.yaml @@ -110,11 +110,14 @@ spec: secretKeyRef: name: test-cap-01-gen key: subscriptionContext + - name: CAPOP_TENANT_MTXS_OPERATION + value: subscribe envFrom: - secretRef: name: test-cap-01-provider-abcd-mtx-gen optional: true - command: ["node", "./node_modules/@sap/cds-mtxs/bin/cds-mtx", "subscribe", "tenant-id-for-provider", "--body", "$(CAPOP_SUBSCRIPTION_PAYLOAD)"] + command: ["node", "./node_modules/@sap/cds-mtxs/bin/cds-mtx"] + args: ["$(CAPOP_TENANT_MTXS_OPERATION)", "tenant-id-for-provider", "--body", "$(CAPOP_SUBSCRIPTION_PAYLOAD)"] image: docker.image.repo/srv/server:latest name: mtx imagePullSecrets: diff --git a/internal/controller/testdata/captenantoperation/ctop-06.expected.yaml b/internal/controller/testdata/captenantoperation/ctop-06.expected.yaml index 8ce5a52..54f037c 100644 --- a/internal/controller/testdata/captenantoperation/ctop-06.expected.yaml +++ b/internal/controller/testdata/captenantoperation/ctop-06.expected.yaml @@ -106,13 +106,16 @@ spec: value: tenant-id-for-provider - name: CAPOP_PROVIDER_SUBDOMAIN value: my-provider + - name: CAPOP_TENANT_MTXS_OPERATION + value: upgrade - name: foo value: bar envFrom: - secretRef: name: test-cap-01-provider-abcd-cap-backend-gen optional: true - command: ["node", "./node_modules/@sap/cds-mtxs/bin/cds-mtx", "upgrade", "tenant-id-for-provider"] + command: ["node", "./node_modules/@sap/cds-mtxs/bin/cds-mtx"] + args: ["$(CAPOP_TENANT_MTXS_OPERATION)", "tenant-id-for-provider"] image: docker.image.repo/srv/server:v2 name: cap-backend imagePullSecrets: diff --git a/internal/controller/testdata/captenantoperation/ctop-09.expected.yaml b/internal/controller/testdata/captenantoperation/ctop-09.expected.yaml index 1198fe3..12e688e 100644 --- a/internal/controller/testdata/captenantoperation/ctop-09.expected.yaml +++ b/internal/controller/testdata/captenantoperation/ctop-09.expected.yaml @@ -110,13 +110,16 @@ spec: value: tenant-id-for-provider - name: CAPOP_PROVIDER_SUBDOMAIN value: my-provider + - name: CAPOP_TENANT_MTXS_OPERATION + value: upgrade - name: flow value: glow envFrom: - secretRef: name: test-cap-01-provider-abcd-ten-op-gen optional: true - command: ["node", "./node_modules/@sap/cds-mtxs/bin/cds-mtx", "upgrade", "tenant-id-for-provider"] + command: ["node", "./node_modules/@sap/cds-mtxs/bin/cds-mtx"] + args: ["$(CAPOP_TENANT_MTXS_OPERATION)", "tenant-id-for-provider"] image: docker.image.repo/srv/server:latest name: ten-op imagePullSecrets: diff --git a/internal/controller/testdata/captenantoperation/ctop-16.expected.yaml b/internal/controller/testdata/captenantoperation/ctop-16.expected.yaml index d10a9cb..9487216 100644 --- a/internal/controller/testdata/captenantoperation/ctop-16.expected.yaml +++ b/internal/controller/testdata/captenantoperation/ctop-16.expected.yaml @@ -104,11 +104,14 @@ spec: value: tenant-id-for-provider - name: CAPOP_PROVIDER_SUBDOMAIN value: my-provider + - name: CAPOP_TENANT_MTXS_OPERATION + value: unsubscribe envFrom: - secretRef: name: test-cap-01-provider-abcd-mtx-gen optional: true - command: ["node", "./node_modules/@sap/cds-mtxs/bin/cds-mtx", "unsubscribe", "tenant-id-for-provider"] + command: ["node", "./node_modules/@sap/cds-mtxs/bin/cds-mtx"] + args: ["$(CAPOP_TENANT_MTXS_OPERATION)", "tenant-id-for-provider"] image: docker.image.repo/srv/server:latest name: mtx imagePullSecrets: diff --git a/internal/controller/testdata/captenantoperation/ctop-18.expected.yaml b/internal/controller/testdata/captenantoperation/ctop-18.expected.yaml index b951d9b..066a45a 100644 --- a/internal/controller/testdata/captenantoperation/ctop-18.expected.yaml +++ b/internal/controller/testdata/captenantoperation/ctop-18.expected.yaml @@ -110,6 +110,8 @@ spec: secretKeyRef: name: test-cap-01-gen key: subscriptionContext + - name: CAPOP_TENANT_MTXS_OPERATION + value: subscribe envFrom: - secretRef: name: test-cap-01-provider-abcd-mtx-gen @@ -117,7 +119,8 @@ spec: command: - node - ./node_modules/@sap/cds-mtxs/bin/cds-mtx - - subscribe + args: + - $(CAPOP_TENANT_MTXS_OPERATION) - tenant-id-for-provider - --body - $(CAPOP_SUBSCRIPTION_PAYLOAD) diff --git a/internal/controller/testdata/captenantoperation/ctop-19.expected.yaml b/internal/controller/testdata/captenantoperation/ctop-19.expected.yaml index f78ece4..c0c2ade 100644 --- a/internal/controller/testdata/captenantoperation/ctop-19.expected.yaml +++ b/internal/controller/testdata/captenantoperation/ctop-19.expected.yaml @@ -104,6 +104,8 @@ spec: value: tenant-id-for-provider - name: CAPOP_PROVIDER_SUBDOMAIN value: my-provider + - name: CAPOP_TENANT_MTXS_OPERATION + value: unsubscribe envFrom: - secretRef: name: test-cap-01-provider-abcd-mtx-gen @@ -111,7 +113,8 @@ spec: command: - node - ./node_modules/@sap/cds-mtxs/bin/cds-mtx - - unsubscribe + args: + - $(CAPOP_TENANT_MTXS_OPERATION) - tenant-id-for-provider image: docker.image.repo/srv/server:latest imagePullPolicy: Always diff --git a/internal/controller/testdata/captenantoperation/ctop-20.expected.yaml b/internal/controller/testdata/captenantoperation/ctop-20.expected.yaml index acb99df..043343b 100644 --- a/internal/controller/testdata/captenantoperation/ctop-20.expected.yaml +++ b/internal/controller/testdata/captenantoperation/ctop-20.expected.yaml @@ -104,6 +104,8 @@ spec: value: tenant-id-for-provider - name: CAPOP_PROVIDER_SUBDOMAIN value: my-provider + - name: CAPOP_TENANT_MTXS_OPERATION + value: upgrade envFrom: - secretRef: name: test-cap-01-provider-abcd-mtx-gen @@ -111,7 +113,8 @@ spec: command: - node - ./node_modules/@sap/cds-mtxs/bin/cds-mtx - - upgrade + args: + - $(CAPOP_TENANT_MTXS_OPERATION) - tenant-id-for-provider image: docker.image.repo/srv/server:latest imagePullPolicy: Always diff --git a/internal/controller/testdata/captenantoperation/ctop-21.expected.yaml b/internal/controller/testdata/captenantoperation/ctop-21.expected.yaml index 036efd2..d41fd68 100644 --- a/internal/controller/testdata/captenantoperation/ctop-21.expected.yaml +++ b/internal/controller/testdata/captenantoperation/ctop-21.expected.yaml @@ -110,6 +110,8 @@ spec: secretKeyRef: name: test-cap-01-gen key: subscriptionContext + - name: CAPOP_TENANT_MTXS_OPERATION + value: subscribe envFrom: - secretRef: name: test-cap-01-provider-abcd-mtx-gen @@ -117,7 +119,8 @@ spec: command: - node - ./node_modules/@sap/cds-mtxs/bin/cds-mtx - - subscribe + args: + - $(CAPOP_TENANT_MTXS_OPERATION) - tenant-id-for-provider - --body - $(CAPOP_SUBSCRIPTION_PAYLOAD) diff --git a/internal/controller/testdata/captenantoperation/ctop-22.expected.yaml b/internal/controller/testdata/captenantoperation/ctop-22.expected.yaml index bc8a26c..af337c3 100644 --- a/internal/controller/testdata/captenantoperation/ctop-22.expected.yaml +++ b/internal/controller/testdata/captenantoperation/ctop-22.expected.yaml @@ -110,6 +110,8 @@ spec: secretKeyRef: name: test-cap-01-gen key: subscriptionContext + - name: CAPOP_TENANT_MTXS_OPERATION + value: subscribe envFrom: - secretRef: name: test-cap-01-provider-abcd-mtx-gen @@ -117,7 +119,8 @@ spec: command: - node - ./node_modules/@sap/cds-mtxs/bin/cds-mtx - - subscribe + args: + - $(CAPOP_TENANT_MTXS_OPERATION) - tenant-id-for-provider - --body - $(CAPOP_SUBSCRIPTION_PAYLOAD) diff --git a/internal/controller/testdata/captenantoperation/ctop-24.expected.yaml b/internal/controller/testdata/captenantoperation/ctop-24.expected.yaml index cf23a07..dcdd08b 100644 --- a/internal/controller/testdata/captenantoperation/ctop-24.expected.yaml +++ b/internal/controller/testdata/captenantoperation/ctop-24.expected.yaml @@ -114,6 +114,8 @@ spec: secretKeyRef: name: test-cap-01-gen key: subscriptionContext + - name: CAPOP_TENANT_MTXS_OPERATION + value: subscribe envFrom: - secretRef: name: test-cap-01-provider-abcd-mtx-gen diff --git a/internal/controller/testdata/captenantoperation/ctop-26.expected.yaml b/internal/controller/testdata/captenantoperation/ctop-26.expected.yaml index 2b21e26..5d1c46f 100644 --- a/internal/controller/testdata/captenantoperation/ctop-26.expected.yaml +++ b/internal/controller/testdata/captenantoperation/ctop-26.expected.yaml @@ -106,6 +106,8 @@ spec: value: tenant-id-for-provider - name: CAPOP_PROVIDER_SUBDOMAIN value: my-provider + - name: CAPOP_TENANT_MTXS_OPERATION + value: upgrade - name: flow value: glow - name: IS_MTXS_ENABLED @@ -114,7 +116,8 @@ spec: - secretRef: name: test-cap-01-provider-abcd-ten-op-gen optional: true - command: ["node", "./node_modules/@sap/cds-mtxs/bin/cds-mtx", "upgrade", "tenant-id-for-provider"] + command: ["node", "./node_modules/@sap/cds-mtxs/bin/cds-mtx"] + args: ["$(CAPOP_TENANT_MTXS_OPERATION)", "tenant-id-for-provider"] image: docker.image.repo/srv/server:latest name: ten-op imagePullSecrets: diff --git a/internal/controller/testdata/captenantoperation/ctop-init.expected.yaml b/internal/controller/testdata/captenantoperation/ctop-init.expected.yaml index 1a6119c..f39ddd9 100644 --- a/internal/controller/testdata/captenantoperation/ctop-init.expected.yaml +++ b/internal/controller/testdata/captenantoperation/ctop-init.expected.yaml @@ -110,6 +110,8 @@ spec: secretKeyRef: name: test-cap-01-gen key: subscriptionContext + - name: CAPOP_TENANT_MTXS_OPERATION + value: subscribe envFrom: - secretRef: name: test-cap-01-provider-abcd-mtx-gen @@ -120,7 +122,8 @@ spec: command: - node - ./node_modules/@sap/cds-mtxs/bin/cds-mtx - - subscribe + args: + - $(CAPOP_TENANT_MTXS_OPERATION) - tenant-id-for-provider - --body - $(CAPOP_SUBSCRIPTION_PAYLOAD) @@ -207,6 +210,13 @@ spec: value: tenant-id-for-provider - name: CAPOP_PROVIDER_SUBDOMAIN value: my-provider + - name: CAPOP_SUBSCRIPTION_PAYLOAD + valueFrom: + secretKeyRef: + name: test-cap-01-gen + key: subscriptionContext + - name: CAPOP_TENANT_MTXS_OPERATION + value: subscribe envFrom: - secretRef: name: test-cap-01-provider-abcd-mtx-gen @@ -246,6 +256,13 @@ spec: value: tenant-id-for-provider - name: CAPOP_PROVIDER_SUBDOMAIN value: my-provider + - name: CAPOP_SUBSCRIPTION_PAYLOAD + valueFrom: + secretKeyRef: + name: test-cap-01-gen + key: subscriptionContext + - name: CAPOP_TENANT_MTXS_OPERATION + value: subscribe envFrom: - secretRef: name: test-cap-01-provider-abcd-mtx-gen diff --git a/internal/controller/testdata/captenantoperation/ctop-scheduling.expected.yaml b/internal/controller/testdata/captenantoperation/ctop-scheduling.expected.yaml index 2ab6f24..c536836 100644 --- a/internal/controller/testdata/captenantoperation/ctop-scheduling.expected.yaml +++ b/internal/controller/testdata/captenantoperation/ctop-scheduling.expected.yaml @@ -110,6 +110,8 @@ spec: secretKeyRef: name: test-cap-01-gen key: subscriptionContext + - name: CAPOP_TENANT_MTXS_OPERATION + value: subscribe envFrom: - secretRef: name: test-cap-01-provider-abcd-mtx-gen @@ -117,7 +119,8 @@ spec: command: - node - ./node_modules/@sap/cds-mtxs/bin/cds-mtx - - subscribe + args: + - $(CAPOP_TENANT_MTXS_OPERATION) - tenant-id-for-provider - --body - $(CAPOP_SUBSCRIPTION_PAYLOAD) diff --git a/internal/controller/testdata/captenantoperation/ctop-vol.expected.yaml b/internal/controller/testdata/captenantoperation/ctop-vol.expected.yaml index 0a0f4dd..89d2d14 100644 --- a/internal/controller/testdata/captenantoperation/ctop-vol.expected.yaml +++ b/internal/controller/testdata/captenantoperation/ctop-vol.expected.yaml @@ -110,6 +110,8 @@ spec: secretKeyRef: name: test-cap-01-gen key: subscriptionContext + - name: CAPOP_TENANT_MTXS_OPERATION + value: subscribe envFrom: - secretRef: name: test-cap-01-provider-abcd-mtx-gen @@ -120,7 +122,8 @@ spec: command: - node - ./node_modules/@sap/cds-mtxs/bin/cds-mtx - - subscribe + args: + - $(CAPOP_TENANT_MTXS_OPERATION) - tenant-id-for-provider - --body - $(CAPOP_SUBSCRIPTION_PAYLOAD) diff --git a/pkg/apis/sme.sap.com/v1alpha1/types.go b/pkg/apis/sme.sap.com/v1alpha1/types.go index 43e37ca..b5c8cf1 100644 --- a/pkg/apis/sme.sap.com/v1alpha1/types.go +++ b/pkg/apis/sme.sap.com/v1alpha1/types.go @@ -367,6 +367,8 @@ type CommonDetails struct { ImagePullPolicy corev1.PullPolicy `json:"imagePullPolicy,omitempty"` // Entrypoint array for the container Command []string `json:"command,omitempty"` + // Arguments to the entrypoint + Args []string `json:"args,omitempty"` // Environment Config for the Container Env []corev1.EnvVar `json:"env,omitempty"` // Volume Configuration for the Pod diff --git a/pkg/apis/sme.sap.com/v1alpha1/zz_generated.deepcopy.go b/pkg/apis/sme.sap.com/v1alpha1/zz_generated.deepcopy.go index d9fc6a4..726f6f3 100644 --- a/pkg/apis/sme.sap.com/v1alpha1/zz_generated.deepcopy.go +++ b/pkg/apis/sme.sap.com/v1alpha1/zz_generated.deepcopy.go @@ -609,6 +609,11 @@ func (in *CommonDetails) DeepCopyInto(out *CommonDetails) { *out = make([]string, len(*in)) copy(*out, *in) } + if in.Args != nil { + in, out := &in.Args, &out.Args + *out = make([]string, len(*in)) + copy(*out, *in) + } if in.Env != nil { in, out := &in.Env, &out.Env *out = make([]v1.EnvVar, len(*in)) diff --git a/pkg/client/applyconfiguration/sme.sap.com/v1alpha1/commondetails.go b/pkg/client/applyconfiguration/sme.sap.com/v1alpha1/commondetails.go index 97da251..e98c7b2 100644 --- a/pkg/client/applyconfiguration/sme.sap.com/v1alpha1/commondetails.go +++ b/pkg/client/applyconfiguration/sme.sap.com/v1alpha1/commondetails.go @@ -17,6 +17,7 @@ type CommonDetailsApplyConfiguration struct { Image *string `json:"image,omitempty"` ImagePullPolicy *v1.PullPolicy `json:"imagePullPolicy,omitempty"` Command []string `json:"command,omitempty"` + Args []string `json:"args,omitempty"` Env []v1.EnvVar `json:"env,omitempty"` Volumes []v1.Volume `json:"volumes,omitempty"` VolumeMounts []v1.VolumeMount `json:"volumeMounts,omitempty"` @@ -65,6 +66,16 @@ func (b *CommonDetailsApplyConfiguration) WithCommand(values ...string) *CommonD return b } +// WithArgs adds the given value to the Args field in the declarative configuration +// and returns the receiver, so that objects can be build by chaining "With" function invocations. +// If called multiple times, values provided by each call will be appended to the Args field. +func (b *CommonDetailsApplyConfiguration) WithArgs(values ...string) *CommonDetailsApplyConfiguration { + for i := range values { + b.Args = append(b.Args, values[i]) + } + return b +} + // WithEnv adds the given value to the Env field in the declarative configuration // and returns the receiver, so that objects can be build by chaining "With" function invocations. // If called multiple times, values provided by each call will be appended to the Env field. diff --git a/pkg/client/applyconfiguration/sme.sap.com/v1alpha1/deploymentdetails.go b/pkg/client/applyconfiguration/sme.sap.com/v1alpha1/deploymentdetails.go index 0c55146..ed9cb05 100644 --- a/pkg/client/applyconfiguration/sme.sap.com/v1alpha1/deploymentdetails.go +++ b/pkg/client/applyconfiguration/sme.sap.com/v1alpha1/deploymentdetails.go @@ -56,6 +56,16 @@ func (b *DeploymentDetailsApplyConfiguration) WithCommand(values ...string) *Dep return b } +// WithArgs adds the given value to the Args field in the declarative configuration +// and returns the receiver, so that objects can be build by chaining "With" function invocations. +// If called multiple times, values provided by each call will be appended to the Args field. +func (b *DeploymentDetailsApplyConfiguration) WithArgs(values ...string) *DeploymentDetailsApplyConfiguration { + for i := range values { + b.Args = append(b.Args, values[i]) + } + return b +} + // WithEnv adds the given value to the Env field in the declarative configuration // and returns the receiver, so that objects can be build by chaining "With" function invocations. // If called multiple times, values provided by each call will be appended to the Env field. diff --git a/pkg/client/applyconfiguration/sme.sap.com/v1alpha1/jobdetails.go b/pkg/client/applyconfiguration/sme.sap.com/v1alpha1/jobdetails.go index 8368560..f171a2d 100644 --- a/pkg/client/applyconfiguration/sme.sap.com/v1alpha1/jobdetails.go +++ b/pkg/client/applyconfiguration/sme.sap.com/v1alpha1/jobdetails.go @@ -53,6 +53,16 @@ func (b *JobDetailsApplyConfiguration) WithCommand(values ...string) *JobDetails return b } +// WithArgs adds the given value to the Args field in the declarative configuration +// and returns the receiver, so that objects can be build by chaining "With" function invocations. +// If called multiple times, values provided by each call will be appended to the Args field. +func (b *JobDetailsApplyConfiguration) WithArgs(values ...string) *JobDetailsApplyConfiguration { + for i := range values { + b.Args = append(b.Args, values[i]) + } + return b +} + // WithEnv adds the given value to the Env field in the declarative configuration // and returns the receiver, so that objects can be build by chaining "With" function invocations. // If called multiple times, values provided by each call will be appended to the Env field.