Skip to content

Commit

Permalink
fix dereferencing null secrets
Browse files Browse the repository at this point in the history
  • Loading branch information
joejulian committed Nov 1, 2024
1 parent e86b1e5 commit fc318e7
Show file tree
Hide file tree
Showing 3 changed files with 156 additions and 20 deletions.
36 changes: 18 additions & 18 deletions pkg/sanity/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ var _ = DescribeSanity("Controller Service [Controller Server]", func(sc *TestCo
VolumeCapabilities: []*csi.VolumeCapability{
TestVolumeCapabilityWithAccessType(sc, csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER),
},
Secrets: sc.Secrets.CreateVolumeSecret,
Secrets: sc.GetCreateVolumeSecret(),
Parameters: sc.Config.TestVolumeParameters,
}

Expand Down Expand Up @@ -296,7 +296,7 @@ var _ = DescribeSanity("Controller Service [Controller Server]", func(sc *TestCo
VolumeCapabilities: []*csi.VolumeCapability{
TestVolumeCapabilityWithAccessType(sc, csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER),
},
Secrets: sc.Secrets.CreateVolumeSecret,
Secrets: sc.GetCreateVolumeSecret(),
Parameters: sc.Config.TestVolumeParameters,
}

Expand Down Expand Up @@ -340,7 +340,7 @@ var _ = DescribeSanity("Controller Service [Controller Server]", func(sc *TestCo
VolumeCapabilities: []*csi.VolumeCapability{
TestVolumeCapabilityWithAccessType(sc, csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER),
},
Secrets: sc.Secrets.CreateVolumeSecret,
Secrets: sc.GetCreateVolumeSecret(),
Parameters: sc.Config.TestVolumeParameters,
}
vol := r.MustCreateVolume(context.Background(), req)
Expand Down Expand Up @@ -374,7 +374,7 @@ var _ = DescribeSanity("Controller Service [Controller Server]", func(sc *TestCo
rsp, err := r.CreateVolume(
context.Background(),
&csi.CreateVolumeRequest{
Secrets: sc.Secrets.CreateVolumeSecret,
Secrets: sc.GetCreateVolumeSecret(),
Parameters: sc.Config.TestVolumeParameters,
},
)
Expand All @@ -387,7 +387,7 @@ var _ = DescribeSanity("Controller Service [Controller Server]", func(sc *TestCo
context.Background(),
&csi.CreateVolumeRequest{
Name: name,
Secrets: sc.Secrets.CreateVolumeSecret,
Secrets: sc.GetCreateVolumeSecret(),
Parameters: sc.Config.TestVolumeParameters,
},
)
Expand All @@ -410,7 +410,7 @@ var _ = DescribeSanity("Controller Service [Controller Server]", func(sc *TestCo
CapacityRange: &csi.CapacityRange{
RequiredBytes: TestVolumeSize(sc),
},
Secrets: sc.Secrets.CreateVolumeSecret,
Secrets: sc.GetCreateVolumeSecret(),
Parameters: sc.Config.TestVolumeParameters,
},
)
Expand All @@ -431,7 +431,7 @@ var _ = DescribeSanity("Controller Service [Controller Server]", func(sc *TestCo
CapacityRange: &csi.CapacityRange{
RequiredBytes: TestVolumeSize(sc),
},
Secrets: sc.Secrets.CreateVolumeSecret,
Secrets: sc.GetCreateVolumeSecret(),
Parameters: sc.Config.TestVolumeParameters,
},
)
Expand Down Expand Up @@ -462,7 +462,7 @@ var _ = DescribeSanity("Controller Service [Controller Server]", func(sc *TestCo
CapacityRange: &csi.CapacityRange{
RequiredBytes: size,
},
Secrets: sc.Secrets.CreateVolumeSecret,
Secrets: sc.GetCreateVolumeSecret(),
Parameters: sc.Config.TestVolumeParameters,
},
)
Expand All @@ -479,7 +479,7 @@ var _ = DescribeSanity("Controller Service [Controller Server]", func(sc *TestCo
CapacityRange: &csi.CapacityRange{
RequiredBytes: size,
},
Secrets: sc.Secrets.CreateVolumeSecret,
Secrets: sc.GetCreateVolumeSecret(),
Parameters: sc.Config.TestVolumeParameters,
},
)
Expand All @@ -504,7 +504,7 @@ var _ = DescribeSanity("Controller Service [Controller Server]", func(sc *TestCo
RequiredBytes: size1,
LimitBytes: size1,
},
Secrets: sc.Secrets.CreateVolumeSecret,
Secrets: sc.GetCreateVolumeSecret(),
Parameters: sc.Config.TestVolumeParameters,
},
)
Expand All @@ -521,7 +521,7 @@ var _ = DescribeSanity("Controller Service [Controller Server]", func(sc *TestCo
RequiredBytes: size2,
LimitBytes: size2,
},
Secrets: sc.Secrets.CreateVolumeSecret,
Secrets: sc.GetCreateVolumeSecret(),
Parameters: sc.Config.TestVolumeParameters,
},
)
Expand All @@ -543,7 +543,7 @@ var _ = DescribeSanity("Controller Service [Controller Server]", func(sc *TestCo
CapacityRange: &csi.CapacityRange{
RequiredBytes: size,
},
Secrets: sc.Secrets.CreateVolumeSecret,
Secrets: sc.GetCreateVolumeSecret(),
Parameters: sc.Config.TestVolumeParameters,
},
)
Expand Down Expand Up @@ -722,7 +722,7 @@ var _ = DescribeSanity("Controller Service [Controller Server]", func(sc *TestCo
CapacityRange: &csi.CapacityRange{
RequiredBytes: TestVolumeSize(sc),
},
Secrets: sc.Secrets.CreateVolumeSecret,
Secrets: sc.GetCreateVolumeSecret(),
Parameters: sc.Config.TestVolumeParameters,
},
)
Expand Down Expand Up @@ -768,7 +768,7 @@ var _ = DescribeSanity("Controller Service [Controller Server]", func(sc *TestCo
CapacityRange: &csi.CapacityRange{
RequiredBytes: TestVolumeSize(sc),
},
Secrets: sc.Secrets.CreateVolumeSecret,
Secrets: sc.GetCreateVolumeSecret(),
Parameters: sc.Config.TestVolumeParameters,
},
)
Expand Down Expand Up @@ -799,7 +799,7 @@ var _ = DescribeSanity("Controller Service [Controller Server]", func(sc *TestCo
CapacityRange: &csi.CapacityRange{
RequiredBytes: TestVolumeSize(sc),
},
Secrets: sc.Secrets.CreateVolumeSecret,
Secrets: sc.GetCreateVolumeSecret(),
Parameters: sc.Config.TestVolumeParameters,
},
)
Expand Down Expand Up @@ -954,7 +954,7 @@ var _ = DescribeSanity("Controller Service [Controller Server]", func(sc *TestCo
VolumeCapabilities: []*csi.VolumeCapability{
TestVolumeCapabilityWithAccessType(sc, csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER),
},
Secrets: sc.Secrets.CreateVolumeSecret,
Secrets: sc.GetCreateVolumeSecret(),
Parameters: sc.Config.TestVolumeParameters,
},
)
Expand Down Expand Up @@ -996,7 +996,7 @@ var _ = DescribeSanity("Controller Service [Controller Server]", func(sc *TestCo
VolumeCapabilities: []*csi.VolumeCapability{
TestVolumeCapabilityWithAccessType(sc, csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER),
},
Secrets: sc.Secrets.CreateVolumeSecret,
Secrets: sc.GetCreateVolumeSecret(),
Parameters: sc.Config.TestVolumeParameters,
},
)
Expand Down Expand Up @@ -1509,7 +1509,7 @@ var _ = DescribeSanity("ExpandVolume [Controller Server]", func(sc *TestContext)
TestVolumeCapabilityWithAccessType(sc, csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER),
},
Parameters: sc.Config.TestVolumeParameters,
Secrets: sc.Secrets.CreateVolumeSecret,
Secrets: sc.GetCreateVolumeSecret(),
CapacityRange: &csi.CapacityRange{
RequiredBytes: TestVolumeSize(sc),
},
Expand Down
4 changes: 2 additions & 2 deletions pkg/sanity/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ var _ = DescribeSanity("Node Service", func(sc *TestContext) {
CapacityRange: &csi.CapacityRange{
RequiredBytes: TestVolumeSize(sc),
},
Secrets: sc.Secrets.CreateVolumeSecret,
Secrets: sc.GetCreateVolumeSecret(),
Parameters: sc.Config.TestVolumeParameters,
},
)
Expand Down Expand Up @@ -550,7 +550,7 @@ var _ = DescribeSanity("Node Service", func(sc *TestContext) {
},
},
},
Secrets: sc.Secrets.CreateVolumeSecret,
Secrets: sc.GetCreateVolumeSecret(),
Parameters: sc.Config.TestVolumeParameters,
},
)
Expand Down
136 changes: 136 additions & 0 deletions pkg/sanity/sanity.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,142 @@ func NewTestContext(config *TestConfig) *TestContext {
}
}

