-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
✨ Minimal MachineHealthCheck Reconciler skeleton #2101
✨ Minimal MachineHealthCheck Reconciler skeleton #2101
Conversation
/hold #2049 Should be merged before this, I will rebase once that is done |
@JoelSpeed Can you please merge the two PRs so they can be reviewed together? |
@vincepri I assumed it would be easier to review if it were two separate PRs, reviewing the first before merging the second? If you'd rather review them together, then this PR contains all commits from the previous one, so I could close the previous in favour of this? (Though I noticed my last commit needs a fixup) |
Closing the other one seems fine to me, let's keep the commits separate until we're ready to merge the PR in, usually we require to squash at the end. |
91ac792
to
730bca2
Compare
/unhold Ready for review whenever people have time |
730bca2
to
57a637c
Compare
8f46a38
to
19cac02
Compare
By("Ensuring the namespace exists") | ||
if err := k8sClient.Get(ctx, client.ObjectKey{Name: namespace.GetName()}, namespace.DeepCopy()); apierrors.IsNotFound(err) { | ||
Expect(k8sClient.Create(ctx, namespace.DeepCopy())).To(Succeed()) | ||
} | ||
By("Creating the Cluster") | ||
Expect(k8sClient.Create(ctx, testCluster.DeepCopy())).To(Succeed()) | ||
}) | ||
|
||
AfterEach(func() { | ||
By("Deleting any MachineHealthChecks") | ||
Expect(cleanupTestMachineHealthChecks(ctx, k8sClient)).To(Succeed()) | ||
By("Deleting the Cluster") | ||
Expect(k8sClient.Delete(ctx, testCluster.DeepCopy())).To(Succeed()) |
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.
Why all the DeepCopy() calls?
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.
I was trying to avoid modifying the namespace
and testCluster
variables so they would be clean for each test, and they would be populated correctly when Ginkgo is building it's test graph, but I've managed to refactor to avoid the deepcopy's
return err | ||
} | ||
for _, mhc := range mhcList.Items { | ||
err = c.Delete(ctx, mhc.DeepCopy()) |
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.
Why DeepCopy?
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 one is because I needed a pointer and mhc
is a range variable, I've declared a second variable in the scope and that works, don't know if that's better or not?
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.
@ncdc thanks for the review, I've addressed your feedback
By("Ensuring the namespace exists") | ||
if err := k8sClient.Get(ctx, client.ObjectKey{Name: namespace.GetName()}, namespace.DeepCopy()); apierrors.IsNotFound(err) { | ||
Expect(k8sClient.Create(ctx, namespace.DeepCopy())).To(Succeed()) | ||
} | ||
By("Creating the Cluster") | ||
Expect(k8sClient.Create(ctx, testCluster.DeepCopy())).To(Succeed()) | ||
}) | ||
|
||
AfterEach(func() { | ||
By("Deleting any MachineHealthChecks") | ||
Expect(cleanupTestMachineHealthChecks(ctx, k8sClient)).To(Succeed()) | ||
By("Deleting the Cluster") | ||
Expect(k8sClient.Delete(ctx, testCluster.DeepCopy())).To(Succeed()) |
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.
I was trying to avoid modifying the namespace
and testCluster
variables so they would be clean for each test, and they would be populated correctly when Ginkgo is building it's test graph, but I've managed to refactor to avoid the deepcopy's
return err | ||
} | ||
for _, mhc := range mhcList.Items { | ||
err = c.Delete(ctx, mhc.DeepCopy()) |
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 one is because I needed a pointer and mhc
is a range variable, I've declared a second variable in the scope and that works, don't know if that's better or not?
a89504f
to
93400e3
Compare
} | ||
|
||
// PopulateDefaultsMachineHealthCheck fills in default field values. | ||
func PopulateDefaultsMachineHealthCheck(m *MachineHealthCheck) { |
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.
Please delete this function and move its contents into Default()
above.
|
||
// PopulateDefaultsMachineHealthCheck fills in default field values. | ||
func PopulateDefaultsMachineHealthCheck(m *MachineHealthCheck) { | ||
defaultMaxUnhealthy := intstr.FromString("100%") |
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 this inside the if check
func (m *MachineHealthCheck) ValidateUpdate(old runtime.Object) error { | ||
mhc, ok := old.(*MachineHealthCheck) | ||
if !ok { | ||
return fmt.Errorf("expected a MachineHealthCheck but got a %T", old) |
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 should return apierrors.NewInvalid(...)
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.
bump
) | ||
|
||
const ( | ||
mhcClusterNameIndex = "mhcClusterNameIndex" |
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.
mhcClusterNameIndex = "mhcClusterNameIndex" | |
mhcClusterNameIndex = "spec.clusterName" |
Scheme: scheme.Scheme, | ||
MetricsBindAddress: "0", | ||
NewCache: func(config *rest.Config, opts cache.Options) (cache.Cache, error) { | ||
syncPeriod := 1 * time.Second |
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's the motivation for having a sync period?
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.
Honestly, I copied the manager set up over from suite_test assuming there was some good reason for it 😅 I don't think it will make a difference to these tests and will get rid of it
93623f0
to
7e354eb
Compare
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.
@ncdc I've fixed up all of your suggestions :)
Scheme: scheme.Scheme, | ||
MetricsBindAddress: "0", | ||
NewCache: func(config *rest.Config, opts cache.Options) (cache.Cache, error) { | ||
syncPeriod := 1 * time.Second |
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.
Honestly, I copied the manager set up over from suite_test assuming there was some good reason for it 😅 I don't think it will make a difference to these tests and will get rid of it
func (m *MachineHealthCheck) ValidateUpdate(old runtime.Object) error { | ||
mhc, ok := old.(*MachineHealthCheck) | ||
if !ok { | ||
return fmt.Errorf("expected a MachineHealthCheck but got a %T", old) |
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.
bump
) | ||
|
||
const ( | ||
mhcClusterNameIndex = "spec.ClusterName" |
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.
mhcClusterNameIndex = "spec.ClusterName" | |
mhcClusterNameIndex = "spec.clusterName" |
I think I just have 2 small outstanding items and then I say we merge & iterate in future PRs |
7e354eb
to
10a7dc1
Compare
@ncdc Apologies, I somehow missed commiting what I had done on the |
mhc, ok := old.(*MachineHealthCheck) | ||
if !ok { | ||
err := field.Invalid(&field.Path{}, old, fmt.Sprintf("expected a MachineHealthCheck but got a %T", old)) | ||
return apierrors.NewInvalid(GroupVersion.WithKind("MachineHealthCheck").GroupKind(), "", field.ErrorList{err}) |
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.
Hmm yeah... maybe we should use NewBadRequest(reason)
instead?
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.
That is much cleaner! Fixed
10a7dc1
to
ac1954c
Compare
// clusterToMachineHealthCheck maps events from Cluster objects to | ||
// MachineHealthCheck objects that belong to the Cluster | ||
func (r *MachineHealthCheckReconciler) clusterToMachineHealthCheck(o handler.MapObject) []reconcile.Request { | ||
m, ok := o.Object.(*clusterv1.Cluster) |
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.
nit: replace m
with c
ac1954c
to
1b7bfbb
Compare
1b7bfbb
to
c5634e9
Compare
LGTM, please squash!!! |
Should I do one commit for the types and another for the reconciler or just all in one? |
I'm fine with 1 commit |
c5634e9
to
5a8da83
Compare
Great, squashed :) |
/lgtm 🎉🎉🎉🎉 |
func (r *MachineHealthCheckReconciler) clusterToMachineHealthCheck(o handler.MapObject) []reconcile.Request { | ||
c, ok := o.Object.(*clusterv1.Cluster) | ||
if !ok { | ||
r.Log.Error(errors.New("incorrect type"), "expected a MachineHealthCheck", "type", fmt.Sprintf("%T", o)) |
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.
@ncdc Sorry, I just realised I've made a typo here, will fix-up and re-push
r.Log.Error(errors.New("incorrect type"), "expected a MachineHealthCheck", "type", fmt.Sprintf("%T", o)) | |
r.Log.Error(errors.New("incorrect type"), "expected a Cluster", "type", fmt.Sprintf("%T", o)) |
5a8da83
to
6ad9dfa
Compare
/lgtm |
Note: This PR is currently containing the commits #2049 and is blocked on that. I've separated the two so that the new controller and functionality can be reviewed in smaller chunks. If reviewing, ignore anything outside of the
controllers
folder.What this PR does / why we need it:
This adds the controller structure for the Machine HealthChecking controller. It is not currently registered in
main.go
so will not be active even after this is merged, that will be done once all business logic is implemented.So far, all that this does is setup the controller, fetch the instance, check the cluster it refers to exists and isn't paused and labels the
MachineHealthCheck
with the cluster name as per the other types within v1alpha3.Which issue(s) this PR fixes (optional, in
fixes #<issue number>(, fixes #<issue_number>, ...)
format, will close the issue(s) when PR gets merged):Skeleton reconcile logic from tracking issue #1990