Skip to content

Commit 0737286

Browse files
authored
refactor: Consistently import CAPI v1beta1 package as clusterv1 alias (#518)
Pulling this change out from #514.
1 parent cb27aca commit 0737286

File tree

18 files changed

+76
-70
lines changed

18 files changed

+76
-70
lines changed

.golangci.yml

+6
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ linters:
3030
- gosimple
3131
- govet
3232
- ineffassign
33+
- importas
3334
- lll
3435
- misspell
3536
- nolintlint
@@ -85,6 +86,11 @@ linters-settings:
8586
dot-import-whitelist:
8687
- github.com/onsi/ginkgo/v2
8788
- github.com/onsi/gomega
89+
importas:
90+
no-unaliased: false
91+
alias:
92+
- pkg: "sigs.k8s.io/cluster-api/api/v1beta1"
93+
alias: clusterv1
8894

8995
issues:
9096
exclude-rules:

cmd/main.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import (
1717
logsv1 "k8s.io/component-base/logs/api/v1"
1818
"k8s.io/component-base/version/verflag"
1919
"k8s.io/klog/v2"
20-
capiv1 "sigs.k8s.io/cluster-api/api/v1beta1"
20+
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
2121
crsv1 "sigs.k8s.io/cluster-api/exp/addons/api/v1beta1"
2222
ctrl "sigs.k8s.io/controller-runtime"
2323
"sigs.k8s.io/controller-runtime/pkg/healthz"
@@ -47,7 +47,7 @@ func main() {
4747
clientScheme := runtime.NewScheme()
4848
utilruntime.Must(clientgoscheme.AddToScheme(clientScheme))
4949
utilruntime.Must(crsv1.AddToScheme(clientScheme))
50-
utilruntime.Must(capiv1.AddToScheme(clientScheme))
50+
utilruntime.Must(clusterv1.AddToScheme(clientScheme))
5151
utilruntime.Must(caaphv1.AddToScheme(clientScheme))
5252

5353
mgrOptions := &ctrl.Options{

common/pkg/capi/apis/schemes.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ package apis
66
import (
77
"k8s.io/apimachinery/pkg/runtime"
88
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
9-
capiv1 "sigs.k8s.io/cluster-api/api/v1beta1"
9+
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
1010
bootstrapv1 "sigs.k8s.io/cluster-api/bootstrap/kubeadm/api/v1beta1"
1111
controlplanev1 "sigs.k8s.io/cluster-api/controlplane/kubeadm/api/v1beta1"
1212
capdv1 "sigs.k8s.io/cluster-api/test/infrastructure/docker/api/v1beta1"
@@ -25,7 +25,7 @@ func CAPIRegisterFuncs() []func(*runtime.Scheme) error {
2525
return []func(*runtime.Scheme) error{
2626
bootstrapv1.AddToScheme,
2727
controlplanev1.AddToScheme,
28-
capiv1.AddToScheme,
28+
clusterv1.AddToScheme,
2929
}
3030
}
3131

common/pkg/capi/clustertopology/handlers/helpers.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
package handlers
55

66
import (
7-
capiv1 "sigs.k8s.io/cluster-api/api/v1beta1"
7+
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
88
runtimehooksv1 "sigs.k8s.io/cluster-api/exp/runtime/hooks/api/v1alpha1"
99
"sigs.k8s.io/controller-runtime/pkg/client"
1010
)
@@ -13,7 +13,7 @@ func ClusterKeyFromReq(req *runtimehooksv1.GeneratePatchesRequest) client.Object
1313
for i := range req.Items {
1414
item := req.Items[i]
1515
if item.HolderReference.Kind == "Cluster" &&
16-
item.HolderReference.APIVersion == capiv1.GroupVersion.String() {
16+
item.HolderReference.APIVersion == clusterv1.GroupVersion.String() {
1717
return client.ObjectKey{
1818
Namespace: item.HolderReference.Namespace,
1919
Name: item.HolderReference.Name,

common/pkg/testutils/capitest/patches.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
gomegatypes "github.com/onsi/gomega/types"
1515
"gomodules.xyz/jsonpatch/v2"
1616
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
17-
capiv1 "sigs.k8s.io/cluster-api/api/v1beta1"
17+
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
1818
runtimehooksv1 "sigs.k8s.io/cluster-api/exp/runtime/hooks/api/v1alpha1"
1919

2020
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/capi/clustertopology/handlers/mutation"
@@ -53,7 +53,7 @@ func ValidateGeneratePatches[T mutation.GeneratePatches](
5353
tt.RequestItem,
5454
{
5555
HolderReference: runtimehooksv1.HolderReference{
56-
APIVersion: capiv1.GroupVersion.String(),
56+
APIVersion: clusterv1.GroupVersion.String(),
5757
Kind: "Cluster",
5858
Namespace: request.Namespace,
5959
Name: request.ClusterName,
@@ -109,7 +109,7 @@ func AssertGeneratePatches[T mutation.GeneratePatches](
109109
tt.RequestItem,
110110
{
111111
HolderReference: runtimehooksv1.HolderReference{
112-
APIVersion: capiv1.GroupVersion.String(),
112+
APIVersion: clusterv1.GroupVersion.String(),
113113
Kind: "Cluster",
114114
Namespace: request.Namespace,
115115
Name: request.ClusterName,

pkg/handlers/generic/lifecycle/clusterautoscaler/strategy_helmaddon.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"github.com/go-logr/logr"
1111
"github.com/spf13/pflag"
1212
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
13-
capiv1 "sigs.k8s.io/cluster-api/api/v1beta1"
13+
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
1414
runtimehooksv1 "sigs.k8s.io/cluster-api/exp/runtime/hooks/api/v1alpha1"
1515
ctrlclient "sigs.k8s.io/controller-runtime/pkg/client"
1616
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
@@ -90,7 +90,7 @@ func (s helmAddonStrategy) apply(
9090
RepoURL: s.helmChart.Repository,
9191
ChartName: s.helmChart.Name,
9292
ClusterSelector: metav1.LabelSelector{
93-
MatchLabels: map[string]string{capiv1.ClusterNameLabel: targetCluster.Name},
93+
MatchLabels: map[string]string{clusterv1.ClusterNameLabel: targetCluster.Name},
9494
},
9595
ReleaseNamespace: req.Cluster.Namespace,
9696
ReleaseName: fmt.Sprintf(defaultHelmReleaseNameTemplate, req.Cluster.Name),

pkg/handlers/generic/lifecycle/cni/calico/strategy_crs.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured/unstructuredscheme"
1717
"k8s.io/apimachinery/pkg/runtime/schema"
1818
"k8s.io/apimachinery/pkg/runtime/serializer/json"
19-
capiv1 "sigs.k8s.io/cluster-api/api/v1beta1"
19+
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
2020
runtimehooksv1 "sigs.k8s.io/cluster-api/exp/runtime/hooks/api/v1alpha1"
2121
ctrlclient "sigs.k8s.io/controller-runtime/pkg/client"
2222

@@ -110,7 +110,7 @@ func (s crsStrategy) apply(
110110

111111
func (s crsStrategy) ensureCNICRSForCluster(
112112
ctx context.Context,
113-
cluster *capiv1.Cluster,
113+
cluster *clusterv1.Cluster,
114114
defaultsNamespace string,
115115
defaultInstallationConfigMapName string,
116116
tigeraConfigMap *corev1.ConfigMap,
@@ -163,7 +163,7 @@ func (s crsStrategy) ensureCNICRSForCluster(
163163

164164
func (s crsStrategy) ensureTigeraOperatorConfigMap(
165165
ctx context.Context,
166-
cluster *capiv1.Cluster,
166+
cluster *clusterv1.Cluster,
167167
defaultsNamespace string,
168168
) (*corev1.ConfigMap, error) {
169169
defaultTigeraOperatorConfigMap := &corev1.ConfigMap{
@@ -196,7 +196,7 @@ func (s crsStrategy) ensureTigeraOperatorConfigMap(
196196
}
197197

198198
func generateTigeraOperatorConfigMap(
199-
defaultTigeraOperatorConfigMap *corev1.ConfigMap, cluster *capiv1.Cluster,
199+
defaultTigeraOperatorConfigMap *corev1.ConfigMap, cluster *clusterv1.Cluster,
200200
) *corev1.ConfigMap {
201201
namespacedTigeraConfigMap := &corev1.ConfigMap{
202202
TypeMeta: metav1.TypeMeta{
@@ -216,7 +216,7 @@ func generateTigeraOperatorConfigMap(
216216

217217
func generateProviderCNIManifestsConfigMap(
218218
installationConfigMap *corev1.ConfigMap,
219-
cluster *capiv1.Cluster,
219+
cluster *clusterv1.Cluster,
220220
) (*corev1.ConfigMap, error) {
221221
defaultManifestStrings := make([]string, 0, len(installationConfigMap.Data))
222222
for _, v := range installationConfigMap.Data {

pkg/handlers/generic/lifecycle/cni/calico/strategy_helmaddon.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
"github.com/spf13/pflag"
1212
corev1 "k8s.io/api/core/v1"
1313
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
14-
capiv1 "sigs.k8s.io/cluster-api/api/v1beta1"
14+
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
1515
runtimehooksv1 "sigs.k8s.io/cluster-api/exp/runtime/hooks/api/v1alpha1"
1616
ctrlclient "sigs.k8s.io/controller-runtime/pkg/client"
1717
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
@@ -93,7 +93,7 @@ func (s helmAddonStrategy) apply(
9393
RepoURL: s.helmChart.Repository,
9494
ChartName: s.helmChart.Name,
9595
ClusterSelector: metav1.LabelSelector{
96-
MatchLabels: map[string]string{capiv1.ClusterNameLabel: req.Cluster.Name},
96+
MatchLabels: map[string]string{clusterv1.ClusterNameLabel: req.Cluster.Name},
9797
},
9898
ReleaseNamespace: defaultTigerOperatorNamespace,
9999
ReleaseName: defaultTigeraOperatorReleaseName,

pkg/handlers/generic/lifecycle/cni/cilium/strategy_helmaddon.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
"github.com/spf13/pflag"
1212
corev1 "k8s.io/api/core/v1"
1313
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
14-
capiv1 "sigs.k8s.io/cluster-api/api/v1beta1"
14+
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
1515
runtimehooksv1 "sigs.k8s.io/cluster-api/exp/runtime/hooks/api/v1alpha1"
1616
ctrlclient "sigs.k8s.io/controller-runtime/pkg/client"
1717
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
@@ -73,7 +73,7 @@ func (s helmAddonStrategy) apply(
7373
RepoURL: s.helmChart.Repository,
7474
ChartName: s.helmChart.Name,
7575
ClusterSelector: metav1.LabelSelector{
76-
MatchLabels: map[string]string{capiv1.ClusterNameLabel: req.Cluster.Name},
76+
MatchLabels: map[string]string{clusterv1.ClusterNameLabel: req.Cluster.Name},
7777
},
7878
ReleaseNamespace: defaultCiliumNamespace,
7979
ReleaseName: defaultCiliumReleaseName,

pkg/handlers/generic/lifecycle/cni/cluster.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ package cni
66
import (
77
"errors"
88

9-
capiv1 "sigs.k8s.io/cluster-api/api/v1beta1"
9+
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
1010
)
1111

1212
var ErrMultiplePodsCIDRBlocks = errors.New("cluster has more than 1 Pods network CIDR blocks")
1313

1414
// PodCIDR will return the Pods network CIDR.
1515
// If not set returns an empty string.
1616
// If more than 1 CIDRBlocks is defined will return an error.
17-
func PodCIDR(cluster *capiv1.Cluster) (string, error) {
17+
func PodCIDR(cluster *clusterv1.Cluster) (string, error) {
1818
var subnets []string
1919
if cluster.Spec.ClusterNetwork != nil &&
2020
cluster.Spec.ClusterNetwork.Pods != nil {

pkg/handlers/generic/lifecycle/nfd/strategy_helmaddon.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
"github.com/spf13/pflag"
1212
corev1 "k8s.io/api/core/v1"
1313
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
14-
capiv1 "sigs.k8s.io/cluster-api/api/v1beta1"
14+
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
1515
runtimehooksv1 "sigs.k8s.io/cluster-api/exp/runtime/hooks/api/v1alpha1"
1616
ctrlclient "sigs.k8s.io/controller-runtime/pkg/client"
1717
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
@@ -80,7 +80,7 @@ image:
8080
RepoURL: s.helmChart.Repository,
8181
ChartName: s.helmChart.Name,
8282
ClusterSelector: metav1.LabelSelector{
83-
MatchLabels: map[string]string{capiv1.ClusterNameLabel: req.Cluster.Name},
83+
MatchLabels: map[string]string{clusterv1.ClusterNameLabel: req.Cluster.Name},
8484
},
8585
ReleaseNamespace: defaultHelmReleaseNamespace,
8686
ReleaseName: defaultHelmReleaseName,

pkg/handlers/generic/mutation/httpproxy/inject.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010

1111
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
1212
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
13-
capiv1 "sigs.k8s.io/cluster-api/api/v1beta1"
13+
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
1414
bootstrapv1 "sigs.k8s.io/cluster-api/bootstrap/kubeadm/api/v1beta1"
1515
controlplanev1 "sigs.k8s.io/cluster-api/controlplane/kubeadm/api/v1beta1"
1616
runtimehooksv1 "sigs.k8s.io/cluster-api/exp/runtime/hooks/api/v1alpha1"
@@ -133,7 +133,7 @@ func (h *httpProxyPatchHandler) detectNoProxy(
133133
ctx context.Context,
134134
clusterKey ctrlclient.ObjectKey,
135135
) ([]string, error) {
136-
cluster := &capiv1.Cluster{}
136+
cluster := &clusterv1.Cluster{}
137137
if err := h.client.Get(ctx, clusterKey, cluster); err != nil {
138138
return nil, err
139139
}
@@ -144,7 +144,7 @@ func (h *httpProxyPatchHandler) detectNoProxy(
144144
// generateNoProxy creates default NO_PROXY values that should be applied on cluster
145145
// in any environment and are preventing the use of proxy for cluster internal
146146
// networking.
147-
func generateNoProxy(cluster *capiv1.Cluster) []string {
147+
func generateNoProxy(cluster *clusterv1.Cluster) []string {
148148
noProxy := []string{
149149
"localhost",
150150
"127.0.0.1",

0 commit comments

Comments
 (0)