diff --git a/api/v1/curvecluster_types.go b/api/v1/curvecluster_types.go index ceec3af6..cfd86676 100644 --- a/api/v1/curvecluster_types.go +++ b/api/v1/curvecluster_types.go @@ -23,46 +23,41 @@ import ( const CustomResourceGroup = "curve.opencurve.io" -// ConditionType represent a resource's status +// ConditionType represents a resource's status type ConditionType string const ( - // ClusterPhasePending: The cluster is running to create. - // ClusterPhaseReady: The cluster has been created successfully. - // ClusterPhaseDeleting: The cluster is running to delete. - // ClusterPhaseError: The cluster created failed becasue some reason. - // ClusterPhaseUnknown: Unknow phase - // ClusterPending + // ClusterPhasePending indicates the cluster is running to create. ClusterPhasePending ConditionType = "Pending" - // ClusterReady + // ClusterPhaseReady indicates the cluster has been created successfully. ClusterPhaseReady ConditionType = "Ready" - // ClusterPhaseDeleting + // ClusterPhaseDeleting indicates the cluster is running to delete. ClusterPhaseDeleting ConditionType = "Deleting" - // ClusterPhaseError + // ClusterPhaseError indicates the cluster created failed because of some reason. ClusterPhaseError ConditionType = "Failed" - // ClusterPhaseUnknown + // ClusterPhaseUnknown is unknown phase ClusterPhaseUnknown ConditionType = "Unknown" ) const ( - // ConditionTypeEtcdReady + // ConditionTypeEtcdReady indicates the etcd is ready ConditionTypeEtcdReady ConditionType = "EtcdReady" - // ConditionTypeMdsReady + // ConditionTypeMdsReady indicates the mds is ready ConditionTypeMdsReady ConditionType = "MdsReady" - // ConditionTypeFormatedReady + // ConditionTypeFormatedReady indicates the formated job is ready ConditionTypeFormatedReady ConditionType = "formatedReady" - // ConditionTypeChunkServerReady + // ConditionTypeChunkServerReady indicates the chunk server is ready ConditionTypeChunkServerReady ConditionType = "ChunkServerReady" - // ConditionTypeSnapShotCloneReady + // ConditionTypeSnapShotCloneReady indicates the snapshot clone is ready ConditionTypeSnapShotCloneReady ConditionType = "SnapShotCloneReady" - // ConditionTypeDeleting + // ConditionTypeDeleting indicates it's deleting ConditionTypeDeleting ConditionType = "Deleting" - // ConditionTypeClusterReady + // ConditionTypeClusterReady indicates the cluster is ready ConditionTypeClusterReady ConditionType = "Ready" - // ConditionTypeFailure + // ConditionTypeFailure indicates it's failed ConditionTypeFailure ConditionType = "Failed" - // ConditionTypeUnknown - ConditionTypeUnknown ConditionType = "Unknow" + // ConditionTypeUnknown is unknown condition + ConditionTypeUnknown ConditionType = "Unknown" ) type ConditionStatus string @@ -146,7 +141,7 @@ type CurveClusterSpec struct { // CurveClusterStatus defines the observed state of CurveCluster type CurveClusterStatus struct { // Phase is a summary of cluster state. - // It can be translate from the last conditiontype + // It can be translated from the last conditiontype Phase ConditionType `json:"phase,omitempty"` // Condition contains current service state of cluster such as progressing/Ready/Failure... @@ -194,7 +189,7 @@ type CurveVersionSpec struct { ImagePullPolicy v1.PullPolicy `json:"imagePullPolicy,omitempty"` } -// EtcdSpec +// EtcdSpec is the spec of etcd type EtcdSpec struct { // +optional PeerPort int `json:"peerPort,omitempty"` @@ -206,7 +201,7 @@ type EtcdSpec struct { Config map[string]string `json:"config,omitempty"` } -// MdsSpec +// MdsSpec is the spec of mds type MdsSpec struct { // +optional Port int `json:"port,omitempty"` @@ -218,7 +213,7 @@ type MdsSpec struct { Config map[string]string `json:"config,omitempty"` } -// SnapShotCloneSpec +// SnapShotCloneSpec is the spec of snapshot clone type SnapShotCloneSpec struct { // +optional Enable bool `json:"enable,omitempty"` @@ -236,7 +231,7 @@ type SnapShotCloneSpec struct { S3Config S3ConfigSpec `json:"s3Config,omitempty"` } -// S3Config +// S3ConfigSpec is the spec of s3 config type S3ConfigSpec struct { AK string `json:"ak,omitempty"` SK string `json:"sk,omitempty"` @@ -244,7 +239,7 @@ type S3ConfigSpec struct { SnapShotBucketName string `json:"bucketName,omitempty"` } -// StorageScopeSpec +// StorageScopeSpec is the spec of storage scope type StorageScopeSpec struct { // +optional UseSelectedNodes bool `json:"useSelectedNodes,omitempty"` @@ -265,7 +260,7 @@ type StorageScopeSpec struct { SelectedNodes []SelectedNodesSpec `json:"selectedNodes,omitempty"` } -// Device represents a disk to use in the cluster +// DevicesSpec represents a disk to use in the cluster type DevicesSpec struct { // +optional Name string `json:"name,omitempty"` diff --git a/main.go b/main.go index df2b1717..5e5dc8af 100644 --- a/main.go +++ b/main.go @@ -20,6 +20,7 @@ import ( "flag" "os" + "github.com/spf13/pflag" "k8s.io/apimachinery/pkg/runtime" "k8s.io/client-go/kubernetes" clientgoscheme "k8s.io/client-go/kubernetes/scheme" @@ -30,7 +31,6 @@ import ( operatorv1 "github.com/opencurve/curve-operator/api/v1" "github.com/opencurve/curve-operator/pkg/clusterd" "github.com/opencurve/curve-operator/pkg/controllers" - "github.com/spf13/pflag" // +kubebuilder:scaffold:imports ) diff --git a/pkg/chunkserver/chunkfilepool.go b/pkg/chunkserver/chunkfilepool.go index 91269e4c..77463c64 100644 --- a/pkg/chunkserver/chunkfilepool.go +++ b/pkg/chunkserver/chunkfilepool.go @@ -17,8 +17,8 @@ import ( ) const ( - PrepareJobName = "prepare-chunkfile" - DEFAULT_CHUNKFILE_SIZE = 16 * 1024 * 1024 // 16MB + PrepareJobName = "prepare-chunkfile" + DefaultChunkfileSize = 16 * 1024 * 1024 // 16MB formatConfigMapName = "format-chunkfile-conf" formatScriptFileDataKey = "format.sh" @@ -267,7 +267,7 @@ func (c *Cluster) makeFormatContainer(device curvev1.DevicesSpec, volumeMounts [ readOnlyRootFilesystem := false argsPercent := strconv.Itoa(device.Percentage) - argsFileSize := strconv.Itoa(DEFAULT_CHUNKFILE_SIZE) + argsFileSize := strconv.Itoa(DefaultChunkfileSize) argsFilePoolDir := ChunkserverContainerDataDir + "/chunkfilepool" argsFilePoolMetaPath := ChunkserverContainerDataDir + "/chunkfilepool.meta" diff --git a/pkg/chunkserver/config.go b/pkg/chunkserver/config.go index da4b895a..ce5a17d0 100644 --- a/pkg/chunkserver/config.go +++ b/pkg/chunkserver/config.go @@ -3,6 +3,7 @@ package chunkserver import "strconv" // chunkserverConfig for a single chunkserver +// chunkserverConfig implements config.ConfigInterface type chunkserverConfig struct { Prefix string Port int // chunkserver.conf(service_port) @@ -55,7 +56,6 @@ type chunkserverDataPathMap struct { ContainerLogDir string } -// chunkserverConfig implement ConfigInterface func (c *chunkserverConfig) GetPrefix() string { return c.Prefix } @@ -121,6 +121,7 @@ func (c *chunkserverConfig) GetDataDir() string { } // cluster + func (c *chunkserverConfig) GetClusterEtcdHttpAddr() string { return "" } diff --git a/pkg/chunkserver/pool.go b/pkg/chunkserver/pool.go index 52d74691..4dc22df6 100644 --- a/pkg/chunkserver/pool.go +++ b/pkg/chunkserver/pool.go @@ -168,7 +168,7 @@ func (c *Cluster) createLogicalPool(logicalPool string) (LogicalPool, []Server) } // copysets - copysets = (int)(copysets / DEFAULT_REPLICAS_PER_COPYSET) + copysets = copysets / DEFAULT_REPLICAS_PER_COPYSET if copysets == 0 { copysets = 1 } diff --git a/pkg/chunkserver/spec.go b/pkg/chunkserver/spec.go index 923c127f..a6c38c50 100644 --- a/pkg/chunkserver/spec.go +++ b/pkg/chunkserver/spec.go @@ -116,7 +116,7 @@ func (c *Cluster) createCSClientConfigMap() error { return nil } -// createS3ConfigMap create s3 configmap +// CreateS3ConfigMap creates s3 configmap func (c *Cluster) CreateS3ConfigMap() error { s3CMTemplate, err := c.context.Clientset.CoreV1().ConfigMaps(c.namespacedName.Namespace).Get(config.S3ConfigMapTemp, metav1.GetOptions{}) if err != nil { @@ -358,7 +358,7 @@ func (c *Cluster) makeCSDaemonContainer(csConfig *chunkserverConfig) v1.Containe return container } -// getChunkServerPodLabels +// getChunkServerPodLabels returns pod labels for chunk server func (c *Cluster) getChunkServerPodLabels(csConfig *chunkserverConfig) map[string]string { labels := make(map[string]string) labels["app"] = AppName diff --git a/pkg/chunkserver/volume.go b/pkg/chunkserver/volume.go index f7211c29..e8d38724 100644 --- a/pkg/chunkserver/volume.go +++ b/pkg/chunkserver/volume.go @@ -86,7 +86,7 @@ func CSDaemonVolumes(csConfig *chunkserverConfig) []v1.Volume { return vols } -// DaemonVolumeMounts returns the pod container volume mounth used only by chunkserver +// CSDaemonVolumeMounts returns the pod container volume mounth used only by chunkserver func CSDaemonVolumeMounts(csConfig *chunkserverConfig) []v1.VolumeMount { mounts := []v1.VolumeMount{} @@ -101,7 +101,7 @@ func CSDaemonVolumeMounts(csConfig *chunkserverConfig) []v1.VolumeMount { return mounts } -// configConfigMapVolumeAndMount Create configmap volume and volume mount for daemon chunkserver pod +// CSConfigConfigMapVolumeAndMount creates configmap volume and volume mount for daemon chunkserver pod func CSConfigConfigMapVolumeAndMount(csConfig *chunkserverConfig) ([]v1.Volume, []v1.VolumeMount) { vols := []v1.Volume{} mounts := []v1.VolumeMount{} @@ -185,14 +185,25 @@ func CSConfigConfigMapVolumeAndMount(csConfig *chunkserverConfig) ([]v1.Volume, return vols, mounts } -// createTopoAndToolVolumeAndMount +// createTopoAndToolVolumeAndMount creates volumes and volumeMounts for topo and tool func (c *Cluster) createTopoAndToolVolumeAndMount() ([]v1.Volume, []v1.VolumeMount) { vols := []v1.Volume{} mounts := []v1.VolumeMount{} // 1. Create topology configmap volume and volume mount("/curvebs/tools/conf/topology.json") mode := int32(0644) - topoConfigMapVolSource := &v1.ConfigMapVolumeSource{LocalObjectReference: v1.LocalObjectReference{Name: config.TopoJsonConfigMapName}, Items: []v1.KeyToPath{{Key: config.TopoJsonConfigmapDataKey, Path: config.TopoJsonConfigmapDataKey, Mode: &mode}}} + topoConfigMapVolSource := &v1.ConfigMapVolumeSource{ + LocalObjectReference: v1.LocalObjectReference{ + Name: config.TopoJsonConfigMapName, + }, + Items: []v1.KeyToPath{ + { + Key: config.TopoJsonConfigmapDataKey, + Path: config.TopoJsonConfigmapDataKey, + Mode: &mode, + }, + }, + } topoConfigVol := v1.Volume{ Name: config.TopoJsonConfigMapName, VolumeSource: v1.VolumeSource{ @@ -209,7 +220,18 @@ func (c *Cluster) createTopoAndToolVolumeAndMount() ([]v1.Volume, []v1.VolumeMou mounts = append(mounts, topoMount) // 2. Create tools configmap volume and volume mount("/etc/curve/tools.conf") - toolConfigMapVolSource := &v1.ConfigMapVolumeSource{LocalObjectReference: v1.LocalObjectReference{Name: config.ToolsConfigMapName}, Items: []v1.KeyToPath{{Key: config.ToolsConfigMapDataKey, Path: config.ToolsConfigMapDataKey, Mode: &mode}}} + toolConfigMapVolSource := &v1.ConfigMapVolumeSource{ + LocalObjectReference: v1.LocalObjectReference{ + Name: config.ToolsConfigMapName, + }, + Items: []v1.KeyToPath{ + { + Key: config.ToolsConfigMapDataKey, + Path: config.ToolsConfigMapDataKey, + Mode: &mode, + }, + }, + } toolConfigVol := v1.Volume{ Name: config.ToolsConfigMapName, VolumeSource: v1.VolumeSource{ diff --git a/pkg/config/variables.go b/pkg/config/variables.go index f047c395..ab3fcfff 100644 --- a/pkg/config/variables.go +++ b/pkg/config/variables.go @@ -193,9 +193,8 @@ func getValue(name string, dc ConfigInterface) string { return "" } -// ReplaceConfigVars +// ReplaceConfigVars replaces vars in config string func ReplaceConfigVars(confStr string, c ConfigInterface) (string, error) { - r, err := regexp.Compile(REGEX_VARIABLE) if err != nil { return "", err diff --git a/pkg/controllers/cleanup.go b/pkg/controllers/cleanup.go index f93cc664..24f50621 100644 --- a/pkg/controllers/cleanup.go +++ b/pkg/controllers/cleanup.go @@ -22,7 +22,7 @@ import ( const ( CleanupAppName = "curve-cleanup" - clusterCleanUpPolicyRetryInterval = 5 //seconds + clusterCleanUpPolicyRetryInterval = 5 * time.Second dataVolumeName = "data-cleanup-volume" dataDirHostPathEnv = "CURVE_DATA_DIR_HOST_PATH" @@ -37,7 +37,7 @@ func (c *ClusterController) startClusterCleanUp(ctx clusterd.Context, cluster *c logger.Infof("starting clean up for cluster %q", cluster.Name) - err := c.waitForCurveDaemonCleanUp(context.TODO(), cluster, time.Duration(clusterCleanUpPolicyRetryInterval)*time.Second) + err := c.waitForCurveDaemonCleanUp(context.TODO(), cluster, clusterCleanUpPolicyRetryInterval) if err != nil { logger.Errorf("failed to wait till curve daemons are destroyed. %v", err) return diff --git a/pkg/controllers/cluster.go b/pkg/controllers/cluster.go index be718df0..5cac8e63 100644 --- a/pkg/controllers/cluster.go +++ b/pkg/controllers/cluster.go @@ -70,7 +70,7 @@ func (c *cluster) reconcileCurveDaemons() error { ticker := time.NewTicker(10 * time.Second) defer ticker.Stop() chn := make(chan bool, 1) - ctx, canf := context.WithTimeout(context.Background(), time.Duration(10*60*time.Second)) + ctx, canf := context.WithTimeout(context.Background(), 10*60*time.Second) defer canf() k8sutil.CheckJobStatus(ctx, c.context.Clientset, ticker, chn, c.NameSpace, job.Name) flag := <-chn @@ -83,7 +83,7 @@ func (c *cluster) reconcileCurveDaemons() error { if err != nil { return errors.Wrap(err, "failed to create all config file template configmap") } - logger.Info("create config template configmap successed") + logger.Info("create config template configmap successfully") // 2. Start etcd cluster etcds := etcd.New(c.context, c.NamespacedName, *c.Spec, c.ownerInfo, c.dataDirHostPath, c.logDirHostPath, c.confDirHostPath) diff --git a/pkg/controllers/curvecluster_controller.go b/pkg/controllers/curvecluster_controller.go index 89ab08d0..940156e8 100644 --- a/pkg/controllers/curvecluster_controller.go +++ b/pkg/controllers/curvecluster_controller.go @@ -141,7 +141,6 @@ func (r *CurveClusterReconciler) reconcileDelete(curveCluster *curvev1.CurveClus if _, ok := r.ClusterController.clusterMap[curveCluster.Namespace]; ok { delete(r.ClusterController.clusterMap, curveCluster.Namespace) } - // Remove finalizers err := r.removeFinalizer(r.Client, r.ClusterController.namespacedName, curveCluster, "") if err != nil { diff --git a/pkg/daemon/volume.go b/pkg/daemon/volume.go index 34535ba5..0f4a058f 100644 --- a/pkg/daemon/volume.go +++ b/pkg/daemon/volume.go @@ -26,7 +26,7 @@ func DaemonVolumes(configMapDataKey string, configMapMountPathDir string, dataPa return vols } -// DaemonVolumeMounts returns the pod container volume mounth used by Curve daemon +// DaemonVolumeMounts returns the pod container volumeMounts used by Curve daemon func DaemonVolumeMounts(configMapDataKey string, configMapMountPathDir string, dataPaths *config.DataPathMap, curConfigMapName string) []v1.VolumeMount { // create configmap mount path mounts := []v1.VolumeMount{} diff --git a/pkg/k8sutil/condition.go b/pkg/k8sutil/condition.go index 55cde867..c8e40488 100644 --- a/pkg/k8sutil/condition.go +++ b/pkg/k8sutil/condition.go @@ -114,6 +114,7 @@ func UpdateStatus(client client.Client, namespaceName types.NamespacedName, obj if kerrors.IsNotFound(err) { err = client.Update(context.Background(), obj) } + if err != nil { return errors.Wrapf(err, "failed to update object %q status", nsName.String()) } diff --git a/pkg/k8sutil/job.go b/pkg/k8sutil/job.go index 57adbe57..8fabc1f5 100644 --- a/pkg/k8sutil/job.go +++ b/pkg/k8sutil/job.go @@ -77,7 +77,7 @@ func DeleteBatchJob(ctx context.Context, clientset kubernetes.Interface, namespa return nil } -// checkJobStatus go routine to check job status +// CheckJobStatus go routine to check job status func CheckJobStatus(ctx context.Context, clientSet kubernetes.Interface, ticker *time.Ticker, chn chan bool, namespace string, jobName string) { for { select { @@ -95,10 +95,8 @@ func CheckJobStatus(ctx context.Context, clientSet kubernetes.Interface, ticker logger.Infof("job %s has successd", job.Name) chn <- true return - } else { - logger.Infof("job %s is running", job.Name) } - + logger.Infof("job %s is running", job.Name) case <-ctx.Done(): chn <- false logger.Error("go routinue exit because check time is more than 5 mins") diff --git a/pkg/k8sutil/readconf.go b/pkg/k8sutil/readconf.go index 85cfdde3..64b07e3c 100644 --- a/pkg/k8sutil/readconf.go +++ b/pkg/k8sutil/readconf.go @@ -8,7 +8,7 @@ import ( "github.com/pkg/errors" ) -// ReadConfFromTemplate read config file of each daemon to map. +// ReadConf reads config file of each daemon to map. func ReadConf(path string) (map[string]string, error) { file, err := os.Open(path) if err != nil {