Skip to content

Commit

Permalink
feat(main): fix helm config (#41)
Browse files Browse the repository at this point in the history
Signed-off-by: cuisongliu <[email protected]>
  • Loading branch information
cuisongliu authored Oct 14, 2024
1 parent c650b53 commit 4ef33c6
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 5 deletions.
3 changes: 3 additions & 0 deletions api/v1beta1/automq_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ func (r *AutoMQ) ValidateUpdate(old runtime.Object) (admission.Warnings, error)
if r.Spec.ClusterID != mqOld.Spec.ClusterID {
return nil, fmt.Errorf("field clusterID is immutable")
}
if r.Spec.Controller.Replicas != mqOld.Spec.Controller.Replicas {
return nil, fmt.Errorf("field controller.replicas is immutable")
}
if err := validate(r); err != nil {
return nil, err
}
Expand Down
37 changes: 37 additions & 0 deletions deploy/charts/automq-operator/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,40 @@ Selector labels
app.kubernetes.io/name: {{ include "automq-operator.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}


{{/*
Extract the tag from the image repository string.
Assumes the tag is the part after the last colon `:`.
If no tag is present, returns an empty string.
*/}}
{{- define "automq-operator.getTag" -}}
{{- $image := .Values.image -}}
{{- $splitImage := splitList ":" $image -}}
{{- if eq (len $splitImage) 2 -}}
{{- index $splitImage 1 -}}
{{- else -}}
latest
{{- end -}}
{{- end -}}

{{/*
Determine the image pull policy.
If the image tag is 'latest', set the pull policy to 'Always'.
Otherwise, use the default pull policy from values.yaml.
*/}}
{{- define "automq-operator.pullPolicy" -}}
{{- if eq (include "automq-operator.getTag" .) "latest" -}}
Always
{{- else -}}
IfNotPresent
{{- end -}}
{{- end -}}

{{- define "automq-operator.revision" -}}
{{- if eq (include "automq-operator.getTag" .) "latest" -}}
{{.Release.Revision}}
{{- else -}}
{{ include "automq-operator.getTag" .}}
{{- end -}}
{{- end -}}
7 changes: 4 additions & 3 deletions deploy/charts/automq-operator/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ spec:
{{- include "automq-operator.selectorLabels" . | nindent 6 }}
template:
metadata:
{{- with .Values.podAnnotations }}
annotations:
{{- with .Values.podAnnotations }}
{{- toYaml . | nindent 8 }}
{{- end }}
{{- end }}
operator-revision: {{ include "automq-operator.revision" . }}
labels:
{{- include "automq-operator.selectorLabels" . | nindent 8 }}
spec:
Expand All @@ -34,7 +35,7 @@ spec:
securityContext:
{{- toYaml .Values.securityContext | nindent 12 }}
image: "{{ .Values.image }}"
imagePullPolicy: IfNotPresent
imagePullPolicy: {{ include "automq-operator.pullPolicy" . }}
args:
- "-leader-elect={{.Values.args.leader}}"
- "-default-burst={{.Values.args.burst}}"
Expand Down
9 changes: 7 additions & 2 deletions internal/controller/automq_controller_b.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func (r *AutoMQReconciler) cleanBroker(ctx context.Context, obj *infrav1beta1.Au
svcc.Name = getAutoMQName(brokerRole, &index)
_ = r.Client.Delete(ctx, svcc)

deploy := &appsv1.StatefulSet{}
deploy := &appsv1.Deployment{}
deploy.Namespace = obj.Namespace
deploy.Name = getAutoMQName(brokerRole, &index)
_ = r.Client.Delete(ctx, deploy)
Expand All @@ -61,6 +61,11 @@ func (r *AutoMQReconciler) cleanBroker(ctx context.Context, obj *infrav1beta1.Au
pvc.Name = getAutoMQName(brokerRole, &index)
_ = r.Client.Delete(ctx, pvc)
}

bsvc := &v1.Service{}
bsvc.Namespace = obj.Namespace
bsvc.Name = getAutoMQName(brokerRole+"-bootstrap", nil)
_ = r.Client.Delete(ctx, bsvc)
return nil
}

Expand Down Expand Up @@ -261,7 +266,7 @@ func (r *AutoMQReconciler) syncBrokerDeploy(ctx context.Context, obj *infrav1bet
"--process.roles",
"broker",
"--node.id",
fmt.Sprintf("%d", index+10),
fmt.Sprintf("%d", index+obj.Spec.Controller.Replicas),
"--cluster.id",
obj.Spec.ClusterID,
"--controller.quorum.voters",
Expand Down

0 comments on commit 4ef33c6

Please sign in to comment.