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

Codify operator controller #280

Conversation

cynepco3hahue
Copy link

Create the machine-api-operator controller via the code and not via manifest.

  • remove owned-manifests directory
  • remove owned-manifests from Dockerfiles
  • codify the machine-api-operator controller

@openshift-ci-robot openshift-ci-robot added the size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. label Apr 11, 2019
@cynepco3hahue
Copy link
Author

@enxebre @ingvagabund I still need to add some basic unittests.

Copy link
Member

@ingvagabund ingvagabund left a 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.

@cynepco3hahue cynepco3hahue force-pushed the codify_operator_controller branch from 149b0b3 to 6e84034 Compare April 14, 2019 10:52
@cynepco3hahue
Copy link
Author

/retest

1 similar comment
@cynepco3hahue
Copy link
Author

/retest

@ingvagabund
Copy link
Member

@cynepco3hahue can you re-arrange and squash some commits? Plus remove UPSTREAM: <carry>: openshift: Fix the e2e test to work with new deployment commit? You can also squash both commits touching vendored deps.

@cynepco3hahue cynepco3hahue force-pushed the codify_operator_controller branch from 6e84034 to f565de3 Compare April 15, 2019 14:24
@cynepco3hahue
Copy link
Author

@cynepco3hahue can you re-arrange and squash some commits? Plus remove UPSTREAM: <carry>: openshift: Fix the e2e test to work with new deployment commit? You can also squash both commits touching vendored deps.

@ingvagabund done

@enxebre
Copy link
Member

enxebre commented Apr 16, 2019

/hold

@openshift-ci-robot openshift-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Apr 16, 2019
eventRecorderScheme := runtime.NewScheme()
osconfigv1.Install(eventRecorderScheme)

eventBroadcaster := record.NewBroadcaster()
Copy link
Member

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?

Copy link
Author

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

},
}

_true := true
Copy link
Member

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

Copy link
Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

broken link

Copy link
Author

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,
			},

PriorityClassName: "system-node-critical",
NodeSelector: map[string]string{"node-role.kubernetes.io/master": ""},
SecurityContext: &corev1.PodSecurityContext{
RunAsNonRoot: &_true,
Copy link
Contributor

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
}

Copy link
Author

Choose a reason for hiding this comment

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

done

Copy link
Contributor

@frobware frobware left a 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?

@cynepco3hahue
Copy link
Author

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

@cynepco3hahue cynepco3hahue force-pushed the codify_operator_controller branch from f565de3 to 4063b78 Compare April 16, 2019 08:24
)

