Skip to content

Commit

Permalink
refactor: set default values back to the original resource
Browse files Browse the repository at this point in the history
  • Loading branch information
zyy17 committed Aug 28, 2024
1 parent 5c3668f commit 7355c2d
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 33 deletions.
2 changes: 1 addition & 1 deletion apis/v1alpha1/defaulting.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ var (
// The default replicas for frontend/meta/datanode.
defaultFrontendReplicas int32 = 1
defaultMetaReplicas int32 = 1
defaultDatanodeReplicas int32 = 3
defaultDatanodeReplicas int32 = 1
defaultFlownodeReplicas int32 = 1

// The default storage settings for datanode.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ spec:
datanode:
httpPort: 4000
rpcPort: 4001
replicas: 3
replicas: 1
storage:
dataHome: /data/greptimedb
mountPath: /data/greptimedb
Expand Down
16 changes: 11 additions & 5 deletions controllers/greptimedbcluster/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,14 +137,20 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (result ct
return
}

if err = cluster.SetDefaults(); err != nil {
r.Recorder.Event(cluster, corev1.EventTypeWarning, "SetDefaultValuesFailed", fmt.Sprintf("Set default values failed: %v", err))
return
}

// Means the cluster is just created.
if len(cluster.Status.ClusterPhase) == 0 {
klog.Infof("Start to create the cluster '%s/%s'", cluster.Namespace, cluster.Name)

if err = cluster.SetDefaults(); err != nil {
r.Recorder.Event(cluster, corev1.EventTypeWarning, "SetDefaultValuesFailed", fmt.Sprintf("Set default values failed: %v", err))
return
}

if err = r.Update(ctx, cluster); err != nil {
r.Recorder.Event(cluster, corev1.EventTypeWarning, "UpdateClusterFailed", fmt.Sprintf("Update cluster failed: %v", err))
return
}

if err = r.updateClusterStatus(ctx, cluster, v1alpha1.PhaseStarting); err != nil {
return
}
Expand Down
16 changes: 11 additions & 5 deletions controllers/greptimedbstandalone/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,20 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (result ct
return

Check failure on line 118 in controllers/greptimedbstandalone/controller.go

View workflow job for this annotation

GitHub Actions / Build the project

naked return in func `Reconcile` with 56 lines of code (nakedret)
}

if err = standalone.SetDefaults(); err != nil {
r.Recorder.Event(standalone, corev1.EventTypeWarning, "SetDefaultValuesFailed", fmt.Sprintf("Set default values failed: %v", err))
return
}

// Means the standalone is just created.
if len(standalone.Status.StandalonePhase) == 0 {
klog.Infof("Start to create the standalone '%s/%s'", standalone.Namespace, standalone.Name)

if err = standalone.SetDefaults(); err != nil {
r.Recorder.Event(standalone, corev1.EventTypeWarning, "SetDefaultValuesFailed", fmt.Sprintf("Set default values failed: %v", err))
return

Check failure on line 127 in controllers/greptimedbstandalone/controller.go

View workflow job for this annotation

GitHub Actions / Build the project

naked return in func `Reconcile` with 56 lines of code (nakedret)
}

if err = r.Update(ctx, standalone); err != nil {
r.Recorder.Event(standalone, corev1.EventTypeWarning, "UpdateStandaloneFailed", fmt.Sprintf("Update standalone failed: %v", err))
return
}

if err = r.setStandaloneStatus(ctx, standalone, v1alpha1.PhaseStarting); err != nil {
return
}
Expand Down
5 changes: 0 additions & 5 deletions tests/e2e/testdata/resources/cluster/basic/cluster.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,3 @@ spec:
- etcd.etcd-cluster:2379
datanode:
replicas: 3
httpPort: 4000
rpcPort: 4001
mysqlPort: 4002
postgreSQLPort: 4003

4 changes: 0 additions & 4 deletions tests/e2e/testdata/resources/cluster/enable-flow/cluster.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,3 @@ spec:
replicas: 3
flownode:
replicas: 2
httpPort: 4000
rpcPort: 4001
mysqlPort: 4002
postgreSQLPort: 4003
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,3 @@ spec:
kafka:
brokerEndpoints:
- kafka-wal-kafka-bootstrap.kafka:9092
httpPort: 4000
rpcPort: 4001
mysqlPort: 4002
postgreSQLPort: 4003
4 changes: 0 additions & 4 deletions tests/e2e/testdata/resources/cluster/scale/cluster.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,3 @@ spec:
replicas: 1
storage:
storageRetainPolicy: Delete
httpPort: 4000
rpcPort: 4001
mysqlPort: 4002
postgreSQLPort: 4003
4 changes: 0 additions & 4 deletions tests/e2e/testdata/resources/standalone/basic/standalone.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,3 @@ spec:
base:
main:
image: localhost:5001/greptime/greptimedb:latest
httpPort: 4000
rpcPort: 4001
mysqlPort: 4002
postgreSQLPort: 4003

0 comments on commit 7355c2d

Please sign in to comment.