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 12, 2023
1 parent 3d74dae commit 25ec5bc
Show file tree
Hide file tree
Showing 15 changed files with 69 additions and 54 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 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
Expand Down Expand Up @@ -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...
Expand Down Expand Up @@ -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"`
Expand All @@ -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"`
Expand All @@ -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"`
Expand All @@ -236,15 +231,15 @@ 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"`
NosAddress string `json:"nosAddress,omitempty"`
SnapShotBucketName string `json:"bucketName,omitempty"`
}

// StorageScopeSpec
// StorageScopeSpec is the spec of storage scope
type StorageScopeSpec struct {
// +optional
UseSelectedNodes bool `json:"useSelectedNodes,omitempty"`
Expand All @@ -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"`
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 @@ -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"

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 @@ -55,7 +56,6 @@ type chunkserverDataPathMap struct {
ContainerLogDir string
}

// chunkserverConfig implement ConfigInterface
func (c *chunkserverConfig) GetPrefix() string {
return c.Prefix
}
Expand Down Expand Up @@ -121,6 +121,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 @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
32 changes: 27 additions & 5 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,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{
Expand All @@ -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{
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 replaces vars in config string
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

dataVolumeName = "data-cleanup-volume"
dataDirHostPathEnv = "CURVE_DATA_DIR_HOST_PATH"
Expand All @@ -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
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 {
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
Expand All @@ -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)
Expand Down
1 change: 0 additions & 1 deletion pkg/controllers/curvecluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
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 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{}
Expand Down
1 change: 1 addition & 0 deletions pkg/k8sutil/condition.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
Expand Down
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 25ec5bc

Please sign in to comment.