diff --git a/controllers/noderefutil/providerid.go b/controllers/noderefutil/providerid.go deleted file mode 100644 index ec9bddcbda8a..000000000000 --- a/controllers/noderefutil/providerid.go +++ /dev/null @@ -1,130 +0,0 @@ -/* -Copyright 2019 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// Package noderefutil implements NodeRef utils. -// The ProviderID type is deprecated and unused by Cluster API internally. -// It will be removed entirely in a future release. -package noderefutil - -import ( - "errors" - "regexp" - "strings" -) - -var ( - // ErrEmptyProviderID means that the provider id is empty. - // - // Deprecated: This var is going to be removed in a future release. - ErrEmptyProviderID = errors.New("providerID is empty") - - // ErrInvalidProviderID means that the provider id has an invalid form. - // - // Deprecated: This var is going to be removed in a future release. - ErrInvalidProviderID = errors.New("providerID must be of the form :////") -) - -// ProviderID is a struct representation of a Kubernetes ProviderID. -// Format: cloudProvider://optional/segments/etc/id -// -// Deprecated: This struct is going to be removed in a future release. -type ProviderID struct { - original string - cloudProvider string - id string -} - -/* -- must start with at least one non-colon -- followed by :// -- followed by any number of characters -- must end with a non-slash. -*/ -var providerIDRegex = regexp.MustCompile("^[^:]+://.*[^/]$") - -// NewProviderID parses the input string and returns a new ProviderID. -// -// Deprecated: This constructor is going to be removed in a future release. -func NewProviderID(id string) (*ProviderID, error) { - if id == "" { - return nil, ErrEmptyProviderID - } - - if !providerIDRegex.MatchString(id) { - return nil, ErrInvalidProviderID - } - - colonIndex := strings.Index(id, ":") - cloudProvider := id[0:colonIndex] - - lastSlashIndex := strings.LastIndex(id, "/") - instance := id[lastSlashIndex+1:] - - res := &ProviderID{ - original: id, - cloudProvider: cloudProvider, - id: instance, - } - - if !res.Validate() { - return nil, ErrInvalidProviderID - } - - return res, nil -} - -// CloudProvider returns the cloud provider portion of the ProviderID. -// -// Deprecated: This method is going to be removed in a future release. -func (p *ProviderID) CloudProvider() string { - return p.cloudProvider -} - -// ID returns the identifier portion of the ProviderID. -// -// Deprecated: This method is going to be removed in a future release. -func (p *ProviderID) ID() string { - return p.id -} - -// Equals returns true if this ProviderID string matches another ProviderID string. -// -// Deprecated: This method is going to be removed in a future release. -func (p *ProviderID) Equals(o *ProviderID) bool { - return p.String() == o.String() -} - -// String returns the string representation of this object. -// -// Deprecated: This method is going to be removed in a future release. -func (p ProviderID) String() string { - return p.original -} - -// Validate returns true if the provider id is valid. -// -// Deprecated: This method is going to be removed in a future release. -func (p *ProviderID) Validate() bool { - return p.CloudProvider() != "" && p.ID() != "" -} - -// IndexKey returns the required level of uniqueness -// to represent and index machines uniquely from their node providerID. -// -// Deprecated: This method is going to be removed in a future release. -func (p *ProviderID) IndexKey() string { - return p.String() -} diff --git a/controllers/noderefutil/providerid_test.go b/controllers/noderefutil/providerid_test.go deleted file mode 100644 index 7774fc28078f..000000000000 --- a/controllers/noderefutil/providerid_test.go +++ /dev/null @@ -1,170 +0,0 @@ -/* -Copyright 2019 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// The ProviderID type is deprecated and unused by Cluster API internally. -// It will be removed entirely in a future release. -package noderefutil - -import ( - "testing" - - . "github.com/onsi/gomega" -) - -const aws = "aws" -const azure = "azure" - -func TestNewProviderID(t *testing.T) { - tests := []struct { - name string - input string - expectedID string - }{ - { - name: "2 slashes after colon, one segment", - input: "aws://instance-id", - expectedID: "instance-id", - }, - { - name: "more than 2 slashes after colon, one segment", - input: "aws:////instance-id", - expectedID: "instance-id", - }, - { - name: "multiple filled-in segments (aws format)", - input: "aws:///zone/instance-id", - expectedID: "instance-id", - }, - { - name: "multiple filled-in segments", - input: "aws://bar/baz/instance-id", - expectedID: "instance-id", - }, - } - - for _, tc := range tests { - t.Run(tc.name, func(t *testing.T) { - g := NewWithT(t) - - id, err := NewProviderID(tc.input) - g.Expect(err).ToNot(HaveOccurred()) - g.Expect(id.CloudProvider()).To(Equal(aws)) - g.Expect(id.ID()).To(Equal(tc.expectedID)) - }) - } -} - -func TestInvalidProviderID(t *testing.T) { - testCases := []struct { - name string - input string - err error - }{ - { - name: "empty id", - input: "", - err: ErrEmptyProviderID, - }, - { - name: "only empty segments", - input: "aws:///////", - err: ErrInvalidProviderID, - }, - { - name: "missing cloud provider", - input: "://instance-id", - err: ErrInvalidProviderID, - }, - { - name: "missing cloud provider and colon", - input: "//instance-id", - err: ErrInvalidProviderID, - }, - { - name: "missing cloud provider, colon, one leading slash", - input: "/instance-id", - err: ErrInvalidProviderID, - }, - { - name: "just an id", - input: "instance-id", - err: ErrInvalidProviderID, - }, - } - - for _, test := range testCases { - t.Run(test.name, func(t *testing.T) { - g := NewWithT(t) - - _, err := NewProviderID(test.input) - g.Expect(err).To(MatchError(test.err)) - }) - } -} - -func TestProviderIDEquals(t *testing.T) { - g := NewWithT(t) - - inputAWS1 := "aws:////instance-id1" - parsedAWS1, err := NewProviderID(inputAWS1) - g.Expect(err).ToNot(HaveOccurred()) - g.Expect(parsedAWS1.String()).To(Equal(inputAWS1)) - g.Expect(parsedAWS1.ID()).To(Equal("instance-id1")) - g.Expect(parsedAWS1.CloudProvider()).To(Equal(aws)) - - inputAWS2 := "aws:///us-west-1/instance-id1" - parsedAWS2, err := NewProviderID(inputAWS2) - g.Expect(err).ToNot(HaveOccurred()) - g.Expect(parsedAWS2.String()).To(Equal(inputAWS2)) - g.Expect(parsedAWS2.ID()).To(Equal("instance-id1")) - g.Expect(parsedAWS2.CloudProvider()).To(Equal(aws)) - - // Test for inequality - g.Expect(parsedAWS1.Equals(parsedAWS2)).To(BeFalse()) - - inputAzure1 := "azure:///subscriptions/4920076a-ba9f-11ec-8422-0242ac120002/resourceGroups/default-template/providers/Microsoft.Compute/virtualMachines/default-template-control-plane-fhrvh" - parsedAzure1, err := NewProviderID(inputAzure1) - g.Expect(err).ToNot(HaveOccurred()) - g.Expect(parsedAzure1.String()).To(Equal(inputAzure1)) - g.Expect(parsedAzure1.ID()).To(Equal("default-template-control-plane-fhrvh")) - g.Expect(parsedAzure1.CloudProvider()).To(Equal(azure)) - - inputAzure2 := inputAzure1 - parsedAzure2, err := NewProviderID(inputAzure2) - g.Expect(err).ToNot(HaveOccurred()) - - // Test for equality - g.Expect(parsedAzure1.Equals(parsedAzure2)).To(BeTrue()) - - // Here we ensure that two different ProviderID strings that happen to have the same 'ID' are not equal - // We use Azure VMSS as an example, two different '0' VMs in different pools: k8s-pool1-vmss, and k8s-pool2-vmss - inputAzureVMFromOneVMSS := "azure:///subscriptions/4920076a-ba9f-11ec-8422-0242ac120002/resourceGroups/default-template/providers/Microsoft.Compute/virtualMachineScaleSets/k8s-pool1-vmss/virtualMachines/0" - inputAzureVMFromAnotherVMSS := "azure:///subscriptions/4920076a-ba9f-11ec-8422-0242ac120002/resourceGroups/default-template/providers/Microsoft.Compute/virtualMachineScaleSets/k8s-pool2-vmss/virtualMachines/0" - parsedAzureVMFromOneVMSS, err := NewProviderID(inputAzureVMFromOneVMSS) - g.Expect(err).ToNot(HaveOccurred()) - g.Expect(parsedAzureVMFromOneVMSS.String()).To(Equal(inputAzureVMFromOneVMSS)) - g.Expect(parsedAzureVMFromOneVMSS.ID()).To(Equal("0")) - g.Expect(parsedAzureVMFromOneVMSS.CloudProvider()).To(Equal(azure)) - - parsedAzureVMFromAnotherVMSS, err := NewProviderID(inputAzureVMFromAnotherVMSS) - g.Expect(err).ToNot(HaveOccurred()) - g.Expect(parsedAzureVMFromAnotherVMSS.String()).To(Equal(inputAzureVMFromAnotherVMSS)) - g.Expect(parsedAzureVMFromAnotherVMSS.ID()).To(Equal("0")) - g.Expect(parsedAzureVMFromAnotherVMSS.CloudProvider()).To(Equal(azure)) - - // Test for inequality - g.Expect(parsedAzureVMFromOneVMSS.Equals(parsedAzureVMFromAnotherVMSS)).To(BeFalse()) -} diff --git a/controllers/noderefutil/util.go b/controllers/noderefutil/util.go index d96e25c64bf1..de40751fde4b 100644 --- a/controllers/noderefutil/util.go +++ b/controllers/noderefutil/util.go @@ -14,6 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ +// Package noderefutil implements noderef utilities. package noderefutil import ( diff --git a/controllers/remote/index.go b/controllers/remote/index.go index 1aa02e8f9d92..16a7f5810240 100644 --- a/controllers/remote/index.go +++ b/controllers/remote/index.go @@ -36,9 +36,3 @@ var NodeProviderIDIndex = Index{ Field: index.NodeProviderIDField, ExtractValue: index.NodeByProviderID, } - -// DefaultIndexes is the default list of indexes on a ClusterCacheTracker. -// -// Deprecated: This variable is deprecated and will be removed in a future release of Cluster API. -// Instead please use `[]Index{NodeProviderIDIndex}`. -var DefaultIndexes = []Index{NodeProviderIDIndex} diff --git a/docs/book/src/developer/providers/migrations/v1.5-to-v1.6.md b/docs/book/src/developer/providers/migrations/v1.5-to-v1.6.md index dc32a2ee18e3..99beb7dfb1ab 100644 --- a/docs/book/src/developer/providers/migrations/v1.5-to-v1.6.md +++ b/docs/book/src/developer/providers/migrations/v1.5-to-v1.6.md @@ -22,6 +22,11 @@ maintainers of providers and consumers of our Go API. ### Removals - API version `v1alpha4` is not served in v1.6 (users can enable it manually in case they are lagging behind with deprecation cycles). Important: `v1alpha4` will be completely removed in 1.7. +- The function(s): + - `ClusterToObjectsMapper` is removed, please use `ClusterToTypedObjectsMapper` function instead. + - `Poll` and `PollImmediate` are removed, please use utils from "k8s.io/apimachinery/pkg/util/wait" instead. +- The variable `DefaultIndexes` is removed, please use `[]Index{NodeProviderIDIndex}` +- `ProviderID` type and all related methods/construct have been removed. Please see this [PR](https://github.com/kubernetes-sigs/cluster-api/pull/8577) for a reference. ### API Changes diff --git a/util/retry.go b/util/retry.go index 378476a0bd38..fe87875e07ba 100644 --- a/util/retry.go +++ b/util/retry.go @@ -46,21 +46,3 @@ func Retry(fn wait.ConditionFunc, initialBackoffSec int) error { } return nil } - -// Poll tries a condition func until it returns true, an error, or the timeout -// is reached. -// -// Deprecated: This function has been deprecated and will be removed in a future release. -// Please use utils from "k8s.io/apimachinery/pkg/util/wait" instead. -func Poll(interval, timeout time.Duration, condition wait.ConditionFunc) error { - return wait.Poll(interval, timeout, condition) -} - -// PollImmediate tries a condition func until it returns true, an error, or the timeout -// is reached. -// -// Deprecated: This function has been deprecated and will be removed in a future release. -// Please use utils from "k8s.io/apimachinery/pkg/util/wait" instead. -func PollImmediate(interval, timeout time.Duration, condition wait.ConditionFunc) error { - return wait.PollImmediate(interval, timeout, condition) -} diff --git a/util/util.go b/util/util.go index 93267f160e60..9edcf9123cbd 100644 --- a/util/util.go +++ b/util/util.go @@ -467,56 +467,6 @@ func (k KubeAwareAPIVersions) Less(i, j int) bool { return k8sversion.CompareKubeAwareVersionStrings(k[i], k[j]) < 0 } -// ClusterToObjectsMapper returns a mapper function that gets a cluster and lists all objects for the object passed in -// and returns a list of requests. -// NB: The objects are required to have `clusterv1.ClusterNameLabel` applied. -// -// Deprecated: This function is deprecated and will be removed in a future release, use ClusterToTypedObjectsMapper instead. -// The problem with this function is that it uses UnstructuredList to retrieve objects, with the default client configuration -// this will lead to uncached List calls, which is a major performance issue. -func ClusterToObjectsMapper(c client.Client, ro client.ObjectList, scheme *runtime.Scheme) (handler.MapFunc, error) { - gvk, err := apiutil.GVKForObject(ro, scheme) - if err != nil { - return nil, err - } - - isNamespaced, err := isAPINamespaced(gvk, c.RESTMapper()) - if err != nil { - return nil, err - } - - return func(ctx context.Context, o client.Object) []ctrl.Request { - cluster, ok := o.(*clusterv1.Cluster) - if !ok { - return nil - } - - listOpts := []client.ListOption{ - client.MatchingLabels{ - clusterv1.ClusterNameLabel: cluster.Name, - }, - } - - if isNamespaced { - listOpts = append(listOpts, client.InNamespace(cluster.Namespace)) - } - - list := &unstructured.UnstructuredList{} - list.SetGroupVersionKind(gvk) - if err := c.List(ctx, list, listOpts...); err != nil { - return nil - } - - results := []ctrl.Request{} - for _, obj := range list.Items { - results = append(results, ctrl.Request{ - NamespacedName: client.ObjectKey{Namespace: obj.GetNamespace(), Name: obj.GetName()}, - }) - } - return results - }, nil -} - // ClusterToTypedObjectsMapper returns a mapper function that gets a cluster and lists all objects for the object passed in // and returns a list of requests. // Note: This function uses the passed in typed ObjectList and thus with the default client configuration all list calls