Skip to content

Commit

Permalink
chore: update comments and remove unnecessary conversions and checks
Browse files Browse the repository at this point in the history
  • Loading branch information
hezhizhen committed Apr 8, 2023
1 parent 383d5f7 commit 451ff32
Show file tree
Hide file tree
Showing 16 changed files with 47 additions and 59 deletions.
51 changes: 23 additions & 28 deletions api/v1/curvecluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 : The cluster is running to create.
ClusterPhasePending ConditionType = "Pending"
// ClusterReady
// ClusterPhaseReady : The cluster has been created successfully.
ClusterPhaseReady ConditionType = "Ready"
// ClusterPhaseDeleting
// ClusterPhaseDeleting : The cluster is running to delete.
ClusterPhaseDeleting ConditionType = "Deleting"
// ClusterPhaseError
// ClusterPhaseError : The cluster created failed because some reason.
ClusterPhaseError ConditionType = "Failed"
// ClusterPhaseUnknown
// ClusterPhaseUnknown : Unknown phase
ClusterPhaseUnknown ConditionType = "Unknown"
)

const (
// ConditionTypeEtcdReady
// ConditionTypeEtcdReady ...
ConditionTypeEtcdReady ConditionType = "EtcdReady"
// ConditionTypeMdsReady
// ConditionTypeMdsReady ...
ConditionTypeMdsReady ConditionType = "MdsReady"
// ConditionTypeFormatedReady
// ConditionTypeFormatedReady ...
ConditionTypeFormatedReady ConditionType = "formatedReady"
// ConditionTypeChunkServerReady
// ConditionTypeChunkServerReady ...
ConditionTypeChunkServerReady ConditionType = "ChunkServerReady"
// ConditionTypeSnapShotCloneReady
// ConditionTypeSnapShotCloneReady ...
ConditionTypeSnapShotCloneReady ConditionType = "SnapShotCloneReady"
// ConditionTypeDeleting
// ConditionTypeDeleting ...
ConditionTypeDeleting ConditionType = "Deleting"
// ConditionTypeClusterReady
// ConditionTypeClusterReady ...
ConditionTypeClusterReady ConditionType = "Ready"
// ConditionTypeFailure
// ConditionTypeFailure ...
ConditionTypeFailure ConditionType = "Failed"
// ConditionTypeUnknown
ConditionTypeUnknown ConditionType = "Unknow"
// ConditionTypeUnknown ...
ConditionTypeUnknown ConditionType = "Unknown"
)