var (
knownDate = metav1.Time{Time: time.Date(1985, 06, 03, 0, 0, 0, 0, time.Local)}
Copy link
Member

Choose a reason for hiding this comment

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

where is knownDate used?

Copy link
Author

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

var (
knownDate = metav1.Time{Time: time.Date(1985, 06, 03, 0, 0, 0, 0, time.Local)}
alwaysReady = func() bool { return true }
noTimestamp = metav1.Time{}
Copy link
Member

Choose a reason for hiding this comment

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

where is noTimestamp used?

Copy link
Author

Choose a reason for hiding this comment

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

done


kubeActions := filterInformerActions(f.kubeClient.Actions())
for i, action := range kubeActions {
if len(f.kubeActions) < i+1 {
Copy link
Member

@enxebre enxebre Apr 16, 2019

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?

Copy link
Author

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

@frobware
Copy link
Contributor

Because it gives a more flexible way to update the deployment in the case of different feature gates

For 4.1 do we have this requirement?

@cynepco3hahue
Copy link
Author

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.

@cynepco3hahue cynepco3hahue force-pushed the codify_operator_controller branch from 4063b78 to 2ed32aa Compare April 16, 2019 09:59
@@ -75,6 +81,16 @@ func runStartCmd(cmd *cobra.Command, args []string) {
}

func startControllers(ctx *ControllerContext) error {
Copy link
Member

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.

Copy link
Author

Choose a reason for hiding this comment

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

done

Copy link
Member

Choose a reason for hiding this comment

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

startControllers did not change

Copy link
Author

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

Copy link
Member

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?

Copy link
Author

Choose a reason for hiding this comment

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

done

@cynepco3hahue cynepco3hahue force-pushed the codify_operator_controller branch 2 times, most recently from 2efea56 to c5fde87 Compare April 16, 2019 13:20
@enxebre
Copy link
Member

enxebre commented May 14, 2019

@cynepco3hahue needs rebase

@cynepco3hahue cynepco3hahue force-pushed the codify_operator_controller branch from 41c2e59 to f657b42 Compare May 14, 2019 15:53
@openshift-ci-robot openshift-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label May 14, 2019
@cynepco3hahue
Copy link
Author

@enxebre Rebased, can you take a look please?

featureGateLister: featureGateInformer.Lister(),
}
stopCh := make(<-chan struct{})
optr := newFakeOperator([]runtime.Object{d}, []runtime.Object{infra}, stopCh)
Copy link
Member

@enxebre enxebre May 15, 2019

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?

Copy link
Author

Choose a reason for hiding this comment

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

done

@cynepco3hahue cynepco3hahue force-pushed the codify_operator_controller branch from f657b42 to c346715 Compare May 15, 2019 12:24
@cynepco3hahue
Copy link
Author

/retest

@cynepco3hahue
Copy link
Author

@enxebre Can you please review again?

@enxebre
Copy link
Member

enxebre commented May 15, 2019

can we now get rid of PopulateTemplate?
over all lgtm PTAL @frobware

@cynepco3hahue cynepco3hahue force-pushed the codify_operator_controller branch from c346715 to 5d45918 Compare May 15, 2019 14:45
@cynepco3hahue
Copy link
Author

can we now get rid of PopulateTemplate?

Thanks, missed it.

TolerationSeconds: pointer.Int64Ptr(120),
},
{
Key: "node.alpha.kubernetes.io/unreachable",
Copy link
Member

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"

Copy link
Author

Choose a reason for hiding this comment

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

true, thanks

Operator: corev1.TolerationOpExists,
},
{
Key: "node.alpha.kubernetes.io/not-ready",
Copy link
Member

@enxebre enxebre May 16, 2019

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"?

Copy link
Author

Choose a reason for hiding this comment

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

true, thanks

@cynepco3hahue cynepco3hahue force-pushed the codify_operator_controller branch from 5d45918 to 2dc673a Compare May 16, 2019 07:38
}

err = optr.sync("test-key")
if !tc.expectedNoop {
Copy link
Member

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?

Copy link
Author

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

@ingvagabund
Copy link
Member

/approve

@openshift-ci-robot
Copy link
Contributor

[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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci-robot openshift-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label May 17, 2019
NodeSelector: map[string]string{"node-role.kubernetes.io/master": ""},
SecurityContext: &corev1.PodSecurityContext{
RunAsNonRoot: pointer.BoolPtr(true),
RunAsUser: &user,
Copy link
Contributor

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().

Copy link
Author

Choose a reason for hiding this comment

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

done

Copy link
Contributor

@frobware frobware left a 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.

@cynepco3hahue cynepco3hahue force-pushed the codify_operator_controller branch from 2dc673a to 2dec0f6 Compare May 26, 2019 08:55
@cynepco3hahue
Copy link
Author

/retest

@openshift-ci-robot
Copy link
Contributor

openshift-ci-robot commented May 26, 2019

@cynepco3hahue: The following test failed, say /retest to rerun them all:

Test name Commit Details Rerun command
ci/prow/actuator-pkg-staleness 2dec0f6 link /test actuator-pkg-staleness

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
Copy link
Member

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

Copy link
Author

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

Copy link
Member

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
})

Copy link
Member

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

@enxebre
Copy link
Member

enxebre commented May 27, 2019

/lgtm

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label May 27, 2019
@openshift-merge-robot openshift-merge-robot merged commit 5cba6ea into openshift:master May 27, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
4.2 approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants