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

Migrate to kubebuilder #494

Merged
merged 15 commits into from
Oct 4, 2018
Merged

Conversation

pwittrock
Copy link

This PR is a WIP for migrating from apiserver-builder (aggregation based) to kubebuilder (CRD based). As a consequence of differences in the design philosophies a number of structural changes are made:

  • Switch from code-generation clients to a dynamic client
  • Remove manually working with informers / listers - replace with first class support for watch-reconcile
  • Decompose the Machine-Node bi-Controller into 2 separate Controllers: Node and Machine
  • Introduction of Manager as mechanism for injecting dependencies instead of "Init" functions called from generated code
  • Deletion of lost of generated code. Replace with small amount of scaffolded code (doesn't need to be regenerated).

@k8s-ci-robot k8s-ci-robot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Sep 7, 2018
@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Sep 7, 2018
@roberthbailey roberthbailey changed the title WIP: DO NOT MERGE: Migrate to kubebuilder Migrate to kubebuilder Sep 27, 2018
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Sep 27, 2018
@roberthbailey
Copy link
Contributor

I've removing WIP from this PR. The tests all pass locally for me and I am able to stand up a cluster on gce using clusterctl with this change. I need to figure out how to get prow configured to run the kubebuilder tests (e.g. have etcd, apiserver, etc. in the path).

It would also be nice to update to go 1.10+ while doing so to re-enable coverage, which works on multiple packages in 1.10 but not in earlier versions. Coverage has temporarily been disabled in the test target.

@pwittrock
Copy link
Author

Tests are passing :)

Copy link

@scruplelesswizard scruplelesswizard left a comment

Choose a reason for hiding this comment

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

cmd/clusterctl/clusterctl binary shouldn't be committed to the repo

This is a quick first pass. Wanted to free up for @xmudrii to continue

CONTRIBUTING.md Outdated
@@ -1,116 +0,0 @@
# Contributing Guidelines

Choose a reason for hiding this comment

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

Was CONTRIBUTING.md intentionally removed, or was this a drive-by in 46b895e?

Copy link
Author

Choose a reason for hiding this comment

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

I think it was an artifact of the commits. I can probably clean that up if you like. It looks like there aren't any changes to that file in the PR as a whole. https://github.com/kubernetes-sigs/cluster-api/pull/494/files

Dockerfile Outdated
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -o manager sigs.k8s.io/cluster-api/cmd/manager

# Copy the controller-manager into a thin image
FROM ubuntu:latest

Choose a reason for hiding this comment

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

We should use debian-base or scratch as the base image

ref: kubernetes/kubernetes#40248 (comment)

Copy link
Author

Choose a reason for hiding this comment

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

I switched to debian:latest. I didn't see debian-base here: https://hub.docker.com/_/debian/. Is this correct?

Dockerfile Outdated
FROM golang:1.10.3 as builder

# Copy in the go src
WORKDIR /go/src/sigs.k8s.io/cluster-api

Choose a reason for hiding this comment

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

/go/ $GOPATH/

Copy link
Author

Choose a reason for hiding this comment

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

Done

LICENSE Outdated
@@ -1,201 +0,0 @@
Apache License

Choose a reason for hiding this comment

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

Was LICENSE intentionally removed, or was this a drive-by?

Copy link
Author

Choose a reason for hiding this comment

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

I think that is an artifact of the commits. It should be back.

closeFn func() error
}

// New creates and returns the address of a Client, the kubeconfig argument is expected to be the string represenattion

Choose a reason for hiding this comment

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

typo
/represenattion/representation/

return nil
}

// NewFromDefaultSearchPath creates and returns the address of a Client, the kubeconfigFile argument is expected to be the path to a

Choose a reason for hiding this comment

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

/Client, the kubeconfigFile/Client. The kubeconfigFile/

Copy link
Author

Choose a reason for hiding this comment

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

Done

}, nil
}

// Frees resources associated with the cluster client

Choose a reason for hiding this comment

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

/Frees/Close frees/

Copy link
Author

Choose a reason for hiding this comment

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

Done

}

// Deprecated API. Please do not extend or use.
func (c *client) GetClusterObjects() ([]*clusterv1.Cluster, error) {

Choose a reason for hiding this comment

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

If the client isn't backwards compatible, maybe this is a good time to drop the deprecated APIs?

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

@xmudrii xmudrii left a comment

Choose a reason for hiding this comment

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

Review in progress, but here are initial findings.

Some other nits:

  • cmd/clusterctl/clusterctl - binary file, should probably be deleted
  • cmd/clusterctl/CONTRIBUTING.md - do we need this CONTRIBUTING.md here?
  • cmd/clusterctl/README.md - to be checked should links be updated

Makefile Outdated
$$GOPATH/bin/conversion-gen -i ./pkg/apis/cluster/v1alpha1/ -O zz_generated.conversion --go-header-file boilerplate.go.txt
# Deploy controller in the configured Kubernetes cluster in ~/.kube/config
deploy: manifests
kubectl apply -f config/crds
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 line could be replaced by deploy: manifests install.

Copy link
Contributor

Choose a reason for hiding this comment

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

I am not sure the CRDs need to be installed separately since they are referenced by config/default/kustomization.yaml. Am I missing something?

Copy link
Author

Choose a reason for hiding this comment

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

No. That can probably just be deleted.

package clientcmd

import (
"fmt"
Copy link
Member

Choose a reason for hiding this comment

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

Nit(goimports): probably a new line here

Copy link
Author

Choose a reason for hiding this comment

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

Obsolete

"sigs.k8s.io/cluster-api/cmd/clusterctl/clientcmd"
)

// Can create cluster clients
Copy link
Member

Choose a reason for hiding this comment

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

Nit(lint): could be Factory can...

Copy link
Author

Choose a reason for hiding this comment

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

Done

"sigs.k8s.io/cluster-api/pkg/apis/cluster/common"
)

