Struct Type String Value Empty on Reconciliation
Closed this issue · 1 comments
Support Request:
Type of question
General operator-related help
Question
What did you do?
I'm encountering an issue with the reconciliation process of my Operator SDK project. Here's a breakdown of the situation:
I have an Operator SDK project with the following ComponentSpec
struct:
type ComponentSpec struct {
Size int32 `json:"size"`
Chart string `json:"chart"`
}
And I have a YAML manifest for a custom resource of kind Component
:
apiVersion: ezto.ezto.io/v1alpha1
kind: Component
metadata:
labels:
app.kubernetes.io/name: component
app.kubernetes.io/instance: component-sample
app.kubernetes.io/managed-by: kustomize
name: component-sample
spec:
size: 1
chart: test
At recouncile function im just logging the values
func (r *ComponentReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
_ = log.FromContext(ctx)
var componentLog = ctrl.Log.WithName("component")
componentLog.Info("starting reconciling", "name", eztov1alpha1.Component{})
return ctrl.Result{}, nil
}
What did you expect to see?
I expected the reconciliation process to populate the Chart
field of the ComponentSpec
struct with the value "test"
from the provided YAML manifest during reconciliation.
{"name": {"metadata":{"creationTimestamp":null},"spec":{"size":0,"chart":"test"}}}
What did you see instead? Under which circumstances?
However, during reconciliation, the Chart
value remains empty. Here's the log indicating the issue:
{"name": {"metadata":{"creationTimestamp":null},"spec":{"size":0,"chart":""}}}
Environment
Operator type: Go
Kubernetes cluster type: Vanilla
$ operator-sdk version
operator-sdk version: "v1.34.1"
commit: "edaed1e5057db0349568e0b02df3743051b54e68"
kubernetes version: "v1.28.0"
go version: "go1.21.7"
GOOS: "darwin"
GOARCH: "amd64"
$ go version
go version go1.21.7 darwin/amd64
$ kubectl version
Client Version: v1.29.1
Kustomize Version: v5.0.4-0.20230601165947-6ce0bf390ce3
Server Version: v1.29.1
Additional context
This issue persists despite the provided YAML manifest containing the correct value for the chart
field.
Any assistance in resolving this issue would be greatly appreciated. Thank you!
https://sdk.operatorframework.io/docs/building-operators/golang/tutorial/#reconcile-loop
recouncil loop has to be implemented before using the struct
ezto := &eztov1alpha1.Component{}
err := r.Get(ctx, req.NamespacedName, ezto)