Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apis/v1/secretproviderclasspodstatus_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ type SecretProviderClassPodStatusStatus struct {
Mounted bool `json:"mounted,omitempty"`
TargetPath string `json:"targetPath,omitempty"`
Objects []SecretProviderClassObject `json:"objects,omitempty"`
FSGroup string `json:"fsGroup,omitempty"`
}

// SecretProviderClassObject defines the object fetched from external secrets store
Expand Down
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Revert changes to charts directory. Chart changes should only be made in the manifest_staging directory.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ spec:
description: SecretProviderClassPodStatusStatus defines the observed state
of SecretProviderClassPodStatus
properties:
fsGroup:
type: string
mounted:
type: boolean
objects:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ spec:
description: SecretProviderClassPodStatusStatus defines the observed state
of SecretProviderClassPodStatus
properties:
fsGroup:
type: string
mounted:
type: boolean
objects:
Expand Down
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Revert changes to deploy directory. Chart changes should only be made in the manifest_staging directory.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ spec:
description: SecretProviderClassPodStatusStatus defines the observed state
of SecretProviderClassPodStatus
properties:
fsGroup:
type: string
mounted:
type: boolean
objects:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ spec:
description: SecretProviderClassPodStatusStatus defines the observed state
of SecretProviderClassPodStatus
properties:
fsGroup:
type: string
mounted:
type: boolean
objects:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ spec:
description: SecretProviderClassPodStatusStatus defines the observed state
of SecretProviderClassPodStatus
properties:
fsGroup:
type: string
mounted:
type: boolean
objects:
Expand Down
5 changes: 5 additions & 0 deletions pkg/constants/constants.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package constants
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to add boilerplate to the top of the file.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


const (
NoGID = int64(-1) // Use the default gid -1 to indicate no change in FSGroup
)
3 changes: 2 additions & 1 deletion pkg/errors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,6 @@ const (
// PodVolumeNotFound error
PodVolumeNotFound = "PodVolumeNotFound"
// FileWriteError error
FileWriteError = "FileWriteError"
FileWriteError = "FileWriteError"
FailedToParseFSGroup = "FailedToParseFSGroup"
)
15 changes: 14 additions & 1 deletion pkg/rotation/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@ import (
"encoding/json"
"fmt"
"os"
"strconv"
"strings"
"time"

secretsstorev1 "sigs.k8s.io/secrets-store-csi-driver/apis/v1"
"sigs.k8s.io/secrets-store-csi-driver/controllers"
secretsStoreClient "sigs.k8s.io/secrets-store-csi-driver/pkg/client/clientset/versioned"
"sigs.k8s.io/secrets-store-csi-driver/pkg/constants"
internalerrors "sigs.k8s.io/secrets-store-csi-driver/pkg/errors"
"sigs.k8s.io/secrets-store-csi-driver/pkg/k8s"
secretsstore "sigs.k8s.io/secrets-store-csi-driver/pkg/secrets-store"
Expand Down Expand Up @@ -398,7 +400,18 @@ func (r *Reconciler) reconcile(ctx context.Context, spcps *secretsstorev1.Secret
r.generateEvent(pod, corev1.EventTypeWarning, mountRotationFailedReason, fmt.Sprintf("failed to lookup provider client: %q", providerName))
return fmt.Errorf("failed to lookup provider client: %q", providerName)
}
newObjectVersions, errorReason, err := secretsstore.MountContent(ctx, providerClient, string(paramsJSON), string(secretsJSON), spcps.Status.TargetPath, string(permissionJSON), oldObjectVersions)
gid := constants.NoGID
if spcps.Status.FSGroup != "" {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if spcps.Status.FSGroup != "" {
if len(spcps.Status.FSGroup) > 0 {

this is the code style we follow in Kubernetes

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

gid, err = strconv.ParseInt(spcps.Status.FSGroup, 10, 64)
if err != nil {
errorReason = internalerrors.FailedToParseFSGroup
errStr := fmt.Sprintf("failed to rotate objects for pod %s/%s, err: %v, invalid FSGroup:%s", spcps.Namespace, spcps.Status.PodName, err, spcps.Status.FSGroup)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
errStr := fmt.Sprintf("failed to rotate objects for pod %s/%s, err: %v, invalid FSGroup:%s", spcps.Namespace, spcps.Status.PodName, err, spcps.Status.FSGroup)
errStr := fmt.Sprintf("failed to rotate objects for pod %s/%s, invalid FSGroup:%s, err: %w", spcps.Namespace, spcps.Status.PodName, spcps.Status.FSGroup, err)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, thanks for the catch. This makes more sense to read as a log.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

however, %w (wrap) format seems to be specific only to fmt.Errorf. Thus, restructured the code to use %v in the Sprintf and %w in the Errorf

r.generateEvent(pod, corev1.EventTypeWarning, mountRotationFailedReason, errStr)
return fmt.Errorf("%s", errStr)
}
}
klog.V(5).Infof("Reconciling pod %s/%s with fsGroup: %v\n", spcps.Namespace, spcps.Status.PodName, gid)
newObjectVersions, errorReason, err := secretsstore.MountContent(ctx, providerClient, string(paramsJSON), string(secretsJSON), spcps.Status.TargetPath, string(permissionJSON), oldObjectVersions, gid)
if err != nil {
r.generateEvent(pod, corev1.EventTypeWarning, mountRotationFailedReason, fmt.Sprintf("provider mount err: %+v", err))
return fmt.Errorf("failed to rotate objects for pod %s/%s, err: %w", spcps.Namespace, spcps.Status.PodName, err)
Expand Down
Loading