Skip to content

Commit

Permalink
renamed method names to be more specific
Browse files Browse the repository at this point in the history
  • Loading branch information
anirudhprasad-sap committed Oct 17, 2024
1 parent 6a3e6a8 commit 388b7d5
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
16 changes: 8 additions & 8 deletions internal/controller/reconcile-capapplicationversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ func (c *Controller) handleContentDeployJob(ca *v1alpha1.CAPApplication, cav *v1

// Get VCAP secret name
err = nil
if !useVolumeMounts(cav) {
if !useVolumeMountsForServiceCredentials(cav) {
vcapSecretName, err = createVCAPSecret(jobName, cav.Namespace, ownerRef, consumedServiceInfos, c.kubeClient)
}

Expand Down Expand Up @@ -301,13 +301,13 @@ func newContentDeploymentJob(ca *v1alpha1.CAPApplication, cav *v1alpha1.CAPAppli

env := workload.JobDefinition.Env

if useVolumeMounts(cav) {
if useVolumeMountsForServiceCredentials(cav) {
// Get ServiceInfos for consumed BTP services
consumedServiceInfos := getConsumedServiceInfos(getConsumedServiceMap(workload.ConsumedBTPServices), ca.Spec.BTP.Services)

env = updateServiceBindingRootEnv(env)
serviceSecretVolumeMounts = getVolumeMounts(consumedServiceInfos)
serviceSecretVolumes = getVolumes(consumedServiceInfos)
serviceSecretVolumeMounts = getServiceCredentialVolumeMounts(consumedServiceInfos)
serviceSecretVolumes = getServiceCredentialVolumes(consumedServiceInfos)
} else {
envFrom = getEnvFrom(vcapSecretName)
}
Expand Down Expand Up @@ -699,7 +699,7 @@ func (c *Controller) updateDeployment(ca *v1alpha1.CAPApplication, cav *v1alpha1

// Get VCAP secret name
err = nil
if !useVolumeMounts(cav) {
if !useVolumeMountsForServiceCredentials(cav) {
vcapSecretName, err = createVCAPSecret(deploymentName, cav.Namespace, ownerRef, consumedServiceInfos, c.kubeClient)
}

Expand All @@ -724,13 +724,13 @@ func newDeployment(ca *v1alpha1.CAPApplication, cav *v1alpha1.CAPApplicationVers
Env: workload.DeploymentDefinition.Env,
}

if useVolumeMounts(cav) {
if useVolumeMountsForServiceCredentials(cav) {
// Get ServiceInfos for consumed BTP services
consumedServiceInfos := getConsumedServiceInfos(getConsumedServiceMap(workload.ConsumedBTPServices), ca.Spec.BTP.Services)

params.Env = updateServiceBindingRootEnv(params.Env)
params.VolumeMounts = getVolumeMounts(consumedServiceInfos)
params.Volumes = getVolumes(consumedServiceInfos)
params.VolumeMounts = getServiceCredentialVolumeMounts(consumedServiceInfos)
params.Volumes = getServiceCredentialVolumes(consumedServiceInfos)
} else {
params.EnvFrom = getEnvFrom(vcapSecretName)
}
Expand Down
6 changes: 3 additions & 3 deletions internal/controller/reconcile-captenantoperation.go
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ func (c *Controller) initiateJobForCAPTenantOperationStep(ctx context.Context, c
consumedServiceInfos := getConsumedServiceInfos(getConsumedServiceMap(workload.ConsumedBTPServices), relatedResources.CAPApplication.Spec.BTP.Services)

// check volume mount annotation
useVolumeMount := useVolumeMounts(relatedResources.CAPApplicationVersion)
useVolumeMount := useVolumeMountsForServiceCredentials(relatedResources.CAPApplicationVersion)

// create VCAP secret from consumed BTP services
var vcapSecretName string
Expand Down Expand Up @@ -442,8 +442,8 @@ func (c *Controller) initiateJobForCAPTenantOperationStep(ctx context.Context, c

if useVolumeMount {
params.Env = updateServiceBindingRootEnv(params.Env)
params.volumeMounts = getVolumeMounts(consumedServiceInfos)
params.volumes = getVolumes(consumedServiceInfos)
params.volumeMounts = getServiceCredentialVolumeMounts(consumedServiceInfos)
params.volumes = getServiceCredentialVolumes(consumedServiceInfos)
} else {
params.EnvFrom = getEnvFrom(vcapSecretName)
}
Expand Down
10 changes: 5 additions & 5 deletions internal/controller/reconcile.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const (
AnnotationSubscriptionContextSecret = "sme.sap.com/subscription-context-secret"
AnnotationProviderSubAccountId = "sme.sap.com/provider-sub-account-id"
AnnotationEnableCleanupMonitoring = "sme.sap.com/enable-cleanup-monitoring"
AnnotationUseVolumeMount = "sme.sap.com/use-credential-volume-mount"
AnnotationUseCredentialVolumeMount = "sme.sap.com/use-credential-volume-mount"
FinalizerCAPApplication = "sme.sap.com/capapplication"
FinalizerCAPApplicationVersion = "sme.sap.com/capapplicationversion"
FinalizerCAPTenant = "sme.sap.com/captenant"
Expand Down Expand Up @@ -621,24 +621,24 @@ func getWorkloadName(cavName, workloadName string) string {
return fmt.Sprintf("%s-%s", cavName, strings.ToLower(workloadName))
}

func getVolumeMounts(serviceInfos []v1alpha1.ServiceInfo) []corev1.VolumeMount {
func getServiceCredentialVolumeMounts(serviceInfos []v1alpha1.ServiceInfo) []corev1.VolumeMount {
volumeMounts := []corev1.VolumeMount{}
for _, serviceInfo := range serviceInfos {
volumeMounts = append(volumeMounts, corev1.VolumeMount{Name: serviceInfo.Name, MountPath: path.Join(defaultServiceBindingRootEnv.Value, serviceInfo.Class), ReadOnly: true})
}
return volumeMounts
}

func getVolumes(serviceInfos []v1alpha1.ServiceInfo) []corev1.Volume {
func getServiceCredentialVolumes(serviceInfos []v1alpha1.ServiceInfo) []corev1.Volume {
volumes := []corev1.Volume{}
for _, serviceInfo := range serviceInfos {
volumes = append(volumes, corev1.Volume{Name: serviceInfo.Name, VolumeSource: corev1.VolumeSource{Secret: &corev1.SecretVolumeSource{SecretName: serviceInfo.Secret}}})
}
return volumes
}

func useVolumeMounts(cav *v1alpha1.CAPApplicationVersion) bool {
value, exists := cav.Annotations[AnnotationUseVolumeMount]
func useVolumeMountsForServiceCredentials(cav *v1alpha1.CAPApplicationVersion) bool {
value, exists := cav.Annotations[AnnotationUseCredentialVolumeMount]
return exists && value == "true"
}

Expand Down

0 comments on commit 388b7d5

Please sign in to comment.