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

🌱 Deprecate DefaultIndex usage and remove where not needed #8855

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion bootstrap/kubeadm/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,6 @@ func setupReconcilers(ctx context.Context, mgr ctrl.Manager) {
remote.ClusterCacheTrackerOptions{
ControllerName: controllerName,
Log: &log,
Indexes: remote.DefaultIndexes,
},
)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion controllers/remote/cluster_cache_healthcheck_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func TestClusterCacheHealthCheck(t *testing.T) {
log := klogr.New()
cct, err = NewClusterCacheTracker(mgr, ClusterCacheTrackerOptions{
Log: &log,
Indexes: DefaultIndexes,
Indexes: []Index{NodeProviderIDIndex},
})
g.Expect(err).NotTo(HaveOccurred())

Expand Down
2 changes: 1 addition & 1 deletion controllers/remote/cluster_cache_tracker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func TestClusterCacheTracker(t *testing.T) {

t.Log("Setting up a ClusterCacheTracker")
cct, err = NewClusterCacheTracker(mgr, ClusterCacheTrackerOptions{
Indexes: DefaultIndexes,
Indexes: []Index{NodeProviderIDIndex},
})
g.Expect(err).NotTo(HaveOccurred())

Expand Down
8 changes: 6 additions & 2 deletions controllers/remote/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,15 @@ type Index struct {
ExtractValue client.IndexerFunc
}

var nodeProviderIDIndex = Index{
// NodeProviderIDIndex is used to index Nodes by ProviderID.
var NodeProviderIDIndex = Index{
Object: &corev1.Node{},
Field: index.NodeProviderIDField,
ExtractValue: index.NodeByProviderID,
}

// DefaultIndexes is the default list of indexes on a ClusterCacheTracker.
var DefaultIndexes = []Index{nodeProviderIDIndex}
//
// 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}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Decided to deprecate this as I think that the naming is possibly one reason it showed up so many places - possibly confused with index.AddDefaultIndexes. As there's only one index here I think it's fine to just explicitly define the array.

3 changes: 1 addition & 2 deletions controlplane/kubeadm/internal/cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,7 @@ func TestGetWorkloadCluster(t *testing.T) {
tracker, err := remote.NewClusterCacheTracker(
env.Manager,
remote.ClusterCacheTrackerOptions{
Log: &log.Log,
Indexes: remote.DefaultIndexes,
Log: &log.Log,
},
)
g.Expect(err).ToNot(HaveOccurred())
Expand Down
1 change: 0 additions & 1 deletion controlplane/kubeadm/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,6 @@ func setupReconcilers(ctx context.Context, mgr ctrl.Manager) {
tracker, err := remote.NewClusterCacheTracker(mgr, remote.ClusterCacheTrackerOptions{
ControllerName: controllerName,
Log: &log,
Indexes: remote.DefaultIndexes,
ClientUncachedObjects: []client.Object{
&corev1.ConfigMap{},
&corev1.Secret{},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ maintainers of providers and consumers of our Go API.
### Deprecation

- API version`v1alpha4` is deprecated and CAPI will stop serving this version in v1.6.
- `sigs.k8s.io/cluster-api/controllers/remote.DefaultIndexex` has been deprecated and will be removed in a future release. Please use `sigs.k8s.io/cluster-api/controllers/external.NodeProviderIDIndex` instead. This index should not be used as a default index and should only be used if a controller is using `index.NodeProviderIDField`.

### Removals

Expand Down
2 changes: 1 addition & 1 deletion internal/controllers/cluster/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func TestMain(m *testing.M) {
mgr,
remote.ClusterCacheTrackerOptions{
Log: &log,
Indexes: remote.DefaultIndexes,
Indexes: []remote.Index{remote.NodeProviderIDIndex},
},
)
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ func TestGetNode(t *testing.T) {

tracker, err := remote.NewClusterCacheTracker(
env.Manager, remote.ClusterCacheTrackerOptions{
Indexes: remote.DefaultIndexes,
Indexes: []remote.Index{remote.NodeProviderIDIndex},
},
)
g.Expect(err).ToNot(HaveOccurred())
Expand Down
2 changes: 1 addition & 1 deletion internal/controllers/machine/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func TestMain(m *testing.M) {
mgr,
remote.ClusterCacheTrackerOptions{
Log: &log,
Indexes: remote.DefaultIndexes,
Indexes: []remote.Index{remote.NodeProviderIDIndex},
},
)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion internal/controllers/machinedeployment/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func TestMain(m *testing.M) {
mgr,
remote.ClusterCacheTrackerOptions{
Log: &log,
Indexes: remote.DefaultIndexes,
Indexes: []remote.Index{remote.NodeProviderIDIndex},
},
)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion internal/controllers/machinehealthcheck/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func TestMain(m *testing.M) {
mgr,
remote.ClusterCacheTrackerOptions{
Log: &log,
Indexes: remote.DefaultIndexes,
Indexes: []remote.Index{remote.NodeProviderIDIndex},
},
)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion internal/controllers/machineset/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func TestMain(m *testing.M) {
mgr,
remote.ClusterCacheTrackerOptions{
Log: &log,
Indexes: remote.DefaultIndexes,
Indexes: []remote.Index{remote.NodeProviderIDIndex},
},
)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ func setupReconcilers(ctx context.Context, mgr ctrl.Manager) {
remote.ClusterCacheTrackerOptions{
ControllerName: controllerName,
Log: &log,
Indexes: remote.DefaultIndexes,
Indexes: []remote.Index{remote.NodeProviderIDIndex},
},
)
if err != nil {
Expand Down
1 change: 0 additions & 1 deletion test/infrastructure/docker/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,6 @@ func setupReconcilers(ctx context.Context, mgr ctrl.Manager) {
remote.ClusterCacheTrackerOptions{
ControllerName: controllerName,
Log: &log,
Indexes: remote.DefaultIndexes,
},
)
if err != nil {
Expand Down
Loading