const ClusterFinalizer string = "cluster.cluster.k8s.io"
const ClusterFinalizer = "cluster.cluster.k8s.io"
Copy link
Member

Choose a reason for hiding this comment

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

Question: should this be cluster.cluster.k8s.io or clusters.cluster.k8s.io? I've seen that CRDs are named plural, but should plural name be used here as well?

Copy link
Author

Choose a reason for hiding this comment

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

@xmudrii Good question. Since this wasn't something changed by this PR and this PR has a lot of changes, perhaps it can be opened in a separate thread or issue.

)

// Finalizer is set on PreareForCreate callback
const MachineFinalizer string = "machine.cluster.k8s.io"
const MachineFinalizer = "machine.cluster.k8s.io"
Copy link
Member

Choose a reason for hiding this comment

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

Question: Same as for cluster/clusters, should this be machines.cluster.k8s.io?

Copy link
Author

Choose a reason for hiding this comment

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

Ack

@pwittrock
Copy link
Author

@xmudrii Thanks for the comments.

@pwittrock
Copy link
Author

FYI: I restructured the commits and re-pushed so that it is easier to review.

@tamalsaha
Copy link

Any plans to use 1.12 instead of ancient 1.10 version at this point?

@@ -128,15 +122,16 @@ type MachineStatus struct {
// can be added as events to the Machine object and/or logged in the
Copy link
Author

Choose a reason for hiding this comment

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

Done

@@ -128,9 +124,7 @@ type MachineSetStatus struct {
ErrorMessage *string `json:"errorMessage,omitempty"`

Choose a reason for hiding this comment

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

typo
/reconcilation/reconciliation/

Copy link
Author

Choose a reason for hiding this comment

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

Done

}

// newRestConfigForKubeconfig creates a rest.Config for a given kubeconfig string.
func newRestConfigForKubeconfig(kubeconfig string) (*rest.Config, error) {
Copy link

@scruplelesswizard scruplelesswizard Sep 28, 2018

Choose a reason for hiding this comment

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

lint: deadcode
It appears this isn't used anywhere in the package. Is this intentional?

Copy link
Author

Choose a reason for hiding this comment

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

Done

"sigs.k8s.io/controller-runtime/pkg/handler"
"sigs.k8s.io/controller-runtime/pkg/manager"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
"sigs.k8s.io/controller-runtime/pkg/source"
)

const requeueAfterWhenQueueAbsent = 1 * time.Second
Copy link

@scruplelesswizard scruplelesswizard Sep 28, 2018

Choose a reason for hiding this comment

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

lint: deadcode

Looks like the patch from #504 was dropped (as intended) without removing the const

Copy link
Author

Choose a reason for hiding this comment

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

Done

@scruplelesswizard
Copy link

Sorry for the late comments, wifi was out on the train. If these have already been fixed please ignore.

@pwittrock
Copy link
Author

Any plans to use 1.12 instead of ancient 1.10 version at this point?

Are you asking about the cluster that gets created, or the codebase the apis are built on? This is using the 1.11.0 : version = "kubernetes-1.11.0" version of the kubernetes libs.

@pwittrock
Copy link
Author

@chaosaffe Thanks for the first pass. I've addressed a few of the comments, but not all.

@@ -298,59 +297,29 @@ func (d *ClusterDeployer) saveProviderComponentsToCluster(factory ProviderCompon
}

func (d *ClusterDeployer) applyClusterAPIStack(client clusterclient.Client, namespace string) error {
glog.Info("Applying Cluster API APIServer")
Copy link
Author

Choose a reason for hiding this comment

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

Deleted because we no longer setup an aggregated apiserver

@liztio
Copy link
Contributor

liztio commented Sep 28, 2018

What's the thinking behind removing the Bazel build infrastructure?

Copy link
Member

@xmudrii xmudrii left a comment

Choose a reason for hiding this comment

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

I've went through some commits again and everything seems reasonable. Looks very well done, no more comments from my side 👍

@roberthbailey
Copy link
Contributor

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Oct 4, 2018
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: pwittrock, roberthbailey

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

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Oct 4, 2018
@k8s-ci-robot k8s-ci-robot merged commit 80129c0 into kubernetes-sigs:master Oct 4, 2018
@pwittrock
Copy link
Author

Woot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.