-
Notifications
You must be signed in to change notification settings - Fork 6
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
chore: migrate controllers to SSA #112
Changes from all commits
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 |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package controllers | ||
|
||
import ( | ||
"encoding/json" | ||
|
||
accuratev2alpha1 "github.com/cybozu-go/accurate/api/accurate/v2alpha1" | ||
accuratev2alpha1ac "github.com/cybozu-go/accurate/internal/applyconfigurations/accurate/v2alpha1" | ||
corev1 "k8s.io/api/core/v1" | ||
"k8s.io/apimachinery/pkg/types" | ||
corev1ac "k8s.io/client-go/applyconfigurations/core/v1" | ||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
) | ||
|
||
const ( | ||
fieldOwner client.FieldOwner = "accurate-controller" | ||
) | ||
|
||
func newSubNamespacePatch(ac *accuratev2alpha1ac.SubNamespaceApplyConfiguration) (*accuratev2alpha1.SubNamespace, client.Patch, error) { | ||
sn := &accuratev2alpha1.SubNamespace{} | ||
sn.Name = *ac.Name | ||
sn.Namespace = *ac.Namespace | ||
|
||
return sn, applyPatch{ac}, nil | ||
} | ||
|
||
func newNamespacePatch(ac *corev1ac.NamespaceApplyConfiguration) (*corev1.Namespace, client.Patch, error) { | ||
ns := &corev1.Namespace{} | ||
ns.Name = *ac.Name | ||
|
||
return ns, applyPatch{ac}, nil | ||
} | ||
|
||
type applyPatch struct { | ||
// must use any type until apply configurations implements a common interface | ||
patch any | ||
} | ||
|
||
func (p applyPatch) Type() types.PatchType { | ||
return types.ApplyPatchType | ||
} | ||
|
||
func (p applyPatch) Data(_ client.Object) ([]byte, error) { | ||
return json.Marshal(p.patch) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,7 +30,7 @@ metadata: | |
team: foo | ||
``` | ||
|
||
Accurate only propagates labels/annotations that have been configured in that respect via the `labelKeys` and `annotationKeys` parameters in `config.yaml`. This prevents the propagation of labels/annotations that were not meant to do so. Accurate currently does not delete previously propagated labels when deleted from the parent namespace to prevent unintended deletions. Users are expected to manually delete labels/annotations that are no longer needed. | ||
Accurate only propagates labels/annotations that have been configured in that respect via the `labelKeys` and `annotationKeys` parameters in `config.yaml`. This prevents the propagation of labels/annotations that were not meant to do so. | ||
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 PR includes a change in specifications. 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. 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. Exactly! @ymmt2005 is correct that this is the main motivation for this PR. There is yet no 1. class support for SSA in controller-runtime, but I have been involved in migrating several operators to SSA using the same approach as in this PR. So I am pretty sure it works, and it's also properly tested now IMO. The main concern with SSA migration is the risk of getting never-ending reconcile loops, but I have added new tests for this. We would be extremely happy if this PR could eventually get merged and released. #98 is a semi-blocker for our further rollout of Accurate in our clusters. 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. @erikgb |
||
|
||
### Preparing resources for tenant users | ||
|
||
|
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.
What do you want this test to confirm?
I think confirming that ns is created from template and that labels and annotations are propagated has already been tested here.
accurate/controllers/namespace_controller_test.go
Line 163 in cda331b
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 test is to ensure consistent reconciles. Reconcile loops is the one thing to fear when migrating to SSA.
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.
Thanks to you, I understood.