Skip to content

Commit

Permalink
Fixing some linter failures found.
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristianAtDell committed Oct 15, 2024
1 parent bb313cb commit a0a5cf0
Show file tree
Hide file tree
Showing 11 changed files with 27 additions and 58 deletions.
6 changes: 5 additions & 1 deletion controllers/csm_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ var (
// - https://pkg.go.dev/sigs.k8s.io/controller-runtime@v0.9.2/pkg/reconcile

// Reconcile - main loop
func (r *ContainerStorageModuleReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
func (r *ContainerStorageModuleReconciler) Reconcile(ctxNotUsed context.Context, req ctrl.Request) (ctrl.Result, error) {
r.IncrUpdateCount()
r.trcID = fmt.Sprintf("%d", r.GetUpdateCount())
name := req.Name + "-" + r.trcID
Expand Down Expand Up @@ -1340,12 +1340,16 @@ func (r *ContainerStorageModuleReconciler) PreChecks(ctx context.Context, cr *cs
log.Infow("Driver not installed yet")
} else {
if driver.GetOwnerReferences() != nil {
found := false
cred := driver.GetOwnerReferences()
for _, m := range cred {
if m.Name == cr.Name {
log.Infow("Owner reference is found and matches")
found = true
break
}
}
if !found {
return fmt.Errorf("required Owner reference not found. Please re-install driver ")
}
}
Expand Down
10 changes: 0 additions & 10 deletions controllers/csm_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1041,7 +1041,6 @@ func (suite *CSMControllerTestSuite) TestContentWatch() {

func (suite *CSMControllerTestSuite) createReconciler() (reconciler *ContainerStorageModuleReconciler) {
logType := logger.DevelopmentLogLevel
logger.SetLoggerLevel(logType)
_, log := logger.GetNewContextWithLogger("0")
log.Infof("Version : %s", logType)

Expand Down Expand Up @@ -2194,15 +2193,6 @@ func (suite *CSMControllerTestSuite) ShouldFail(method string, obj runtime.Objec
return nil
}

// debugFakeObjects prints the runtime objects in the fake client
func (suite *CSMControllerTestSuite) debugFakeObjects() {
objects := suite.fakeClient.(*crclient.Client).Objects
for key, o := range objects {
unittestLogger.Info("found fake object ", "name", key.Name)
unittestLogger.Info("found fake object ", "object", fmt.Sprintf("%#v", o))
}
}

func (suite *CSMControllerTestSuite) makeFakeRevProxyCSM(name string, ns string, withFinalizer bool, modules []v1.Module, driverType string) {
// Create secrets and config map for Reconcile
sec := shared.MakeSecret("csirevproxy-tls-secret", ns, configVersion)
Expand Down
2 changes: 0 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,6 @@ func main() {

ctrl.SetLogger(crzap.New(crzap.UseFlagOptions(&opts)))

logType := logger.DevelopmentLogLevel
logger.SetLoggerLevel(logType)
_, log := logger.GetNewContextWithLogger("main")

ctrl.SetLogger(crzap.New(crzap.UseFlagOptions(&opts)))
Expand Down
5 changes: 4 additions & 1 deletion pkg/drivers/powerflex_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,10 @@ var (
func TestPowerFlexGo(t *testing.T) {
ctx := context.Background()
for _, tt := range powerFlexTests {
tt.ct.Create(ctx, tt.sec)
err := tt.ct.Create(ctx, tt.sec)
if err != nil {
assert.Nil(t, err)
}
t.Run(tt.name, func(t *testing.T) { // #nosec G601 - Run waits for the call to complete.
err := PrecheckPowerFlex(ctx, &tt.csm, config, tt.ct)
if tt.expectedErr == "" {
Expand Down
5 changes: 4 additions & 1 deletion pkg/drivers/powermax_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,10 @@ func TestPrecheckPowerMax(t *testing.T) {
}

for _, tt := range powerMaxTests {
tt.ct.Create(ctx, tt.sec)
err := tt.ct.Create(ctx, tt.sec)
if err != nil {
assert.Nil(t, err)
}
t.Run(tt.name, func(t *testing.T) { // #nosec G601 - Run waits for the call to complete.
err := PrecheckPowerMax(ctx, &tt.csm, config, tt.ct)
if tt.expectedErr == "" {
Expand Down
11 changes: 4 additions & 7 deletions pkg/drivers/powerscale_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,9 @@ import (
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
)

var (
csmPScale = csmWithTolerations(csmv1.PowerScaleName, "shared.ConfigVersion")
powerScaleCSM = csmForPowerScale()
powerScaleCSMBadSkipCert = csmForPowerScaleBadSkipCert()
powerScaleCSMBadCertCnt = csmForPowerScaleBadCertCnt()
Expand Down Expand Up @@ -68,10 +66,6 @@ var (
{"missing secret", powerScaleCSM, powerScaleClient, powerScaleSecret, "failed to find secret"},
{"bad version", powerScaleCSMBadVersion, powerScaleClient, powerScaleSecret, "not supported"},
}

opts = zap.Options{
Development: true,
}
)

func TestGetApplyCertVolume(t *testing.T) {
Expand Down Expand Up @@ -101,7 +95,10 @@ func TestPrecheckPowerScale(t *testing.T) {
}

for _, tt := range powerScaleTests {
tt.ct.Create(ctx, tt.sec)
err := tt.ct.Create(ctx, tt.sec)
if err != nil {
assert.Nil(t, err)
}
t.Run(tt.name, func(t *testing.T) { // #nosec G601 - Run waits for the call to complete.
err := PrecheckPowerScale(ctx, &tt.csm, config, tt.ct)
if tt.expectedErr == "" {
Expand Down
5 changes: 4 additions & 1 deletion pkg/drivers/powerstore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,10 @@ func TestPrecheckPowerStore(t *testing.T) {
}

for _, tt := range powerStoreTests {
tt.ct.Create(ctx, tt.sec)
err := tt.ct.Create(ctx, tt.sec)
if err != nil {
assert.Nil(t, err)
}
t.Run(tt.name, func(t *testing.T) { // #nosec G601 - Run waits for the call to complete.
err := PrecheckPowerStore(ctx, &tt.csm, config, tt.ct)
if tt.expectedErr == "" {
Expand Down
22 changes: 5 additions & 17 deletions pkg/drivers/unity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,11 @@ func TestPrecheckUnity(t *testing.T) {
}

for _, tt := range unityTests {
tt.ct.Create(ctx, tt.sec)
err := tt.ct.Create(ctx, tt.sec)
if err != nil {
assert.Nil(t, err)
}

t.Run(tt.name, func(t *testing.T) { // #nosec G601 - Run waits for the call to complete.
err := PrecheckUnity(ctx, &tt.csm, config, tt.ct)
if tt.expectedErr == "" {
Expand Down Expand Up @@ -169,19 +173,3 @@ func csmForUnitySkipCertISFalse() csmv1.ContainerStorageModule {

return res
}

// makes a csm object with bad allowed network input
func csmForUnityAllowedNetwork() csmv1.ContainerStorageModule {
res := shared.MakeCSM("csm", "driver-test", shared.UnityConfigVersion)

// Add log level to cover some code in GetConfigMap
envVarLogLevel1 := corev1.EnvVar{Name: "CERT_SECRET_COUNT", Value: "2"}
envVarLogLevel2 := corev1.EnvVar{Name: "X_CSI_ALLOWED_NETWORKS", Value: "THIS IS BAD INPUT NETWORK"}
res.Spec.Driver.Common.Envs = []corev1.EnvVar{envVarLogLevel1, envVarLogLevel2}

// Add unitydriver version
res.Spec.Driver.ConfigVersion = shared.UnityConfigVersion
res.Spec.Driver.CSIDriverType = csmv1.Unity

return res
}
10 changes: 1 addition & 9 deletions pkg/logger/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,9 @@ const (
LogCtxIDKey = "TraceId"
)

var defaultLogLevel LogLevel

// loggerKey holds the context key used for loggers.
type loggerKey struct{}

// SetLoggerLevel helps set defaultLogLevel, using which newLogger func helps
// create either development logger or production logger
func SetLoggerLevel(logLevel LogLevel) {
defaultLogLevel = logLevel
}

// getLogger returns the logger associated with the given context.
// If there is no logger associated with context, getLogger func will return
// a new logger.
Expand Down Expand Up @@ -89,7 +81,7 @@ func newLogger() *zap.Logger {
consoleEncoder := zapcore.NewConsoleEncoder(pe)

level := zap.InfoLevel
level = zap.DebugLevel
//level = zap.DebugLevel

core := zapcore.NewCore(consoleEncoder, zapcore.AddSync(os.Stderr), level)

Expand Down
2 changes: 0 additions & 2 deletions pkg/modules/authorization.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@ const (

var (
redisStorageClass string
authHostname string
proxyIngressClassName string
authCertificate string
authPrivateKey string
Expand Down Expand Up @@ -1268,7 +1267,6 @@ func getCerts(ctx context.Context, op utils.OperatorConfig, cr csmv1.ContainerSt

for _, component := range authModule.Components {
if component.Name == AuthProxyServerComponent {
authHostname = component.Hostname
authCertificate = component.Certificate
authPrivateKey = component.PrivateKey
}
Expand Down
7 changes: 0 additions & 7 deletions pkg/utils/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,6 @@ var checkModuleStatus = map[csmv1.ModuleType]func(context.Context, *csmv1.Contai
csmv1.AuthorizationServer: authProxyStatusCheck,
}

func getInt32(pointer *int32) int32 {
if pointer == nil {
return 0
}
return *pointer
}

// calculates deployment state of drivers only; module deployment status will be checked in checkModuleStatus
func getDeploymentStatus(ctx context.Context, instance *csmv1.ContainerStorageModule, r ReconcileCSM) (csmv1.PodStatus, error) {
log := logger.GetLogger(ctx)
Expand Down

0 comments on commit a0a5cf0

Please sign in to comment.