Skip to content

Commit 4df9a6d

Browse files
Fix the comments, logs and delete unused configs
1 parent a1f19b7 commit 4df9a6d

File tree

8 files changed

+30
-59
lines changed

8 files changed

+30
-59
lines changed

Makefile

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -532,15 +532,6 @@ manifests: $(CONTROLLER_GEN) $(KUSTOMIZE) ## Generate manifests e.g. CRD, RBAC
532532
@sed -i '1s/^/{{ if .Values.enableSecretRotation }}\n/gm; s/namespace: .*/namespace: {{ .Release.Namespace }}/gm; $$s/$$/\n{{ end }}/gm' manifest_staging/charts/secrets-store-csi-driver/templates/role-rotation_binding.yaml
533533
@sed -i '/^roleRef:/i \ \ labels:\n{{ include \"sscd.labels\" . | indent 4 }}' manifest_staging/charts/secrets-store-csi-driver/templates/role-rotation_binding.yaml
534534

535-
# Generate token requests specific RBAC
536-
$(CONTROLLER_GEN) rbac:roleName=secretprovidertokenrequest-role paths="./controllers/tokenrequest" output:dir=config/rbac-tokenrequest
537-
$(KUSTOMIZE) build config/rbac-tokenrequest -o manifest_staging/deploy/rbac-secretprovidertokenrequest.yaml
538-
cp config/rbac-tokenrequest/role.yaml manifest_staging/charts/secrets-store-csi-driver/templates/role-tokenrequest.yaml
539-
cp config/rbac-tokenrequest/role_binding.yaml manifest_staging/charts/secrets-store-csi-driver/templates/role-tokenrequest_binding.yaml
540-
@sed -i '1s/^/{{ if .Values.tokenRequests }}\n/gm; $$s/$$/\n{{ end }}/gm' manifest_staging/charts/secrets-store-csi-driver/templates/role-tokenrequest.yaml
541-
@sed -i '/^rules:/i \ \ labels:\n{{ include \"sscd.labels\" . | indent 4 }}' manifest_staging/charts/secrets-store-csi-driver/templates/role-tokenrequest.yaml
542-
@sed -i '1s/^/{{ if .Values.tokenRequests }}\n/gm; s/namespace: .*/namespace: {{ .Release.Namespace }}/gm; $$s/$$/\n{{ end }}/gm' manifest_staging/charts/secrets-store-csi-driver/templates/role-tokenrequest_binding.yaml
543-
@sed -i '/^roleRef:/i \ \ labels:\n{{ include \"sscd.labels\" . | indent 4 }}' manifest_staging/charts/secrets-store-csi-driver/templates/role-tokenrequest_binding.yaml
544535

545536
.PHONY: generate-protobuf
546537
generate-protobuf: $(PROTOC) $(PROTOC_GEN_GO) $(PROTOC_GEN_GO_GRPC) # generates protobuf

config/rbac-tokenrequest/kustomization.yaml

Lines changed: 0 additions & 3 deletions
This file was deleted.

config/rbac-tokenrequest/role.yaml

Lines changed: 0 additions & 12 deletions
This file was deleted.

config/rbac-tokenrequest/role_binding.yaml

Lines changed: 0 additions & 12 deletions
This file was deleted.

controllers/secretproviderclasspodstatus_controller.go

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ func (r *SecretProviderClassPodStatusReconciler) processIfBelongsToNode(objMeta
397397
}
398398

