Skip to content
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

feat: Automatically trigger pod rollout for appsv1 resources when AuthProxyWorkload changes. #197

Merged
merged 3 commits into from
Feb 7, 2023

Conversation

hessjcg
Copy link
Collaborator

@hessjcg hessjcg commented Feb 7, 2023

Given an AuthProxyWorkload resource that has been applied to StatefulSet, DaemonSet,
ReplicaSet, and/or Deployment workloads, when that AuthProxyWorkload is updated, the operator
will add or modify an annotation on the PodTemplateSpec of that workload, causing k8s to
replace the workload's pods following the workload's rollout strategy, thus applying the
AuthProxyWorkload's configuration change.

Related to #187.

The code for this feature will be split across a few PRs for clarity. These are the first 4:

  1. (This PR) Automatically rollout pod changes on AuthProxyWorkload update.
  2. Automatically rollout pod changes on AuthProxyWorkload delete.
  3. Add AutomaticRolloutEnabled field to the AuthProxyWorkload resource.
  4. Update AuthProxyWorkload status conditions to show if a workload has out-of-date pods

@hessjcg hessjcg requested a review from a team as a code owner February 7, 2023 15:37
@hessjcg hessjcg force-pushed the gh-187-rollout branch 3 times, most recently from b70585b to e3ee326 Compare February 7, 2023 16:02

var status metav1.ConditionStatus
var result ctrl.Result
if upToDate {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small Go nit:

status := metav1.ConditionFalse
result := requeueNow

if upToDate {
  status = metav1.ConditionTrue
  result = ctrl.Result{}
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

// on the pod.
func PodAnnotation(r *cloudsqlapi.AuthProxyWorkload) (string, string) {
return fmt.Sprintf("%s/%s", cloudsqlapi.AnnotationPrefix, r.Name),
strconv.FormatInt(r.Generation, 10)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is 10?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

10 is "format this int64 in base 10"

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤦 Let's just use fmt.Sprintf("%d", r.Generation) in that. I somehow totally read over FormatInt.

}

// test that annotation was set properly
if !reflect.DeepEqual(wl.PodTemplateAnnotations(), wantAnnotations) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reflect.DeepEqual is fine here, but FYI there is https://github.com/google/go-cmp which is helpful for more sophistication comparisons.


// Check if the correct annotation exists
an := wl.PodTemplateAnnotations()
if an != nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if an != nil && an[k] == v {
  return false
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

@enocom enocom removed the request for review from jackwotherspoon February 7, 2023 18:29
Copy link
Collaborator Author

@hessjcg hessjcg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated and ready for a new review.


// Check if the correct annotation exists
an := wl.PodTemplateAnnotations()
if an != nil {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.


var status metav1.ConditionStatus
var result ctrl.Result
if upToDate {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

// on the pod.
func PodAnnotation(r *cloudsqlapi.AuthProxyWorkload) (string, string) {
return fmt.Sprintf("%s/%s", cloudsqlapi.AnnotationPrefix, r.Name),
strconv.FormatInt(r.Generation, 10)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

10 is "format this int64 in base 10"

@hessjcg
Copy link
Collaborator Author

hessjcg commented Feb 7, 2023

/gcbrun

@hessjcg hessjcg requested a review from enocom February 7, 2023 21:33
@hessjcg
Copy link
Collaborator Author

hessjcg commented Feb 7, 2023

/gcbrun

@hessjcg hessjcg merged commit 3b0359b into main Feb 7, 2023
@hessjcg hessjcg deleted the gh-187-rollout branch February 7, 2023 22:07
hessjcg pushed a commit that referenced this pull request Feb 21, 2023
Features
- Add new field RolloutStrategy control automatic rollout (#202) (090b88d)
- Add new terraform project for e2e test resources (#181) (0140592)
- Add script to run terraform with input validation. (#182) (857444a)
- Add support for Unix sockets. (#205) (8177a35), closes #47
- Add telemetry settings to configure health check port (#210) (3ede42d)
- Add the e2e test job for Cloud Build (#184) (dc2990c)
- Automatic changes to workloads when an AuthProxyWorload is deleted (#200) (e11caed)
- Automatically trigger pod rollout for appsv1 resources when AuthProxyWorkload changes. (#197) (3b0359b)
- Separate terraform for project setup and permissions (#179) (8f43657)
- Validate AuthProxyWorkload spec.selector field (#209) (98c460b)
- Validate AuthProxyWorkload updates to prevent changes to the workload selector. (#211) (4304283)

Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com>
Co-authored-by: Release PR Generate Bot action release-please[bot] <release-please[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants