-
Notifications
You must be signed in to change notification settings - Fork 61
K8SPG-698: create serviceaccount before statefulset #1125
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
result.Requeue = true | ||
return result, nil | ||
} | ||
// K8SPG-698: it should happen earlier |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we removed comments
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
} | ||
serviceAccountName := sts.Spec.Template.Spec.ServiceAccountName | ||
if serviceAccountName == "" { | ||
panic("it's not expected to have empty service account name") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since checkObject(...)
returns an error and when used we do this
if err := sc.checkObject(ctx, obj); err != nil {
panic(err) // should panic because reconciler can ignore the error
}
I think this check can return an error and let the caller panic it. WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
func (sc *saTestClient) Update(ctx context.Context, obj client.Object, opts ...client.UpdateOption) error { | ||
if err := sc.checkObject(ctx, obj); err != nil { | ||
panic(err) // should panic because reconciler can ignore the error | ||
} | ||
return sc.Client.Update(ctx, obj, opts...) | ||
} | ||
|
||
func (sc *saTestClient) Patch(ctx context.Context, obj client.Object, patch client.Patch, opts ...client.PatchOption) error { | ||
if err := sc.checkObject(ctx, obj); err != nil { | ||
panic(err) // should panic because reconciler can ignore the error | ||
} | ||
return sc.Client.Patch(ctx, obj, patch, opts...) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need these? Seems that they are not used in the test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Crunchy code uses a patch
request to create the ServiceAccount instead of a create
request:
func (r *Reconciler) apply(ctx context.Context, object client.Object) error { | |
// Generate an apply-patch by comparing the object to its zero value. | |
zero := reflect.New(reflect.TypeOf(object).Elem()).Interface() | |
data, err := client.MergeFrom(zero.(client.Object)).Data(object) | |
apply := client.RawPatch(client.Apply.Type(), data) | |
// Keep a copy of the object before any API calls. | |
intent := object.DeepCopyObject() | |
patch := kubeapi.NewJSONPatch() | |
// Send the apply-patch with force=true. | |
if err == nil { | |
err = r.patch(ctx, object, apply, client.ForceOwnership) | |
} | |
// Some fields cannot be server-side applied correctly. When their outcome | |
// does not match the intent, send a json-patch to get really specific. | |
switch actual := object.(type) { | |
case *corev1.Service: | |
applyServiceSpec(patch, actual.Spec, intent.(*corev1.Service).Spec, "spec") | |
} | |
// Send the json-patch when necessary. | |
if err == nil && !patch.IsEmpty() { | |
err = r.patch(ctx, object, patch) | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seems ok, let's check the golangci and the envtests why they are failing and then we can approve. |
commit: f24206a |
https://perconadev.atlassian.net/browse/K8SPG-698
DESCRIPTION
Problem:
The
cluster1-repo-host
StatefulSet is created before its corresponding ServiceAccountcluster1-pgbackrest
exists. This can cause failures in certain environments.Solution:
Create ServiceAccount before the StatefulSet.
CHECKLIST
Jira
Needs Doc
) and QA (Needs QA
)?Tests
Config/Logging/Testability