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 support to auto-update external references #2267

Merged
merged 1 commit into from
Feb 14, 2020

Conversation

vincepri
Copy link
Member

@vincepri vincepri commented Feb 5, 2020

Signed-off-by: Vince Prignano vincepri@vmware.com

What this PR does / why we need it:

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):
Fixes #2140

@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. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Feb 5, 2020
@vincepri
Copy link
Member Author

vincepri commented Feb 5, 2020

Going to add tests once code looks good / this is what we expect

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: vincepri

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 Feb 5, 2020
@@ -182,6 +196,18 @@ func (r *MachineDeploymentReconciler) reconcile(_ context.Context, cluster *clus
return ctrl.Result{}, errors.Errorf("unexpected deployment strategy type: %s", d.Spec.Strategy.Type)
}

func (r *MachineDeploymentReconciler) reconcileExternalReference(ctx context.Context, cluster *clusterv1.Cluster, ref *corev1.ObjectReference) error {
Copy link
Member

Choose a reason for hiding this comment

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

Should we go ahead and set ownerref (non-controller) here for the referenced templates as well? I'm worried that we could potentially delete a template that is still referenced by an existing MachineDeployment if for some reason all of the associated MachineSets are deleted.

docs/book/src/developer/providers/v1alpha2-to-v1alpha3.md Outdated Show resolved Hide resolved
docs/book/src/developer/providers/v1alpha2-to-v1alpha3.md Outdated Show resolved Hide resolved
docs/book/src/developer/providers/v1alpha2-to-v1alpha3.md Outdated Show resolved Hide resolved
"testing"

fuzz "github.com/google/gofuzz"
"github.com/onsi/gomega"
"github.com/pkg/errors"
corev1 "k8s.io/api/core/v1"
"k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1"
Copy link
Member

Choose a reason for hiding this comment

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

This import caused me to double take... not sure why they aren't exposing this out via k8s.io/api/apiextensions/...

Copy link
Contributor

Choose a reason for hiding this comment

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

util/conversion/conversion.go Show resolved Hide resolved
// If there is no label, return early without changing the reference.
supportedVersions, ok := crd.Labels[contract]
if !ok {
return nil
Copy link
Member

Choose a reason for hiding this comment

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

Should we return an error here since we are saying that the labels will be required for v1alpha3+?

Copy link
Member Author

Choose a reason for hiding this comment

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

I was wondering the same if we should treat it as an error, or just let the reference be what it is. I'd prefer erroring out though

Copy link
Member

Choose a reason for hiding this comment

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

I think my preference here is to go ahead and error, since it is breaking the contract we are defining, but I'll defer to @ncdc for final ack/nack :)


// Modify the GroupVersionKind with the new version.
gvk := ref.GroupVersionKind()
gvk.Version = versions[len(versions)-1]
Copy link
Member

Choose a reason for hiding this comment

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

I'm wondering if it would make sense to sort the available versions using https://godoc.org/k8s.io/apimachinery/pkg/version#CompareKubeAwareVersionStrings?

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah nice! I can definitely add this in

@vincepri
Copy link
Member Author

vincepri commented Feb 6, 2020

Tests are gonna fail until kubernetes-sigs/controller-tools#400 is implemented, because that will change the actual base files vs kustomize won't until they're rebuilt. This is of course a possible solution, if we want to go down another path, that's also fine.

The method to check for the CRD versions is also going to be very expensive until we can use kubernetes-sigs/controller-runtime#792

@rudoi
Copy link
Contributor

rudoi commented Feb 14, 2020

@vincepri aside from the controller-tools changes, is this generally good to go, or is there more to do?

It's the last piece of the puzzle!!!

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Feb 14, 2020
@vincepri
Copy link
Member Author

The controller-tools change is needed for tests, I'll try to see if I can do a patch locally though

@k8s-ci-robot k8s-ci-robot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Feb 14, 2020
@vincepri vincepri changed the title [WIP] 🏃 Add support to auto-update external references ⚠️ Add support to auto-update external references Feb 14, 2020
@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 Feb 14, 2020
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Feb 14, 2020
@vincepri
Copy link
Member Author

I might get away with it in tests for now, pushed an update

@vincepri
Copy link
Member Author

This is good to go @detiber @ncdc @rudoi

@vincepri vincepri force-pushed the update-refs-nicely branch 3 times, most recently from 203a7a5 to 7cabe4b Compare February 14, 2020 20:00
Copy link
Member

@fabriziopandini fabriziopandini left a comment

Choose a reason for hiding this comment

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

LGTM for me, two nits not blocking

util/util.go Show resolved Hide resolved
util/util.go Outdated
// optional "alpha" or "beta" strings followed by a minor version (e.g. v1, v2beta1).
// Versions will be sorted based on GA/alpha/beta first and then major and minor
// versions. e.g. v2, v1, v1beta2, v1beta1, v1alpha1.
type KubeVersions []string
Copy link
Member

Choose a reason for hiding this comment

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

KubeAwareVersion?

Copy link
Contributor

Choose a reason for hiding this comment

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

+1, KubeVersions instantly makes me think of KubernetesVersion.

Copy link
Member Author

Choose a reason for hiding this comment

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

Opted for KubeAwareAPIVersions to be extra clear :)

@vincepri vincepri force-pushed the update-refs-nicely branch 2 times, most recently from 22b8f14 to b3ea5b0 Compare February 14, 2020 21:34
@rudoi
Copy link
Contributor

rudoi commented Feb 14, 2020

/retest

This looks good to me, I think the capd e2e has just been having a bad time today.

"sigs.k8s.io/controller-runtime/pkg/conversion"
)

const (
DataAnnotation = "cluster.x-k8s.io/conversion-data"
)

var (
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
var (
const (

Copy link
Member Author

Choose a reason for hiding this comment

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

It can't actually be assigned to a constant because the value comes from a function and can only be resolved at runtime

Signed-off-by: Vince Prignano <vincepri@vmware.com>
@wfernandes
Copy link
Contributor

/lgtm

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

@vincepri: The following test failed, say /retest to rerun all failed tests:

Test name Commit Details Rerun command
pull-cluster-api-capd-e2e 9ad583b link /test pull-cluster-api-capd-e2e

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.

@k8s-ci-robot k8s-ci-robot merged commit 4fd4c7f into kubernetes-sigs:master Feb 14, 2020
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/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Problem with v1alpha2 references
8 participants