399399
// createOrUpdateK8sSecret creates K8s secret with data from mounted files
400-
// If a secret with the same name already exists in the namespace of the pod, the error is nil.
400+
// If a secret with the same name already exists in the namespace of the pod, it will update that existing secret.
401401
func (r *SecretProviderClassPodStatusReconciler) createOrUpdateK8sSecret(ctx context.Context, name, namespace string, datamap map[string][]byte, labelsmap map[string]string, annotationsmap map[string]string, secretType corev1.SecretType) error {
402402
secret := &corev1.Secret{
403403
ObjectMeta: metav1.ObjectMeta{
@@ -415,17 +415,18 @@ func (r *SecretProviderClassPodStatusReconciler) createOrUpdateK8sSecret(ctx con
415415
klog.InfoS("successfully created Kubernetes secret", "secret", klog.ObjectRef{Namespace: namespace, Name: name})
416416
return nil
417417
}
418-
if apierrors.IsAlreadyExists(err) {
419-
klog.InfoS("Kubernetes secret is already created", "secret", klog.ObjectRef{Namespace: namespace, Name: name})
420-
err := r.writer.Update(ctx, secret)
421-
if err != nil {
422-
klog.ErrorS(err, "Unable to update kubernetes secret", "secret", klog.ObjectRef{Namespace: namespace, Name: name})
423-
return err
424-
}
425-
klog.InfoS("successfully updated Kubernetes secret", "secret", klog.ObjectRef{Namespace: namespace, Name: name})
426-
return nil
418+
if !apierrors.IsAlreadyExists(err) {
419+
return err
427420
}
428-
return err
421+
422+
klog.InfoS("Kubernetes secret is already created", "secret", klog.ObjectRef{Namespace: namespace, Name: name})
423+
err = r.writer.Update(ctx, secret)
424+
if err != nil {
425+
klog.ErrorS(err, "Unable to update kubernetes secret", "secret", klog.ObjectRef{Namespace: namespace, Name: name})
426+
return err
427+
}
428+
klog.InfoS("successfully updated Kubernetes secret", "secret", klog.ObjectRef{Namespace: namespace, Name: name})
429+
return nil
429430
}
430431

431432
// patchSecretWithOwnerRef patches the secret owner reference with the spc pod status

manifest_staging/charts/secrets-store-csi-driver/templates/csidriver.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,5 @@ spec:
1414
requiresRepublish: true
1515
tokenRequests:
1616
{{- toYaml .Values.tokenRequests | nindent 2 }}
17+
requiresRepublish: {{ .Values.requiresRepublish }}
1718
{{- end }}

manifest_staging/charts/secrets-store-csi-driver/values.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,10 @@ tokenRequests: []
239239
# - audience: aud1
240240
# - audience: aud2
241241

242+
# To set the requiresRepublish which can be used to refresh the mounted secret periodically
243+
# refer to https://kubernetes-csi.github.io/docs/token-requests.html for more details.
244+
# Supported only for Kubernetes v1.20+
245+
requiresRepublish: true
242246
# -- Labels to apply to all resources
243247
commonLabels: {}
244248
# team_name: dev

pkg/secrets-store/nodeserver.go

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,9 @@ func (ns *nodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePublis
8080
defer func() {
8181
if err != nil {
8282
// if there is an error at any stage during node publish volume and if the path
83-
// has already been mounted, unmount the target path so the next time kubelet calls
83+
// has already been mounted if the rotation is disabled, unmount the target path so the next time kubelet calls
8484
// again for mount, entire node publish volume is retried
85+
// If the rotation is enabled the target path won't be unmounted just the next call will try to mount the content.
8586
if targetPath != "" && mounted && !isRemountRequest {
8687
klog.InfoS("unmounting target path as node publish volume failed", "targetPath", targetPath, "pod", klog.ObjectRef{Namespace: podNamespace, Name: podName})
8788
if unmountErr := ns.mounter.Unmount(targetPath); unmountErr != nil {
@@ -120,16 +121,6 @@ func (ns *nodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePublis
120121
podNamespace = attrib[CSIPodNamespace]
121122
podUID = attrib[CSIPodUID]
122123

123-
if ns.rotationConfig.enabled {
124-
lastModificationTime, err := ns.getLastUpdateTime(targetPath)
125-
if err != nil {
126-
klog.InfoS("could not find last modification time for targetpath", targetPath, "error", err)
127-
} else if startTime.Before(lastModificationTime.Add(ns.rotationConfig.rotationPollInterval)) {
128-
// if next rotation is not yet due, then skip the mount operation
129-
return &csi.NodePublishVolumeResponse{}, nil
130-
}
131-
}
132-
133124
mounted, err = ns.ensureMountPoint(targetPath)
134125
if err != nil {
135126
// kubelet will not create the CSI NodePublishVolume target directory in 1.20+, in accordance with the CSI specification.
@@ -152,6 +143,16 @@ func (ns *nodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePublis
152143
return &csi.NodePublishVolumeResponse{}, nil
153144
}
154145

146+
if rotationEnabled {
147+
lastModificationTime, err := ns.getLastUpdateTime(targetPath)
148+
if err != nil {
149+
klog.InfoS("could not find last modification time for targetpath", targetPath, "error", err)
150+
} else if startTime.Before(lastModificationTime.Add(ns.rotationConfig.rotationPollInterval)) {
151+
// if next rotation is not yet due, then skip the mount operation
152+
return &csi.NodePublishVolumeResponse{}, nil
153+
}
154+
}
155+
155156
klog.V(2).InfoS("node publish volume", "target", targetPath, "volumeId", volumeID, "mount flags", mountFlags)
156157

157158
if isMockProvider(providerName) {
@@ -200,7 +201,7 @@ func (ns *nodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePublis
200201
// and send it to the provider in the parameters.
201202
if parameters[CSIPodServiceAccountTokens] == "" {
202203
// Inject pod service account token into volume attributes
203-
klog.ErrorS(err, "csi.storage.k8s.io/serviceAccount.tokens is not populated, set RequiresRepublish")
204+
klog.Info(err, "csi.storage.k8s.io/serviceAccount.tokens is not populated")
204205
}
205206

206207
// ensure it's read-only

0 commit comments

Comments
 (0)