From 86c878c97a87fa27af520dd9fbc84f9bbdad7b35 Mon Sep 17 00:00:00 2001 From: jai kumar <8251914+nb950@users.noreply.github.com> Date: Wed, 12 Jan 2022 10:10:47 -0500 Subject: [PATCH 1/2] update k8s supported version (#4) * update k8s supported version * fix lint errors --- api/v1/csipowermaxrevproxy_types.go | 1 + api/v1/csm_types.go | 3 ++- api/v1/types.go | 34 ++++++++++++++++++++--------- api/v1/zz_generated.deepcopy.go | 1 + controllers/csm_controller.go | 2 ++ main.go | 2 +- pkg/drivers/powerscale.go | 5 +++++ pkg/modules/authorization.go | 4 ++++ pkg/utils/status.go | 6 +++++ pkg/utils/utils.go | 8 +++++-- 10 files changed, 52 insertions(+), 14 deletions(-) diff --git a/api/v1/csipowermaxrevproxy_types.go b/api/v1/csipowermaxrevproxy_types.go index eaa93331e..3a9f057df 100644 --- a/api/v1/csipowermaxrevproxy_types.go +++ b/api/v1/csipowermaxrevproxy_types.go @@ -15,6 +15,7 @@ import ( corev1 "k8s.io/api/core/v1" ) +// ProxyLimits max limits // EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN! // NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized. // ProxyLimits is used for storing the various types of limits diff --git a/api/v1/csm_types.go b/api/v1/csm_types.go index d91c217dc..599a10f10 100644 --- a/api/v1/csm_types.go +++ b/api/v1/csm_types.go @@ -85,11 +85,12 @@ func (cr *ContainerStorageModule) GetCSMStatus() *ContainerStorageModuleStatus { return &cr.Status } +// GetControllerName - Returns a controller func (cr *ContainerStorageModule) GetControllerName() string { return fmt.Sprintf("%s-controller", cr.Name) } -// GetDaemonSetName - Returns the name of the daemonset for the driver +// GetNodeName - Returns the name of the daemonset for the driver func (cr *ContainerStorageModule) GetNodeName() string { return fmt.Sprintf("%s-node", cr.Name) } diff --git a/api/v1/types.go b/api/v1/types.go index 2bd10c0a0..217f94f1d 100644 --- a/api/v1/types.go +++ b/api/v1/types.go @@ -65,19 +65,31 @@ const ( // PowerStore - placeholder for constant powerstore PowerStore DriverType = "powerstore" + // Provisioner - placeholder for constant Provisioner = "provisioner" - Attacher = "attacher" + // Attacher - placeholder for constant + Attacher = "attacher" + // Snapshotter - placeholder for constant Snapshotter = "snapshotter" - Registrar = "registrar" - Resizer = "resizer" - Sdcmonitor = "sdc-monitor" - - Succeeded CSMOperatorConditionType = "Succeeded" + // Registrar - placeholder for constant + Registrar = "registrar" + // Resizer - placeholder for constant + Resizer = "resizer" + // Sdcmonitor - placeholder for constant + Sdcmonitor = "sdc-monitor" + + // Succeeded - constant + Succeeded CSMOperatorConditionType = "Succeeded" + // InvalidConfig - constant InvalidConfig CSMOperatorConditionType = "InvalidConfig" - Running CSMOperatorConditionType = "Running" - Error CSMOperatorConditionType = "Error" - Updating CSMOperatorConditionType = "Updating" - Failed CSMOperatorConditionType = "Failed" + // Running - Constant + Running CSMOperatorConditionType = "Running" + // Error - Constant + Error CSMOperatorConditionType = "Error" + // Updating - Constant + Updating CSMOperatorConditionType = "Updating" + // Failed - Constant + Failed CSMOperatorConditionType = "Failed" ) // Module defines the desired state of a ContainerStorageModuleModules @@ -181,6 +193,7 @@ type Driver struct { TLSCertSecret string `json:"tlsCertSecret,omitempty" yaml:"tlsCertSecret"` } +//ContainerTemplate template type ContainerTemplate struct { // Name is the name of Container @@ -217,6 +230,7 @@ type ContainerTemplate struct { NodeSelector map[string]string `json:"nodeSelector,omitempty" yaml:"nodeSelector"` } +//SnapshotClass struct type SnapshotClass struct { // Name is the name of the Snapshot Class // +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Snapshot Class Name" diff --git a/api/v1/zz_generated.deepcopy.go b/api/v1/zz_generated.deepcopy.go index 0889602d3..01203e9e5 100644 --- a/api/v1/zz_generated.deepcopy.go +++ b/api/v1/zz_generated.deepcopy.go @@ -1,3 +1,4 @@ +//go:build !ignore_autogenerated // +build !ignore_autogenerated /* diff --git a/controllers/csm_controller.go b/controllers/csm_controller.go index e73c08186..232b1d9ae 100644 --- a/controllers/csm_controller.go +++ b/controllers/csm_controller.go @@ -96,6 +96,7 @@ var configVersionKey = fmt.Sprintf("%s/%s", MetadataPrefix, "CSIDriverConfigVers // For more details, check Reconcile and its Result here: // - 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) { log := r.Log.WithValues("csm", req.NamespacedName) // your logic here @@ -496,6 +497,7 @@ func (r *ContainerStorageModuleReconciler) SyncCSM(ctx context.Context, cr csmv1 return nil } +// PreChecks - validate inputs func (r *ContainerStorageModuleReconciler) PreChecks(ctx context.Context, cr *csmv1.ContainerStorageModule, operatorConfig utils.OperatorConfig, reqLogger logr.Logger) error { if cr.Spec.Driver.Common.Image == "" { diff --git a/main.go b/main.go index 93a8ff2e4..27c14e39e 100644 --- a/main.go +++ b/main.go @@ -46,7 +46,7 @@ const ( // K8sMinimumSupportedVersion is the minimum supported version for k8s K8sMinimumSupportedVersion = "1.19" // K8sMaximumSupportedVersion is the maximum supported version for k8s - K8sMaximumSupportedVersion = "1.22" + K8sMaximumSupportedVersion = "1.23" // OpenshiftMinimumSupportedVersion is the minimum supported version for openshift OpenshiftMinimumSupportedVersion = "4.6" // OpenshiftMaximumSupportedVersion is the maximum supported version for openshift diff --git a/pkg/drivers/powerscale.go b/pkg/drivers/powerscale.go index 60aebf439..04cc6fcb8 100644 --- a/pkg/drivers/powerscale.go +++ b/pkg/drivers/powerscale.go @@ -17,6 +17,7 @@ import ( // +kubebuilder:scaffold:imports ) +// GetPowerScaleController driver func GetPowerScaleController(cr csmv1.ContainerStorageModule, operatorConfig utils.OperatorConfig) (*utils.ControllerYAML, error) { configMapPath := fmt.Sprintf("%s/driverconfig/powerscale/%s/controller.yaml", operatorConfig.ConfigDirectory, cr.Spec.Driver.ConfigVersion) buf, err := ioutil.ReadFile(configMapPath) @@ -76,6 +77,7 @@ func GetPowerScaleController(cr csmv1.ContainerStorageModule, operatorConfig uti } +// GetPowerScaleNode node func GetPowerScaleNode(cr csmv1.ContainerStorageModule, operatorConfig utils.OperatorConfig) (*utils.NodeYAML, error) { configMapPath := fmt.Sprintf("%s/driverconfig/powerscale/%s/node.yaml", operatorConfig.ConfigDirectory, cr.Spec.Driver.ConfigVersion) buf, err := ioutil.ReadFile(configMapPath) @@ -139,6 +141,7 @@ func GetPowerScaleNode(cr csmv1.ContainerStorageModule, operatorConfig utils.Ope } +// GetPowerScaleConfigMap configmap func GetPowerScaleConfigMap(cr csmv1.ContainerStorageModule, operatorConfig utils.OperatorConfig) (*corev1.ConfigMap, error) { configMapPath := fmt.Sprintf("%s/driverconfig/powerscale/%s/driver-config-params.yaml", operatorConfig.ConfigDirectory, cr.Spec.Driver.ConfigVersion) buf, err := ioutil.ReadFile(configMapPath) @@ -167,6 +170,7 @@ func GetPowerScaleConfigMap(cr csmv1.ContainerStorageModule, operatorConfig util } +// GetPowerScaleCSIDriver driver func GetPowerScaleCSIDriver(cr csmv1.ContainerStorageModule, operatorConfig utils.OperatorConfig) (*storagev1.CSIDriver, error) { configMapPath := fmt.Sprintf("%s/driverconfig/powerscale/%s/csidriver.yaml", operatorConfig.ConfigDirectory, cr.Spec.Driver.ConfigVersion) buf, err := ioutil.ReadFile(configMapPath) @@ -184,6 +188,7 @@ func GetPowerScaleCSIDriver(cr csmv1.ContainerStorageModule, operatorConfig util } +// PrecheckPowerScale validate func PrecheckPowerScale(ctx context.Context, cr *csmv1.ContainerStorageModule, r utils.ReconcileCSM, log logr.Logger) error { // Check for secrete only config := cr.Name + "-creds" diff --git a/pkg/modules/authorization.go b/pkg/modules/authorization.go index 0f84f3375..b04f6bc4c 100644 --- a/pkg/modules/authorization.go +++ b/pkg/modules/authorization.go @@ -18,6 +18,7 @@ import ( ) const ( + // DefaultPluginIdentifier constant DefaultPluginIdentifier = "" ) @@ -132,6 +133,7 @@ func getAuthVolumes(cr csmv1.ContainerStorageModule, op utils.OperatorConfig, au return vols, nil } +// AuthInjectDaemonset auth module func AuthInjectDaemonset(ds appsv1.DaemonSet, cr csmv1.ContainerStorageModule, op utils.OperatorConfig) (*appsv1.DaemonSet, error) { authModule, containerPtr, err := getAuthCR(cr, op) if err != nil { @@ -159,6 +161,7 @@ func AuthInjectDaemonset(ds appsv1.DaemonSet, cr csmv1.ContainerStorageModule, o return &ds, nil } +// AuthInjectDeployment deploy func AuthInjectDeployment(dp appsv1.Deployment, cr csmv1.ContainerStorageModule, op utils.OperatorConfig) (*appsv1.Deployment, error) { authModule, containerPtr, err := getAuthCR(cr, op) if err != nil { @@ -187,6 +190,7 @@ func AuthInjectDeployment(dp appsv1.Deployment, cr csmv1.ContainerStorageModule, } +// AuthorizationPrecheck precheck func AuthorizationPrecheck(ctx context.Context, cr *csmv1.ContainerStorageModule, auth csmv1.Module, r utils.ReconcileCSM, log logr.Logger) error { if _, ok := SupportedDrivers[string(cr.Spec.Driver.CSIDriverType)]; !ok { return fmt.Errorf("csm authorization does not support %s driver", string(cr.Spec.Driver.CSIDriverType)) diff --git a/pkg/utils/status.go b/pkg/utils/status.go index a1fcaf8cc..f549bc881 100644 --- a/pkg/utils/status.go +++ b/pkg/utils/status.go @@ -116,6 +116,7 @@ func getDaemonSetStatus(ctx context.Context, instance *csmv1.ContainerStorageMod }, nil } +// CalculateState for cr func CalculateState(ctx context.Context, instance *csmv1.ContainerStorageModule, r ReconcileCSM, newStatus *csmv1.ContainerStorageModuleStatus) (bool, error) { running := false controllerReplicas, controllerStatus, controllerErr := getDeploymentStatus(ctx, instance, r) @@ -143,6 +144,7 @@ func CalculateState(ctx context.Context, instance *csmv1.ContainerStorageModule, return running, err } +// SetStatus of cr func SetStatus(instance *csmv1.ContainerStorageModule, newStatus *csmv1.ContainerStorageModuleStatus) { instance.GetCSMStatus().State = newStatus.State instance.GetCSMStatus().LastUpdate.ErrorMessage = newStatus.LastUpdate.ErrorMessage @@ -153,6 +155,7 @@ func SetStatus(instance *csmv1.ContainerStorageModule, newStatus *csmv1.Containe instance.GetCSMStatus().ContainerStorageModuleHash = newStatus.ContainerStorageModuleHash } +// SetLastStatusUpdate for cr func SetLastStatusUpdate(status *csmv1.ContainerStorageModuleStatus, conditionType csmv1.CSMOperatorConditionType, errorMsg string) csmv1.LastUpdate { // If the condition has not changed, then don't update the time if status.LastUpdate.Condition == conditionType && status.LastUpdate.ErrorMessage == errorMsg { @@ -169,6 +172,7 @@ func SetLastStatusUpdate(status *csmv1.ContainerStorageModuleStatus, conditionTy } } +// UpdateStatus for cr func UpdateStatus(ctx context.Context, instance *csmv1.ContainerStorageModule, r ReconcileCSM, reqLogger logr.Logger, newStatus, oldStatus *csmv1.ContainerStorageModuleStatus) error { //running := calculateState(ctx, instance, r, newStatus) if !reflect.DeepEqual(oldStatus, newStatus) { @@ -191,6 +195,7 @@ func UpdateStatus(ctx context.Context, instance *csmv1.ContainerStorageModule, r return nil } +// HandleValidationError for cr func HandleValidationError(ctx context.Context, instance *csmv1.ContainerStorageModule, r ReconcileCSM, reqLogger logr.Logger, validationError error) (reconcile.Result, error) { reqLogger.Error(validationError, "Validation error") @@ -225,6 +230,7 @@ func GetOperatorConditionTypeFromState(state csmv1.CSMStateType) csmv1.CSMOperat return csmv1.Error } +// HandleSuccess for cr func HandleSuccess(ctx context.Context, instance *csmv1.ContainerStorageModule, r ReconcileCSM, reqLogger logr.Logger, newStatus, oldStatus *csmv1.ContainerStorageModuleStatus) (reconcile.Result, error) { errorMsg := "" running, err := CalculateState(ctx, instance, r, newStatus) diff --git a/pkg/utils/utils.go b/pkg/utils/utils.go index 6996461d3..c1afcdd70 100644 --- a/pkg/utils/utils.go +++ b/pkg/utils/utils.go @@ -61,9 +61,12 @@ type NodeYAML struct { } const ( - DefaultReleaseName = "" + // DefaultReleaseName const + DefaultReleaseName = "" + // DefaultReleaseNamespace const DefaultReleaseNamespace = "" - DefaultImagePullPolicy = "IfNotPresent" + // DefaultImagePullPolicy const + DefaultImagePullPolicy = "IfNotPresent" ) // SplitYAML divides a big bytes of yaml files in individual yaml files. @@ -263,6 +266,7 @@ func HashContainerStorageModule(instance *csmv1.ContainerStorageModule) uint64 { return uint64(hash.Sum32()) } +// CSMHashChanged for cr func CSMHashChanged(instance *csmv1.ContainerStorageModule) (uint64, uint64, bool) { expectedHash := HashContainerStorageModule(instance) return expectedHash, instance.GetCSMStatus().ContainerStorageModuleHash, instance.GetCSMStatus().ContainerStorageModuleHash != expectedHash From 176f2b99223d791cba5acb2a9cf29314879c46db Mon Sep 17 00:00:00 2001 From: karthikk92 <92289639+karthikk92@users.noreply.github.com> Date: Tue, 18 Jan 2022 17:47:30 +0530 Subject: [PATCH 2/2] GO version update to 1.17 (#6) --- Dockerfile | 2 +- go.mod | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index f82d2bc87..81f71d2d6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,5 @@ # Build the manager binary -FROM golang:1.16 as builder +FROM golang:1.17 as builder WORKDIR /workspace # Copy the Go Modules manifests diff --git a/go.mod b/go.mod index 5a7d83996..b69f43f3a 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/dell/csm-operator -go 1.16 +go 1.17 require ( github.com/go-logr/logr v0.3.0