-
Notifications
You must be signed in to change notification settings - Fork 67
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
Changes from 2 commits
af4977a
5dcd0e0
f1f4ce3
3497874
da937df
d58f029
5eba903
f24206a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -1622,3 +1622,118 @@ var _ = Describe("Validate TLS", Ordered, func() { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| checkSecretProjectionWithCA(cr, cr.Spec.Secrets.CustomReplicationClientTLSSecret, secretName) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| type saTestClient struct { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| client.Client | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| crName string | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ns string | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| func (sc *saTestClient) checkObject(ctx context.Context, obj client.Object) error { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| sts, ok := obj.(*appsv1.StatefulSet) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if !ok { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return nil | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| serviceAccountName := sts.Spec.Template.Spec.ServiceAccountName | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if serviceAccountName == "" { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| panic("it's not expected to have empty service account name") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if err := sc.Client.Get(ctx, types.NamespacedName{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Name: serviceAccountName, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Namespace: sts.Namespace, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, new(corev1.ServiceAccount)); err != nil { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if k8serrors.IsNotFound(err) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return errors.Wrap(err, "test error: service account should be created before the statefulset") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return err | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return nil | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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...) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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.
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.
f1f4ce3