-
Notifications
You must be signed in to change notification settings - Fork 214
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
Codify operator controller #280
Codify operator controller #280
Conversation
@enxebre @ingvagabund I still need to add some basic unittests. |
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.
Looks good in overall. For the container naming scheme, both controller
and manager
reflects almost the same semantics. I.e. manager can run one or more controllers. So it supersedes controller
. It's sufficient to just use controller
.
149b0b3
to
6e84034
Compare
/retest |
1 similar comment
/retest |
@cynepco3hahue can you re-arrange and squash some commits? Plus remove |
6e84034
to
f565de3
Compare
@ingvagabund done |
/hold |
cmd/machine-api-operator/start.go
Outdated
eventRecorderScheme := runtime.NewScheme() | ||
osconfigv1.Install(eventRecorderScheme) | ||
|
||
eventBroadcaster := record.NewBroadcaster() |
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 behind moving this here?
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.
to make possible to pass fake recorder under the unittest
pkg/operator/sync.go
Outdated
}, | ||
} | ||
|
||
_true := true |
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.
should be this call runAsNonRoot
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.
broken link
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.
sorry for that, I do not want to pass again the link, because it will be broken on the next push, but you can search for :
SecurityContext: &corev1.PodSecurityContext{
RunAsNonRoot: pointer.BoolPtr(true),
RunAsUser: &user,
},
pkg/operator/sync.go
Outdated
PriorityClassName: "system-node-critical", | ||
NodeSelector: map[string]string{"node-role.kubernetes.io/master": ""}, | ||
SecurityContext: &corev1.PodSecurityContext{ | ||
RunAsNonRoot: &_true, |
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.
Prefer k8s.io/utils/pointer.BoolPtr(true)
.
// BoolPtr returns a pointer to a bool
func BoolPtr(b bool) *bool {
return &b
}
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.
done
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 we see as the advantage of code over a declarative template?
Because it gives a more flexible way to update the deployment in the case of different feature gates |
f565de3
to
4063b78
Compare
pkg/operator/operator_test.go
Outdated
) | ||
|
||
var ( | ||
knownDate = metav1.Time{Time: time.Date(1985, 06, 03, 0, 0, 0, 0, time.Local)} |
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.
where is knownDate
used?
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, missed it, remaining from copy-paste
pkg/operator/operator_test.go
Outdated
var ( | ||
knownDate = metav1.Time{Time: time.Date(1985, 06, 03, 0, 0, 0, 0, time.Local)} | ||
alwaysReady = func() bool { return true } | ||
noTimestamp = metav1.Time{} |
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.
where is noTimestamp
used?
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.
done
pkg/operator/operator_test.go
Outdated
|
||
kubeActions := filterInformerActions(f.kubeClient.Actions()) | ||
for i, action := range kubeActions { | ||
if len(f.kubeActions) < i+1 { |
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.
couldn't we just check once len(kubeActions) !-= len (f.kubeActions)
?
can we call this may be actualKubeActions
for easier readibility?
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 prefer to have to checks under the unittest to make debugging easier, but I will rename variables
For 4.1 do we have this requirement? |
At least from what I understood from @enxebre, it is one of the requirements to introduce new controllers under the machine-api-operator. |
4063b78
to
2ed32aa
Compare
cmd/machine-api-operator/start.go
Outdated
@@ -75,6 +81,16 @@ func runStartCmd(cmd *cobra.Command, args []string) { | |||
} | |||
|
|||
func startControllers(ctx *ControllerContext) 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.
Can you create additional function initRecorder
:
func initRecorder(kubeClient kubernetes.Interface) eventBroadcaster.EventRecorder {
eventRecorderScheme := runtime.NewScheme()
osconfigv1.Install(eventRecorderScheme)
eventBroadcaster := record.NewBroadcaster()
eventBroadcaster.StartLogging(glog.Infof)
eventBroadcaster.StartRecordingToSink(&coreclientsetv1.EventSinkImpl{Interface: kubeClient.CoreV1().Events("")})
return eventBroadcaster.NewRecorder(eventRecorderScheme, v1.EventSource{Component: "machineapioperator"})
}
, change startControllers
implementation into:
func startControllers(ctx *ControllerContext) {
kubeClient := ctx.ClientBuilder.KubeClientOrDie(componentName)
recorder := initRecorder(kubeClient)
go operator.New(
componentNamespace, componentName,
startOpts.imagesFile,
config,
ctx.KubeNamespacedInformerFactory.Apps().V1().Deployments(),
kubeClient,
ctx.ClientBuilder.OpenshiftClientOrDie(componentName),
recorder,
).Run(2, ctx.Stop)
}
and replace:
if err := startControllers(ctrlCtx); err != nil {
glog.Fatalf("error starting controllers: %v", err)
}
with startControllers(ctrlCtx)
?
startControllers
always returns nil
so it does not make sense to check for err != nil
and fail.
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.
done
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.
startControllers
did not change
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.
sorry forgot that I disabled auto-save option
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.
Thank you. Can you also remove error
return type of the function? And remove return nil
?
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.
done
2efea56
to
c5fde87
Compare
@cynepco3hahue needs rebase |
41c2e59
to
f657b42
Compare
@enxebre Rebased, can you take a look please? |
pkg/operator/operator_test.go
Outdated
featureGateLister: featureGateInformer.Lister(), | ||
} | ||
stopCh := make(<-chan struct{}) | ||
optr := newFakeOperator([]runtime.Object{d}, []runtime.Object{infra}, stopCh) |
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 are we passing the deployment here? shouldn't the expected behaviour for it to be created by the fake client on sync?
Also can we validate that for noop providers is not created?
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.
done
f657b42
to
c346715
Compare
/retest |
@enxebre Can you please review again? |
can we now get rid of |
c346715
to
5d45918
Compare
Thanks, missed it. |
pkg/operator/sync.go
Outdated
TolerationSeconds: pointer.Int64Ptr(120), | ||
}, | ||
{ | ||
Key: "node.alpha.kubernetes.io/unreachable", |
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.
shouldn't this be - key: "node.kubernetes.io/not-ready"
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.
true, thanks
pkg/operator/sync.go
Outdated
Operator: corev1.TolerationOpExists, | ||
}, | ||
{ | ||
Key: "node.alpha.kubernetes.io/not-ready", |
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.
shou;ldn't this be key: "node.kubernetes.io/not-ready"
?
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.
true, thanks
5d45918
to
2dc673a
Compare
} | ||
|
||
err = optr.sync("test-key") | ||
if !tc.expectedNoop { |
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.
@enxebre IIRC, you authored this unit test. Is it ok to check for !assert.NoError(t, err, "unexpected sync failure")
no matter what tc.expectedNoop
is set to?
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.
@ingvagabund by the way before the all correct provider's tests failed to deploy, because of missing deployment file, I do not sure if at proper test
/approve |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: ingvagabund The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
pkg/operator/sync.go
Outdated
NodeSelector: map[string]string{"node-role.kubernetes.io/master": ""}, | ||
SecurityContext: &corev1.PodSecurityContext{ | ||
RunAsNonRoot: pointer.BoolPtr(true), | ||
RunAsUser: &user, |
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.
For consistency use pointer.Int64Ptr()
.
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.
done
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.
Just the one nit (#280 (comment)), then LGTM.
2dc673a
to
2dec0f6
Compare
/retest |
@cynepco3hahue: The following test failed, say
Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here. |
// TestOperatorSync_NoOp tests syncing to ensure that the mao reports available | ||
// for platforms that are no-ops. | ||
func TestOperatorSync_NoOp(t *testing.T) { | ||
cases := []struct { | ||
platform configv1.PlatformType |
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.
for future PRs of this size it be nice if we stick to the necessary changes so avoid unnecessary changes for the sake of easier review and smoother workflow
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.
it necessary change, because this unittest worked before for cases when the deployment manifests does not exist, but not we do not depend on the deployment manifest, so I needed to change the test
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.
sorry I meant the import names, e.g configv1 <-> v1
} | ||
return true, nil | ||
}) | ||
|
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: this is worth a comment
/lgtm |
Create the machine-api-operator controller via the code and not via manifest.