Skip to content

Commit

Permalink
Fix exported function and variable
Browse files Browse the repository at this point in the history
  • Loading branch information
dargudear-google committed Dec 20, 2024
1 parent 00854c2 commit 50018eb
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 21 deletions.
2 changes: 1 addition & 1 deletion controllers/secretproviderclasspodstatus_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ func (r *SecretProviderClassPodStatusReconciler) createOrUpdateK8sSecret(ctx con
klog.InfoS("Kubernetes secret is already created", "secret", klog.ObjectRef{Namespace: namespace, Name: name})
err := r.writer.Update(ctx, secret)
if err != nil {
klog.Errorf("Unable to update kubernetes secret", "secret", klog.ObjectRef{Namespace: namespace, Name: name})
klog.ErrorS(err, "Unable to update kubernetes secret", "secret", klog.ObjectRef{Namespace: namespace, Name: name})
return err
}
klog.InfoS("successfully updated Kubernetes secret", "secret", klog.ObjectRef{Namespace: namespace, Name: name})
Expand Down
10 changes: 4 additions & 6 deletions pkg/secrets-store/nodeserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ type nodeServer struct {
// This should be used sparingly and only when the client does not fit the use case.
reader client.Reader
providerClients *PluginClientBuilder
rotationConfig *RotationConfig
rotationConfig *rotationConfig
}

const (
Expand Down Expand Up @@ -122,7 +122,7 @@ func (ns *nodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePublis
if ns.rotationConfig.enabled {
lastModificationTime, err := ns.getLastUpdateTime(targetPath)
if err != nil {
klog.Infof("could not find last modification time for %s, error: %v\n", targetPath, err)
klog.InfoS("could not find last modification time for targetpath", targetPath, "error", err)
} else if startTime.Before(lastModificationTime.Add(ns.rotationConfig.rotationPollInterval)) {
// if next rotation is not yet due, then skip the mount operation
return &csi.NodePublishVolumeResponse{}, nil
Expand Down Expand Up @@ -153,9 +153,7 @@ func (ns *nodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePublis
if isMockProvider(providerName) {
// mock provider is used only for running sanity tests against the driver

// TODO: until requiresRemount (#585) is supported, "mounted" will always be false
// and this code will always be called
if !mounted {
if !rotationEnabled && !mounted {
err := ns.mounter.Mount("tmpfs", targetPath, "tmpfs", []string{})

if err != nil {
Expand Down Expand Up @@ -198,7 +196,7 @@ func (ns *nodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePublis
// and send it to the provider in the parameters.
if parameters[CSIPodServiceAccountTokens] == "" {
// Inject pod service account token into volume attributes
klog.Error("csi.storage.k8s.io/serviceAccount.tokens is not populated, set RequiresRepublish")
klog.ErrorS(err, "csi.storage.k8s.io/serviceAccount.tokens is not populated, set RequiresRepublish")
}

// ensure it's read-only
Expand Down
16 changes: 8 additions & 8 deletions pkg/secrets-store/nodeserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client/fake"
)

func testNodeServer(t *testing.T, client client.Client, reporter StatsReporter, rotationConfig *RotationConfig) (*nodeServer, error) {
func testNodeServer(t *testing.T, client client.Client, reporter StatsReporter, rotationConfig *rotationConfig) (*nodeServer, error) {
t.Helper()

// Create a mock provider named "provider1".
Expand Down Expand Up @@ -228,7 +228,7 @@ func TestNodePublishVolume_Errors(t *testing.T) {
t.Run(test.name, func(t *testing.T) {
r := mocks.NewFakeReporter()

ns, err := testNodeServer(t, fake.NewClientBuilder().WithScheme(s).WithObjects(test.initObjects...).Build(), r, &RotationConfig{})
ns, err := testNodeServer(t, fake.NewClientBuilder().WithScheme(s).WithObjects(test.initObjects...).Build(), r, &rotationConfig{})
if err != nil {
t.Fatalf("expected error to be nil, got: %+v", err)
}
Expand Down Expand Up @@ -268,7 +268,7 @@ func TestNodePublishVolume(t *testing.T) {
name string
nodePublishVolReq *csi.NodePublishVolumeRequest
initObjects []client.Object
rotationConfig *RotationConfig
rotationConfig *rotationConfig
}{
{
name: "volume mount",
Expand Down Expand Up @@ -296,7 +296,7 @@ func TestNodePublishVolume(t *testing.T) {
},
},
},
rotationConfig: &RotationConfig{
rotationConfig: &rotationConfig{
enabled: false,
rotationPollInterval: time.Minute,
},
Expand Down Expand Up @@ -330,7 +330,7 @@ func TestNodePublishVolume(t *testing.T) {
},
},
},
rotationConfig: &RotationConfig{
rotationConfig: &rotationConfig{
enabled: true,
rotationPollInterval: -1 * time.Minute, // Using negative interval to pass the rotation interval check in unit tests
},
Expand Down Expand Up @@ -361,7 +361,7 @@ func TestNodePublishVolume(t *testing.T) {
},
},
},
rotationConfig: &RotationConfig{
rotationConfig: &rotationConfig{
enabled: true,
rotationPollInterval: time.Minute,
},
Expand Down Expand Up @@ -427,7 +427,7 @@ func TestNodeUnpublishVolume(t *testing.T) {
)

r := mocks.NewFakeReporter()
ns, err := testNodeServer(t, fake.NewClientBuilder().WithScheme(s).Build(), r, &RotationConfig{})
ns, err := testNodeServer(t, fake.NewClientBuilder().WithScheme(s).Build(), r, &rotationConfig{})
if err != nil {
t.Fatalf("expected error to be nil, got: %+v", err)
}
Expand Down Expand Up @@ -506,7 +506,7 @@ func TestNodeUnpublishVolume_Error(t *testing.T) {
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
r := mocks.NewFakeReporter()
ns, err := testNodeServer(t, fake.NewClientBuilder().WithScheme(s).Build(), r, &RotationConfig{})
ns, err := testNodeServer(t, fake.NewClientBuilder().WithScheme(s).Build(), r, &rotationConfig{})
if err != nil {
t.Fatalf("expected error to be nil, got: %+v", err)
}
Expand Down
12 changes: 6 additions & 6 deletions pkg/secrets-store/secrets-store.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ type SecretsStore struct {
ids *identityServer
}

// RotationConfig stores the information required to rotate the secrets.
type RotationConfig struct {
// rotationConfig stores the information required to rotate the secrets.
type rotationConfig struct {
enabled bool
rotationPollInterval time.Duration
}
Expand All @@ -56,7 +56,7 @@ func NewSecretsStoreDriver(driverName, nodeID, endpoint string,
os.Exit(1)
}

rc := NewRotationConfig(rotationEnabled, rotationPollInterval)
rc := newRotationConfig(rotationEnabled, rotationPollInterval)
ns, err := newNodeServer(nodeID, mount.New(""), providerClients, client, reader, sr, rc)
if err != nil {
klog.ErrorS(err, "failed to initialize node server")
Expand All @@ -77,7 +77,7 @@ func newNodeServer(nodeID string,
client client.Client,
reader client.Reader,
statsReporter StatsReporter,
rotationConfig *RotationConfig) (*nodeServer, error) {
rotationConfig *rotationConfig) (*nodeServer, error) {
return &nodeServer{
mounter: mounter,
reporter: statsReporter,
Expand All @@ -89,8 +89,8 @@ func newNodeServer(nodeID string,
}, nil
}

func NewRotationConfig(enabled bool, interval time.Duration) *RotationConfig {
return &RotationConfig{
func newRotationConfig(enabled bool, interval time.Duration) *rotationConfig {
return &rotationConfig{
enabled: enabled,
rotationPollInterval: interval,
}
Expand Down

0 comments on commit 50018eb

Please sign in to comment.