type ConditionStatus string
Expand Down Expand Up @@ -155,7 +150,7 @@ type CurveClusterStatus struct {
// Important: Run "make" to regenerate code after modifying this file

// 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...
Expand Down Expand Up @@ -204,7 +199,7 @@ type CurveVersionSpec struct {
ImagePullPolicy v1.PullPolicy `json:"imagePullPolicy,omitempty"`
}

// EtcdSpec
// EtcdSpec ...
type EtcdSpec struct {
// +optional
PeerPort int `json:"peerPort,omitempty"`
Expand All @@ -216,7 +211,7 @@ type EtcdSpec struct {
Config map[string]string `json:"config,omitempty"`
}

// MdsSpec
// MdsSpec ...
type MdsSpec struct {
// +optional
Port int `json:"port,omitempty"`
Expand All @@ -228,7 +223,7 @@ type MdsSpec struct {
Config map[string]string `json:"config,omitempty"`
}

// SnapShotCloneSpec
// SnapShotCloneSpec ...
type SnapShotCloneSpec struct {
// +optional
Enable bool `json:"enable,omitempty"`
Expand All @@ -246,15 +241,15 @@ type SnapShotCloneSpec struct {
S3Config S3ConfigSpec `json:"s3Config,omitempty"`
}

// S3Config
// S3ConfigSpec ...
type S3ConfigSpec struct {
AK string `json:"ak,omitempty"`
SK string `json:"sk,omitempty"`
NosAddress string `json:"nosAddress,omitempty"`
SnapShotBucketName string `json:"bucketName,omitempty"`
}

// StorageScopeSpec
// StorageScopeSpec ...
type StorageScopeSpec struct {
// +optional
UseSelectedNodes bool `json:"useSelectedNodes,omitempty"`
Expand All @@ -275,7 +270,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"`
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
)

Expand Down
6 changes: 3 additions & 3 deletions pkg/chunkserver/chunkfilepool.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -272,7 +272,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"

Expand Down
3 changes: 2 additions & 1 deletion pkg/chunkserver/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -59,7 +60,6 @@ type configData struct {
data map[string]string
}

// chunkserverConfig implement ConfigInterface
func (c *chunkserverConfig) GetPrefix() string {
return c.Prefix
}
Expand Down Expand Up @@ -125,6 +125,7 @@ func (c *chunkserverConfig) GetDataDir() string {
}

// cluster

func (c *chunkserverConfig) GetClusterEtcdHttpAddr() string {
return ""
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/chunkserver/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/chunkserver/spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,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 {
Expand Down Expand Up @@ -360,7 +360,7 @@ func (c *Cluster) makeCSDaemonContainer(csConfig *chunkserverConfig) v1.Containe
return container
}

// getChunkServerPodLabels
// getChunkServerPodLabels ...
func (c *Cluster) getChunkServerPodLabels(csConfig *chunkserverConfig) map[string]string {
labels := make(map[string]string)
labels["app"] = AppName
Expand Down
6 changes: 3 additions & 3 deletions pkg/chunkserver/volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}

Expand All @@ -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{}
Expand Down Expand Up @@ -185,7 +185,7 @@ func CSConfigConfigMapVolumeAndMount(csConfig *chunkserverConfig) ([]v1.Volume,
return vols, mounts
}

// createTopoAndToolVolumeAndMount
// createTopoAndToolVolumeAndMount ...
func (c *Cluster) createTopoAndToolVolumeAndMount() ([]v1.Volume, []v1.VolumeMount) {
vols := []v1.Volume{}
mounts := []v1.VolumeMount{}
Expand Down
3 changes: 1 addition & 2 deletions pkg/config/variables.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,8 @@ func getValue(name string, dc ConfigInterface) string {
return ""
}

// ReplaceConfigVars
// ReplaceConfigVars ...
func ReplaceConfigVars(confStr string, c ConfigInterface) (string, error) {

r, err := regexp.Compile(REGEX_VARIABLE)
if err != nil {
return "", err
Expand Down
4 changes: 2 additions & 2 deletions pkg/controllers/cleanup.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (

const (
CleanupAppName = "curve-cleanup"
clusterCleanUpPolicyRetryInterval = 5 //seconds
clusterCleanUpPolicyRetryInterval = 5 * time.Second
)

var (
Expand All @@ -41,7 +41,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
Expand Down
4 changes: 2 additions & 2 deletions pkg/controllers/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func (c *cluster) reconcileCurveDaemons() error {
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)

Expand All @@ -86,7 +86,7 @@ func (c *cluster) reconcileCurveDaemons() error {
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)
Expand Down
4 changes: 1 addition & 3 deletions pkg/controllers/curvecluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,7 @@ func (r *CurveClusterReconciler) reconcileDelete(curveCluster *curvev1.CurveClus
}

// Delete it from clusterMap
if _, ok := r.ClusterController.clusterMap[curveCluster.Namespace]; ok {
delete(r.ClusterController.clusterMap, curveCluster.Namespace)
}
delete(r.ClusterController.clusterMap, curveCluster.Namespace)

// Remove finalizers
err := r.removeFinalizer(r.Client, r.ClusterController.namespacedName, curveCluster, "")
Expand Down
2 changes: 1 addition & 1 deletion pkg/controllers/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const (
JobName = "read-config"
)

var conf_type = [7]string{"mds.conf", "chunkserver.conf", "snapshotclone.conf", "s3.conf", "cs_client.conf", "snap_client.conf", "tools.conf"}
var confType = [7]string{"mds.conf", "chunkserver.conf", "snapshotclone.conf", "s3.conf", "cs_client.conf", "snap_client.conf", "tools.conf"}

// createEachConfigMap
func (c *cluster) createEachConfigMap() error {
Expand Down
2 changes: 1 addition & 1 deletion pkg/daemon/volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 volume mounts used by Curve daemon
func DaemonVolumeMounts(configMapDataKey string, configMapMountPathDir string, dataPaths *config.DataPathMap, curConfigMapName string) []v1.VolumeMount {
// create configmap mount path
mounts := []v1.VolumeMount{}
Expand Down
5 changes: 1 addition & 4 deletions pkg/k8sutil/condition.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,6 @@ 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())
}

return nil
return errors.Wrapf(err, "failed to update object %q status", nsName.String())
}
6 changes: 2 additions & 4 deletions pkg/k8sutil/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion pkg/k8sutil/readconf.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 451ff32

Please sign in to comment.