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

Add Patch #44

Merged
merged 5 commits into from
Jun 24, 2019
Merged

Add Patch #44

merged 5 commits into from
Jun 24, 2019

Conversation

johnsonj
Copy link
Contributor

@johnsonj johnsonj commented May 8, 2019

Introduce Patch. An Addon can implement the Patchable interface to
accept a set of Patches that are overlaid on the deployment. For
example:

apiVersion: addons.sigs.k8s.io/v1alpha1
kind: Dashboard
metadata:
  name: dashboard-sample
  namespace: kube-system
spec:
  patches:
  - apiVersion: apps/v1beta2
    kind: Deployment
    metadata:
      name: kubernetes-dashboard
      namespace: kube-system
    spec:
      replicas: 5

This patch will change the replica count of the dashboard deployment.
This allows us to provide a break-glass experience for the user to set
configuration options while not requiring every configuration option be
directly exposed on the CRD.

  • It's not clear if we want this on all addons. If so, we should
    graduate it to CommonObject
  • This patching is equivalent/borrowed from kustomize which is not
    currently avaliable as a library.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label May 8, 2019
@johnsonj
Copy link
Contributor Author

johnsonj commented May 8, 2019

/assign @justinsb

@k8s-ci-robot k8s-ci-robot added the sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. label May 8, 2019
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: johnsonj

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 May 8, 2019
@k8s-ci-robot k8s-ci-robot added the size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. label May 8, 2019
@stealthybox
Copy link

Would we want to be able to specify kustomize bases as well?

This would allow you to check your overlays/patches into source control and use overlays that are distributed via channels or the operator's file system.

@johnsonj
Copy link
Contributor Author

That seems interesting @stealthybox!

I think we need to think about if the patches on the CRD are the 'final assembly' or the a higher level (declaration of the intent?). If they're the sort of final instructions, then I think we can keep patch as simple as possible. If they're higher level then should we just completely accept a kustomization field?

I guess we should think about: 'would a user patch the CRD with kustomize' or 'is this CRD an interface into kustomize'?

declarative.WithObjectTransform(addon.TransformApplicationFromStatus),
declarative.WithManagedApplication(srcLabels),
declarative.WithObjectTransform(addon.ApplyPatches),
Copy link
Contributor

Choose a reason for hiding this comment

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

It is going to be weird if the field is there, but the patches don't actually do anything. Maybe this should be the default?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is necessary today because the addons package defines the types, so the declarative package can't extract the patch out. We could workaround this with reflection.

I think what we really need is an AddonsReconciler that applies all (or most?) of these transforms.

for _, gk := range uniqueGroupKind(objects) {
componentGroupKinds = append(componentGroupKinds, map[string]interface{}{"group": gk.Group, "kind": gk.Kind})
}
app.SetNestedSlice(componentGroupKinds, "spec", "componentGroupKinds")
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks good, though why are we doing this? Just to break the dependency on metav1?

Copy link
Contributor Author

@johnsonj johnsonj Jun 14, 2019

Choose a reason for hiding this comment

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

I had to do this because the actual metav1.LabelSelector{} couldn't be deep copied (which is why SetNestedFieldNoCopy) was used. That version didn't properly set these values (but the API server accepted it because the CRD was basically untyped).

@justinsb
Copy link
Contributor

This lgtm.

On the base question, I think we can consider that separately from this PR @stealthybox ? My guess is that the base should be defined by the operator itself - or maybe by a version/channel field in the object, and that we wouldn't expect to allow arbitrary bases. But that's just my guess!

@justinsb
Copy link
Contributor

Thanks @johnsonj

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jun 24, 2019
@johnsonj
Copy link
Contributor Author

/test pull-declarative-test

Introduce Patch. An Addon can implement the Patchable interface to
accept a set of Patches that are overlaid on the deployment. For
example:

apiVersion: addons.sigs.k8s.io/v1alpha1
kind: Dashboard
metadata:
  name: dashboard-sample
  namespace: kube-system
spec:
  patches:
  - apiVersion: apps/v1beta2
    kind: Deployment
    metadata:
      name: kubernetes-dashboard
      namespace: kube-system
    spec:
      replicas: 5

This patch will change the replica count of the dashboard deployment.
This allows us to provide a break-glass experience for the user to set
configuration options while not requiring every configuration option be
directly exposed on the CRD.

- It's not clear if we want this on all addons. If so, we should
  graduate it to CommonObject
- Patch doesn't work if it happens after the addons.TransformApplicationFromStatus
  transform. It raises a DeepCopy error. This is a bug.
- This patching is equivalent/borrowed from kustomize which is not
  currently avaliable as a library.
Change the mutation of Application to be based on map[string]interface{}
instead of using k8s types (like GroupKind). The k8s types do not
properly deserialize.
@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jun 24, 2019
@johnsonj
Copy link
Contributor Author

/test pull-declarative-test

@johnsonj
Copy link
Contributor Author

/ok-to-test

@k8s-ci-robot k8s-ci-robot added the ok-to-test Indicates a non-member PR verified by an org member that is safe to test. label Jun 24, 2019
@johnsonj
Copy link
Contributor Author

/retest

@justinsb
Copy link
Contributor

Thanks for rebasing & fixing tests!

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jun 24, 2019
@k8s-ci-robot k8s-ci-robot merged commit 3bfb586 into kubernetes-sigs:master Jun 24, 2019
johnsonj added a commit to johnsonj/addon-operators that referenced this pull request Jun 24, 2019
johnsonj added a commit to johnsonj/addon-operators that referenced this pull request Jun 24, 2019
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. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. 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.

None yet

4 participants