-
Notifications
You must be signed in to change notification settings - Fork 16
feat: add new field RolloutStrategy control automatic rollout #202
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 all commits
72b7856
6c4b306
d140ce4
e39e0cb
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 |
|---|---|---|
|
|
@@ -880,6 +880,13 @@ spec: | |
| description: 'Requests describes the minimum amount of compute resources required. If Requests is omitted for a container, it defaults to Limits if that is explicitly specified, otherwise to an implementation-defined value. More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/' | ||
| type: object | ||
| type: object | ||
| rolloutStrategy: | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is generated from the source code comments: authproxyworkload_types.go |
||
| default: Workload | ||
| description: 'RolloutStrategy indicates the strategy to use when rolling out changes to the workloads affected by the results. When this is set to `Workload`, changes to this resource will be automatically applied to a running Deployment, StatefulSet, DaemonSet, or ReplicaSet in accordance with the Strategy set on that workload. When this is set to `None`, the operator will take no action to roll out changes to affected workloads. `Workload` will be used by default if no value is set. See: https://kubernetes.io/docs/concepts/workloads/controllers/deployment/#strategy' | ||
| enum: | ||
| - Workload | ||
| - None | ||
| type: string | ||
| sqlAdminAPIEndpoint: | ||
| description: SQLAdminAPIEndpoint is a debugging parameter that when specified will change the Google Cloud api endpoint used by the proxy. | ||
| type: string | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -58,7 +58,7 @@ func TestReconcileState11(t *testing.T) { | |
| Name: "test", | ||
| }, "project:region:db") | ||
|
|
||
| err := runReconcileTestcase(p, []client.Object{p}, true, "", "") | ||
| _, _, err := runReconcileTestcase(p, []client.Object{p}, true, "", "") | ||
| if err != nil { | ||
| t.Fatal(err) | ||
| } | ||
|
|
@@ -115,7 +115,7 @@ func TestReconcileState21ByName(t *testing.T) { | |
| addFinalizers(p) | ||
| addPodWorkload(p) | ||
|
|
||
| err := runReconcileTestcase(p, []client.Object{p}, false, metav1.ConditionTrue, v1alpha1.ReasonNoWorkloadsFound) | ||
| _, _, err := runReconcileTestcase(p, []client.Object{p}, false, metav1.ConditionTrue, v1alpha1.ReasonNoWorkloadsFound) | ||
| if err != nil { | ||
| t.Fatal(err) | ||
| } | ||
|
|
@@ -129,7 +129,7 @@ func TestReconcileState21BySelector(t *testing.T) { | |
| addFinalizers(p) | ||
| addSelectorWorkload(p, "Pod", "app", "things") | ||
|
|
||
| err := runReconcileTestcase(p, []client.Object{p}, false, metav1.ConditionTrue, v1alpha1.ReasonNoWorkloadsFound) | ||
| _, _, err := runReconcileTestcase(p, []client.Object{p}, false, metav1.ConditionTrue, v1alpha1.ReasonNoWorkloadsFound) | ||
| if err != nil { | ||
| t.Fatal(err) | ||
| } | ||
|
|
@@ -165,11 +165,82 @@ func TestReconcileState32(t *testing.T) { | |
| }}, | ||
| } | ||
|
|
||
| err := runReconcileTestcase(p, []client.Object{p, pod}, wantRequeue, wantStatus, wantReason) | ||
| c, ctx, err := runReconcileTestcase(p, []client.Object{p, pod}, wantRequeue, wantStatus, wantReason) | ||
| if err != nil { | ||
| t.Fatal(err) | ||
| } | ||
|
|
||
| // Fetch the deployment and make sure the annotations show the | ||
| // deleted resource. | ||
| d := &appsv1.Deployment{} | ||
| err = c.Get(ctx, types.NamespacedName{ | ||
| Namespace: pod.GetNamespace(), | ||
| Name: pod.GetName(), | ||
| }, d) | ||
| if err != nil { | ||
| t.Fatal(err) | ||
| } | ||
|
|
||
| if got, want := d.Spec.Template.ObjectMeta.Annotations[reqName], "2"; !strings.HasPrefix(got, "2") { | ||
| t.Fatalf("got %v, wants annotation value to have prefix %v", got, want) | ||
| } | ||
|
|
||
| } | ||
|
|
||
| func TestReconcileState32RolloutStrategyNone(t *testing.T) { | ||
| const ( | ||
| wantRequeue = false | ||
| wantStatus = metav1.ConditionTrue | ||
| wantReason = v1alpha1.ReasonFinishedReconcile | ||
| labelK = "app" | ||
| labelV = "things" | ||
| ) | ||
|
|
||
| p := testhelpers.BuildAuthProxyWorkload(types.NamespacedName{ | ||
| Namespace: "default", | ||
| Name: "test", | ||
| }, "project:region:db") | ||
| p.Spec.AuthProxyContainer = &v1alpha1.AuthProxyContainerSpec{ | ||
| RolloutStrategy: v1alpha1.NoneStrategy, | ||
| } | ||
| p.Generation = 2 | ||
| addFinalizers(p) | ||
| addSelectorWorkload(p, "Deployment", labelK, labelV) | ||
|
|
||
| // mimic a deployment that was updated by the webhook | ||
| deployment := &appsv1.Deployment{ | ||
| ObjectMeta: metav1.ObjectMeta{ | ||
| Name: "thing", | ||
| Namespace: "default", | ||
| Labels: map[string]string{labelK: labelV}, | ||
| }, | ||
| Spec: appsv1.DeploymentSpec{Template: corev1.PodTemplateSpec{ | ||
| ObjectMeta: metav1.ObjectMeta{Annotations: map[string]string{ | ||
| "annotation": "set", | ||
| }}, | ||
| }}, | ||
| } | ||
|
|
||
| c, ctx, err := runReconcileTestcase(p, []client.Object{p, deployment}, wantRequeue, wantStatus, wantReason) | ||
| if err != nil { | ||
| t.Fatal(err) | ||
| } | ||
|
|
||
| // Fetch the deployment and make sure the annotations show the | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This means the annotations are gone, but we haven't rolled it out, yeah?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This demonstrates the intended behavior. When RolloutStrategy== "None", then Reconcile() will not modify the Deployment's annotations. |
||
| // deleted resource. | ||
| d := &appsv1.Deployment{} | ||
| err = c.Get(ctx, types.NamespacedName{ | ||
| Namespace: deployment.GetNamespace(), | ||
| Name: deployment.GetName(), | ||
| }, d) | ||
| if err != nil { | ||
| t.Fatal(err) | ||
| } | ||
|
|
||
| if got, want := len(d.Spec.Template.ObjectMeta.Annotations), 1; got != want { | ||
| t.Fatalf("got %v annotations, wants %v annotations", got, want) | ||
| } | ||
|
|
||
| } | ||
|
|
||
| func TestReconcileState33(t *testing.T) { | ||
|
|
@@ -202,7 +273,7 @@ func TestReconcileState33(t *testing.T) { | |
| }}, | ||
| } | ||
|
|
||
| err := runReconcileTestcase(p, []client.Object{p, pod}, wantRequeue, wantStatus, wantReason) | ||
| _, _, err := runReconcileTestcase(p, []client.Object{p, pod}, wantRequeue, wantStatus, wantReason) | ||
| if err != nil { | ||
| t.Fatal(err) | ||
| } | ||
|
|
@@ -289,21 +360,21 @@ func TestReconcileDeleteUpdatesWorkload(t *testing.T) { | |
|
|
||
| } | ||
|
|
||
| func runReconcileTestcase(p *v1alpha1.AuthProxyWorkload, clientObjects []client.Object, wantRequeue bool, wantStatus metav1.ConditionStatus, wantReason string) error { | ||
| func runReconcileTestcase(p *v1alpha1.AuthProxyWorkload, clientObjects []client.Object, wantRequeue bool, wantStatus metav1.ConditionStatus, wantReason string) (client.WithWatch, context.Context, error) { | ||
| cb, err := clientBuilder() | ||
| if err != nil { | ||
| return err // shouldn't ever happen | ||
| return nil, nil, err // shouldn't ever happen | ||
| } | ||
|
|
||
| c := cb.WithObjects(clientObjects...).Build() | ||
|
|
||
| r, req, ctx := reconciler(p, c) | ||
| res, err := r.Reconcile(ctx, req) | ||
| if err != nil { | ||
| return err | ||
| return nil, nil, err | ||
| } | ||
| if res.Requeue != wantRequeue { | ||
| return fmt.Errorf("got %v, want %v for requeue", res.Requeue, wantRequeue) | ||
| return nil, nil, fmt.Errorf("got %v, want %v for requeue", res.Requeue, wantRequeue) | ||
| } | ||
|
|
||
| for _, o := range clientObjects { | ||
|
|
@@ -316,17 +387,17 @@ func runReconcileTestcase(p *v1alpha1.AuthProxyWorkload, clientObjects []client. | |
| if wantStatus != "" || wantReason != "" { | ||
| cond := findCondition(p.Status.Conditions, v1alpha1.ConditionUpToDate) | ||
| if cond == nil { | ||
| return fmt.Errorf("the UpToDate condition was nil, wants condition to exist") | ||
| return nil, nil, fmt.Errorf("the UpToDate condition was nil, wants condition to exist") | ||
| } | ||
| if wantStatus != "" && cond.Status != wantStatus { | ||
| return fmt.Errorf("got %v, want %v for UpToDate condition status", cond.Status, wantStatus) | ||
| return nil, nil, fmt.Errorf("got %v, want %v for UpToDate condition status", cond.Status, wantStatus) | ||
| } | ||
| if wantReason != "" && cond.Reason != wantReason { | ||
| return fmt.Errorf("got %v, want %v for UpToDate condition reason", cond.Reason, wantReason) | ||
| return nil, nil, fmt.Errorf("got %v, want %v for UpToDate condition reason", cond.Reason, wantReason) | ||
| } | ||
| } | ||
|
|
||
| return nil | ||
| return c, ctx, nil | ||
| } | ||
|
|
||
| func clientBuilder() (*fake.ClientBuilder, error) { | ||
|
|
||
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.
This is generated from the source code comments: authproxyworkload_types.go