// GetCreateVolumeSecret retrieves the secret credentials required for creating
// a volume. This function returns a map containing the key-value pairs of the
// secret if available in the TestContext's CSISecrets structure. If no secret
// is defined for CreateVolumeSecret, it returns nil.
func (tc *TestContext) GetCreateVolumeSecret() map[string]string {
if tc.Secrets == nil {
return nil
}
return tc.Secrets.CreateVolumeSecret
}

// GetDeleteVolumeSecret retrieves the secret credentials required for deleting
// a volume. This function returns a map containing the key-value pairs of the
// secret if available in the TestContext's CSISecrets structure. If no secret
// is defined for DeleteVolumeSecret, it returns nil.
func (tc *TestContext) GetDeleteVolumeSecret() map[string]string {
if tc.Secrets == nil {
return nil
}
return tc.Secrets.DeleteVolumeSecret
}

// GetControllerPublishVolumeSecret retrieves the secret credentials required
// for publishing a volume by the controller. This function returns a map
// containing the key-value pairs of the secret if available in the TestContext's
// CSISecrets structure. If no secret is defined for ControllerPublishVolumeSecret,
// it returns nil.
func (tc *TestContext) GetControllerPublishVolumeSecret() map[string]string {
if tc.Secrets == nil {
return nil
}
return tc.Secrets.ControllerPublishVolumeSecret
}

