Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

feat(main): fix panic for pipelines #38

Merged
merged 1 commit into from
Oct 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 13 additions & 20 deletions internal/controller/automq_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ func (r *AutoMQReconciler) reconcile(ctx context.Context, obj client.Object) (ct
return ctrl.Result{}, errors.New("obj convert automq is error")
}
automq.Status.ControllerAddresses = r.controllerVoters(automq)
pipelines := []func(ctx context.Context, mq *infrav1beta1.AutoMQ) context.Context{
pipelines := []func(ctx context.Context, mq *infrav1beta1.AutoMQ) bool{
r.s3Service,
r.scriptConfigmap,
r.syncControllersScale,
Expand All @@ -171,10 +171,10 @@ func (r *AutoMQReconciler) reconcile(ctx context.Context, obj client.Object) (ct
r.syncBrokers,
r.syncKafkaBootstrapService,
}

var ifRunning bool
for _, fn := range pipelines {
ctx = fn(ctx, automq)
if o, found := ctx.Value(ctxKey("goto")).(bool); found && o {
ifRunning = fn(ctx, automq)
if !ifRunning {
break
}
}
Expand Down Expand Up @@ -219,7 +219,7 @@ func (r *AutoMQReconciler) syncStatus(ctx context.Context, automq *infrav1beta1.
return nil
}

func (r *AutoMQReconciler) s3Service(ctx context.Context, obj *infrav1beta1.AutoMQ) context.Context {
func (r *AutoMQReconciler) s3Service(ctx context.Context, obj *infrav1beta1.AutoMQ) bool {
conditionType := "SyncS3ServiceReady"
sg, err := storage.NewBucket(storage.Config{
Type: "s3",
Expand All @@ -228,11 +228,6 @@ func (r *AutoMQReconciler) s3Service(ctx context.Context, obj *infrav1beta1.Auto
Region: obj.Spec.S3.Region,
Endpoint: obj.Spec.S3.Endpoint,
})
setGoto := func() {
if err != nil {
ctx = context.WithValue(ctx, ctxKey("goto"), true)
}
}
if err != nil {
meta.SetStatusCondition(&obj.Status.Conditions, metav1.Condition{
Type: conditionType,
Expand All @@ -241,8 +236,7 @@ func (r *AutoMQReconciler) s3Service(ctx context.Context, obj *infrav1beta1.Auto
Reason: "AwsS3ReconcilingInit",
Message: fmt.Sprintf("Failed to create S3 Bucket interface for the custom resource (%s): (%s)", obj.Name, err),
})
setGoto()
return ctx
return false
}
err = sg.MkBucket(ctx, obj.Spec.S3.Bucket)
if err != nil && !strings.Contains(err.Error(), "BucketAlready") {
Expand All @@ -253,8 +247,7 @@ func (r *AutoMQReconciler) s3Service(ctx context.Context, obj *infrav1beta1.Auto
Reason: "AwsS3ReconcilingBucket",
Message: fmt.Sprintf("Failed to create S3 Bucket interface for the custom resource (%s): (%s)", obj.Name, err),
})
setGoto()
return ctx
return false
}
meta.SetStatusCondition(&obj.Status.Conditions, metav1.Condition{
Type: conditionType,
Expand All @@ -263,10 +256,10 @@ func (r *AutoMQReconciler) s3Service(ctx context.Context, obj *infrav1beta1.Auto
Reason: "AwsS3Reconciling",
Message: fmt.Sprintf("S3 Bucket interface for the custom resource (%s) has been created", obj.Name),
})
return ctx
return true
}

func (r *AutoMQReconciler) scriptConfigmap(ctx context.Context, obj *infrav1beta1.AutoMQ) context.Context {
func (r *AutoMQReconciler) scriptConfigmap(ctx context.Context, obj *infrav1beta1.AutoMQ) bool {
log := log.FromContext(ctx)
conditionType := "SyncConfigmapReady"
data, err := defaults.Asset("defaults/up.sh")
Expand All @@ -278,7 +271,7 @@ func (r *AutoMQReconciler) scriptConfigmap(ctx context.Context, obj *infrav1beta
Reason: "ConfigmapReconcilingInit",
Message: fmt.Sprintf("Failed to create script configmap for the custom resource (%s): (%s)", obj.Name, err),
})
return ctx
return false
}
ctx = context.WithValue(ctx, ctxKey("hash-configmap"), hash.Hash(data))
if err = retry.RetryOnConflict(retry.DefaultRetry, func() error {
Expand All @@ -305,17 +298,17 @@ func (r *AutoMQReconciler) scriptConfigmap(ctx context.Context, obj *infrav1beta
Reason: "ConfigmapReconcilingCreate",
Message: fmt.Sprintf("Failed to create script configmap for the custom resource (%s): (%s)", obj.Name, err),
})
return ctx
return false
}

meta.SetStatusCondition(&obj.Status.Conditions, metav1.Condition{
Type: conditionType,
Status: metav1.ConditionTrue,
ObservedGeneration: obj.Generation,
Reason: "ConfigmapReconciling",
Message: fmt.Sprintf("Configmap script for the custom resource (%s) has been created", obj.Name),
Message: fmt.Sprintf("Script configmap for the custom resource (%s) has been created", obj.Name),
})
return ctx
return true
}

func getAutoMQLabelMap(name, role string) map[string]string {
Expand Down
26 changes: 17 additions & 9 deletions internal/controller/automq_controller_b.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func (r *AutoMQReconciler) cleanBroker(ctx context.Context, obj *infrav1beta1.Au
return nil
}

func (r *AutoMQReconciler) syncBrokerScale(ctx context.Context, obj *infrav1beta1.AutoMQ) context.Context {
func (r *AutoMQReconciler) syncBrokerScale(ctx context.Context, obj *infrav1beta1.AutoMQ) bool {
conditionType := "SyncBrokerScale"
currentReplicas := obj.Status.BrokerReplicas
if currentReplicas > obj.Spec.Broker.Replicas {
Expand All @@ -90,10 +90,10 @@ func (r *AutoMQReconciler) syncBrokerScale(ctx context.Context, obj *infrav1beta
Reason: "BrokerScaleReconciling",
Message: fmt.Sprintf("Broker scale for the custom resource (%s) has been reconciled", obj.Name),
})
return ctx
return true
}

func (r *AutoMQReconciler) syncBrokers(ctx context.Context, obj *infrav1beta1.AutoMQ) context.Context {
func (r *AutoMQReconciler) syncBrokers(ctx context.Context, obj *infrav1beta1.AutoMQ) bool {
conditionType := "SyncBrokerReady"

// 1. sync pvc
Expand All @@ -110,7 +110,7 @@ func (r *AutoMQReconciler) syncBrokers(ctx context.Context, obj *infrav1beta1.Au
Reason: "BrokerPVCReconciling",
Message: fmt.Sprintf("Failed to create pvc for the custom resource (%s): (%s)", obj.Name, err),
})
return ctx
return true
}
if err := r.syncBrokerService(ctx, obj, int32(i)); err != nil {
meta.SetStatusCondition(&obj.Status.Conditions, metav1.Condition{
Expand All @@ -120,7 +120,7 @@ func (r *AutoMQReconciler) syncBrokers(ctx context.Context, obj *infrav1beta1.Au
Reason: "BrokerServiceReconciling",
Message: fmt.Sprintf("Failed to create service for the custom resource (%s): (%s)", obj.Name, err),
})
return ctx
return true
}
if err := r.syncBrokerDeploy(ctx, obj, int32(i)); err != nil {
meta.SetStatusCondition(&obj.Status.Conditions, metav1.Condition{
Expand All @@ -130,7 +130,7 @@ func (r *AutoMQReconciler) syncBrokers(ctx context.Context, obj *infrav1beta1.Au
Reason: "BrokerSTSReconciling",
Message: fmt.Sprintf("Failed to create deploy for the custom resource (%s): (%s)", obj.Name, err),
})
return ctx
return true
}
}
meta.SetStatusCondition(&obj.Status.Conditions, metav1.Condition{
Expand All @@ -140,7 +140,7 @@ func (r *AutoMQReconciler) syncBrokers(ctx context.Context, obj *infrav1beta1.Au
Reason: "BrokerReconciling",
Message: fmt.Sprintf("Broker resource for the custom resource (%s) has been created or update", obj.Name),
})
return ctx
return true
}

func (r *AutoMQReconciler) syncBrokerPVC(ctx context.Context, obj *infrav1beta1.AutoMQ, index int32) error {
Expand Down Expand Up @@ -441,7 +441,7 @@ func (r *AutoMQReconciler) syncBrokerService(ctx context.Context, obj *infrav1be
return nil
}

func (r *AutoMQReconciler) syncKafkaBootstrapService(ctx context.Context, obj *infrav1beta1.AutoMQ) context.Context {
func (r *AutoMQReconciler) syncKafkaBootstrapService(ctx context.Context, obj *infrav1beta1.AutoMQ) bool {
log := log.FromContext(ctx)
conditionType := "SyncBootstrapServiceReady"

Expand Down Expand Up @@ -479,6 +479,14 @@ func (r *AutoMQReconciler) syncKafkaBootstrapService(ctx context.Context, obj *i
Reason: "BootstrapServiceReconciling",
Message: fmt.Sprintf("Failed to create bootstrap service for the custom resource (%s): (%s)", obj.Name, err),
})
return true
}
return nil
meta.SetStatusCondition(&obj.Status.Conditions, metav1.Condition{
Type: conditionType,
Status: metav1.ConditionTrue,
ObservedGeneration: obj.Generation,
Reason: "BootstrapServiceReconciling",
Message: fmt.Sprintf("Bootstrap service for the custom resource (%s) has been created", obj.Name),
})
return true
}
14 changes: 7 additions & 7 deletions internal/controller/automq_controller_c.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func (r *AutoMQReconciler) cleanController(ctx context.Context, obj *infrav1beta
return nil
}

func (r *AutoMQReconciler) syncControllersScale(ctx context.Context, obj *infrav1beta1.AutoMQ) context.Context {
func (r *AutoMQReconciler) syncControllersScale(ctx context.Context, obj *infrav1beta1.AutoMQ) bool {
conditionType := "SyncControllerScale"
currentReplicas := obj.Status.ControllerReplicas
if currentReplicas > obj.Spec.Controller.Replicas {
Expand All @@ -85,10 +85,10 @@ func (r *AutoMQReconciler) syncControllersScale(ctx context.Context, obj *infrav
Reason: "ControllerScaleReconciling",
Message: fmt.Sprintf("Controller scale for the custom resource (%s) has been reconciled", obj.Name),
})
return ctx
return true
}

func (r *AutoMQReconciler) syncControllers(ctx context.Context, obj *infrav1beta1.AutoMQ) context.Context {
func (r *AutoMQReconciler) syncControllers(ctx context.Context, obj *infrav1beta1.AutoMQ) bool {
conditionType := "SyncControllerReady"

// 1. sync pvc
Expand All @@ -105,7 +105,7 @@ func (r *AutoMQReconciler) syncControllers(ctx context.Context, obj *infrav1beta
Reason: "ControllerPVCReconciling",
Message: fmt.Sprintf("Failed to create pvc for the custom resource (%s): (%s)", obj.Name, err),
})
return ctx
return true
}
if err := r.syncControllerDeploy(ctx, obj, int32(i)); err != nil {
meta.SetStatusCondition(&obj.Status.Conditions, metav1.Condition{
Expand All @@ -115,7 +115,7 @@ func (r *AutoMQReconciler) syncControllers(ctx context.Context, obj *infrav1beta
Reason: "ControllerSTSReconciling",
Message: fmt.Sprintf("Failed to create deploy for the custom resource (%s): (%s)", obj.Name, err),
})
return ctx
return true
}
if err := r.syncControllerService(ctx, obj, int32(i)); err != nil {
meta.SetStatusCondition(&obj.Status.Conditions, metav1.Condition{
Expand All @@ -125,7 +125,7 @@ func (r *AutoMQReconciler) syncControllers(ctx context.Context, obj *infrav1beta
Reason: "ControllerServiceReconciling",
Message: fmt.Sprintf("Failed to create service for the custom resource (%s): (%s)", obj.Name, err),
})
return ctx
return true
}
}
meta.SetStatusCondition(&obj.Status.Conditions, metav1.Condition{
Expand All @@ -135,7 +135,7 @@ func (r *AutoMQReconciler) syncControllers(ctx context.Context, obj *infrav1beta
Reason: "ControllerReconciling",
Message: fmt.Sprintf("Controller resource for the custom resource (%s) has been created or update", obj.Name),
})
return ctx
return true
}

func (r *AutoMQReconciler) syncControllerPVC(ctx context.Context, obj *infrav1beta1.AutoMQ, index int32) error {
Expand Down