Skip to content

Commit

Permalink
code refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
ashleyvjoy committed Jun 9, 2024
1 parent 58bce30 commit a9262f7
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 21 deletions.
8 changes: 5 additions & 3 deletions controllers/acc_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ const (

// AccInitContainerImage - tag for init container image
AccInitContainerImage string = "<ACC_INIT_CONTAINER_IMAGE>"

// BrownfieldManifest - manifest for brownfield role/rolebinding creation
BrownfieldManifest string = "brownfield-onboard.yaml"
)

// ApexConnectivityClientReconciler reconciles a ApexConnectivityClient object
Expand Down Expand Up @@ -473,10 +476,9 @@ func DeployApexConnectivityClient(ctx context.Context, isDeleting bool, operator
err = ctrlClient.List(ctx, csmList)
if err == nil && len(csmList.Items) > 0 {
log.Info("Found existing csm installations. Proceeding to onboard them to Apex Navigator for Kubernetes")
BrownfieldCR := "brownfield-onboard.yaml"
brownfieldManifestFilePath := fmt.Sprintf("%s/clientconfig/%s/%s/%s", operatorConfig.ConfigDirectory, csmv1.DreadnoughtClient, cr.Spec.Client.ConfigVersion, BrownfieldCR)
brownfieldManifestFilePath := fmt.Sprintf("%s/clientconfig/%s/%s/%s", operatorConfig.ConfigDirectory, csmv1.DreadnoughtClient, cr.Spec.Client.ConfigVersion, BrownfieldManifest)
if err = utils.BrownfieldOnboard(ctx, brownfieldManifestFilePath, cr, ctrlClient); err != nil {
log.Error(err, "brownfield cluster onboarding failed")
log.Error(err, "error creating role/rolebindings")
}
}
log.Info("No existing csm installations found")
Expand Down
40 changes: 22 additions & 18 deletions controllers/csm_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -881,25 +881,29 @@ func (r *ContainerStorageModuleReconciler) SyncCSM(ctx context.Context, cr csmv1
}

//If dell connectivity client is deployed, create role/rolebindings in the csm namespaces

Check failure on line 883 in controllers/csm_controller.go

View workflow job for this annotation

GitHub Actions / golangci-lint

File is not `gofumpt`-ed (gofumpt)
list := &csmv1.ApexConnectivityClientList{}
if err := ctrlClient.List(ctx, list); err != nil {
log.Info("dell connectivity client not found")
return nil
} else if len(list.Items) <= 0 {
log.Info("dell connectivity client not found")
return nil
} else {
log.Info("dell connectivity client found")
cr := new(csmv1.ApexConnectivityClient)
BrownfieldCR := "brownfield-onboard.yaml"
configVersion1 := list.Items[0].Spec.Client.ConfigVersion
brownfieldManifestFilePath := fmt.Sprintf("%s/clientconfig/%s/%s/%s", operatorConfig.ConfigDirectory, csmv1.DreadnoughtClient, configVersion1, BrownfieldCR)

if err = utils.BrownfieldOnboard(ctx, brownfieldManifestFilePath, *cr, ctrlClient); err != nil {
log.Error(err, "error creating role/rolebindings to newly discovered csm namespace")
return err
}
if err = utils.CheckAccAndCreateRbac(ctx, operatorConfig, ctrlClient); err != nil {
return err
}

// list := &csmv1.ApexConnectivityClientList{}
// if err := ctrlClient.List(ctx, list); err != nil {
// log.Info("dell connectivity client not found")
// return nil
// } else if len(list.Items) <= 0 {
// log.Info("dell connectivity client not found")
// return nil
// } else {
// log.Info("dell connectivity client found")
// cr := new(csmv1.ApexConnectivityClient)
// BrownfieldCR := "brownfield-onboard.yaml"
// configVersion1 := list.Items[0].Spec.Client.ConfigVersion
// brownfieldManifestFilePath := fmt.Sprintf("%s/clientconfig/%s/%s/%s", operatorConfig.ConfigDirectory, csmv1.DreadnoughtClient, configVersion1, BrownfieldCR)

// if err = utils.BrownfieldOnboard(ctx, brownfieldManifestFilePath, *cr, ctrlClient); err != nil {
// log.Error(err, "error creating role/rolebindings to newly discovered csm namespace")
// return err
// }
// }
return nil
}

Expand Down
25 changes: 25 additions & 0 deletions pkg/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ const (
// BrownfieldNamespace
ExistingNamespace = "<ExistingNameSpace>"
ClientNamespace = "<ClientNameSpace>"
// BrownfieldManifest - manifest for brownfield role/rolebinding creation
BrownfieldManifest string = "brownfield-onboard.yaml"
)

// SplitYaml divides a big bytes of yaml files in individual yaml files.
Expand Down Expand Up @@ -1288,3 +1290,26 @@ func CreateObjects(ctx context.Context, yamlFile string, ctrlClient crclient.Cli
}
return nil
}

func CheckAccAndCreateRbac(ctx context.Context, operatorConfig OperatorConfig, ctrlClient crclient.Client) error {
log := logger.GetLogger(ctx)
list := &csmv1.ApexConnectivityClientList{}
if err := ctrlClient.List(ctx, list); err != nil {
log.Info("dell connectivity client not found")
return nil
} else if len(list.Items) <= 0 {
log.Info("dell connectivity client not found")
return nil
} else {

Check warning on line 1303 in pkg/utils/utils.go

View workflow job for this annotation

GitHub Actions / golangci-lint

indent-error-flow: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary) (revive)
log.Info("dell connectivity client found")
cr := new(csmv1.ApexConnectivityClient)
configVersion1 := list.Items[0].Spec.Client.ConfigVersion
brownfieldManifestFilePath := fmt.Sprintf("%s/clientconfig/%s/%s/%s", operatorConfig.ConfigDirectory, csmv1.DreadnoughtClient, configVersion1, BrownfieldManifest)

if err = BrownfieldOnboard(ctx, brownfieldManifestFilePath, *cr, ctrlClient); err != nil {
log.Error(err, "error creating role/rolebindings")
return err
}
}
return nil
}

0 comments on commit a9262f7

Please sign in to comment.