sigs.k8s.io/cluster-api@v1.7.1/api/v1beta1/index/index.go (about)

     1  /*
     2  Copyright 2021 The Kubernetes Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  // Package index provides indexes for the api.
    18  package index
    19  
    20  import (
    21  	"context"
    22  
    23  	ctrl "sigs.k8s.io/controller-runtime"
    24  
    25  	"sigs.k8s.io/cluster-api/feature"
    26  )
    27  
    28  // AddDefaultIndexes registers the default list of indexes.
    29  func AddDefaultIndexes(ctx context.Context, mgr ctrl.Manager) error {
    30  	if err := ByMachineNode(ctx, mgr); err != nil {
    31  		return err
    32  	}
    33  
    34  	if err := ByMachineProviderID(ctx, mgr); err != nil {
    35  		return err
    36  	}
    37  
    38  	if feature.Gates.Enabled(feature.ClusterTopology) {
    39  		if err := ByClusterClassName(ctx, mgr); err != nil {
    40  			return err
    41  		}
    42  	}
    43  
    44  	if feature.Gates.Enabled(feature.MachinePool) {
    45  		if err := ByMachinePoolNode(ctx, mgr); err != nil {
    46  			return err
    47  		}
    48  
    49  		if err := ByMachinePoolProviderID(ctx, mgr); err != nil {
    50  			return err
    51  		}
    52  	}
    53  
    54  	return nil
    55  }