// GetControllerUnpublishVolumeSecret retrieves the secret credentials required
// for unpublishing a volume by the controller. This function returns a map
// containing the key-value pairs of the secret if available in the TestContext's
// CSISecrets structure. If no secret is defined for ControllerUnpublishVolumeSecret,
// it returns nil.
func (tc *TestContext) GetControllerUnpublishVolumeSecret() map[string]string {
if tc.Secrets == nil {
return nil
}
return tc.Secrets.ControllerUnpublishVolumeSecret
}

// GetControllerValidateVolumeCapabilitiesSecret retrieves the secret credentials
// required for validating volume capabilities. This function returns a map
// containing the key-value pairs of the secret if available in the TestContext's
// CSISecrets structure. If no secret is defined for ControllerValidateVolumeCapabilitiesSecret,
// it returns nil.
func (tc *TestContext) GetControllerValidateVolumeCapabilitiesSecret() map[string]string {
if tc.Secrets == nil {
return nil
}
return tc.Secrets.ControllerValidateVolumeCapabilitiesSecret
}

// GetNodeStageVolumeSecret retrieves the secret credentials required for staging
// a volume on the node. This function returns a map containing the key-value
// pairs of the secret if available in the TestContext's CSISecrets structure.
// If no secret is defined for NodeStageVolumeSecret, it returns nil.
func (tc *TestContext) GetNodeStageVolumeSecret() map[string]string {
if tc.Secrets == nil {
return nil
}
return tc.Secrets.NodeStageVolumeSecret
}

// GetNodePublishVolumeSecret retrieves the secret credentials required for
// publishing a volume on the node. This function returns a map containing
// the key-value pairs of the secret if available in the TestContext's
// CSISecrets structure. If no secret is defined for NodePublishVolumeSecret,
// it returns nil.
func (tc *TestContext) GetNodePublishVolumeSecret() map[string]string {
if tc.Secrets == nil {
return nil
}
return tc.Secrets.NodePublishVolumeSecret
}

// GetCreateSnapshotSecret retrieves the secret credentials required for creating
// a snapshot. This function returns a map containing the key-value pairs of
// the secret if available in the TestContext's CSISecrets structure. If no secret
// is defined for CreateSnapshotSecret, it returns nil.
func (tc *TestContext) GetCreateSnapshotSecret() map[string]string {
if tc.Secrets == nil {
return nil
}
return tc.Secrets.CreateSnapshotSecret
}

// GetDeleteSnapshotSecret retrieves the secret credentials required for deleting
// a snapshot. This function returns a map containing the key-value pairs of the
// secret if available in the TestContext's CSISecrets structure. If no secret is
// defined for DeleteSnapshotSecret, it returns nil.
func (tc *TestContext) GetDeleteSnapshotSecret() map[string]string {
if tc.Secrets == nil {
return nil
}
return tc.Secrets.DeleteSnapshotSecret
}

// GetControllerExpandVolumeSecret retrieves the secret credentials required
// for expanding a volume. This function returns a map containing the key-value
// pairs of the secret if available in the TestContext's CSISecrets structure.
// If no secret is defined for ControllerExpandVolumeSecret, it returns nil.
func (tc *TestContext) GetControllerExpandVolumeSecret() map[string]string {
if tc.Secrets == nil {
return nil
}
return tc.Secrets.ControllerExpandVolumeSecret
}

// GetControllerModifyVolumeSecret retrieves the secret credentials required
// for modifying a volume. This function returns a map containing the key-value
// pairs of the secret if available in the TestContext's CSISecrets structure.
// If no secret is defined for ControllerModifyVolumeSecret, it returns nil.
func (tc *TestContext) GetControllerModifyVolumeSecret() map[string]string {
if tc.Secrets == nil {
return nil
}
return tc.Secrets.ControllerModifyVolumeSecret
}

// GetListSnapshotsSecret retrieves the secret credentials required for listing
// snapshots. This function returns a map containing the key-value pairs of the
// secret if available in the TestContext's CSISecrets structure. If no secret is
// defined for ListSnapshotsSecret, it returns nil.
func (tc *TestContext) GetListSnapshotsSecret() map[string]string {
if tc.Secrets == nil {
return nil
}
return tc.Secrets.ListSnapshotsSecret
}

// Test will test the CSI driver at the specified address by
// setting up a Ginkgo suite and running it.
func Test(t GinkgoTestingT, config TestConfig) {
Expand Down

0 comments on commit fc318e7

Please sign in to comment.