Skip to content

refactor: Consistently import CAPI v1beta1 package as clusterv1 alias #518

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

Merged
merged 1 commit into from
Apr 16, 2024
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
6 changes: 6 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ linters:
- gosimple
- govet
- ineffassign
- importas
- lll
- misspell
- nolintlint
Expand Down Expand Up @@ -85,6 +86,11 @@ linters-settings:
dot-import-whitelist:
- github.com/onsi/ginkgo/v2
- github.com/onsi/gomega
importas:
no-unaliased: false
alias:
- pkg: "sigs.k8s.io/cluster-api/api/v1beta1"
alias: clusterv1

issues:
exclude-rules:
Expand Down
4 changes: 2 additions & 2 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
logsv1 "k8s.io/component-base/logs/api/v1"
"k8s.io/component-base/version/verflag"
"k8s.io/klog/v2"
capiv1 "sigs.k8s.io/cluster-api/api/v1beta1"
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
crsv1 "sigs.k8s.io/cluster-api/exp/addons/api/v1beta1"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/healthz"
Expand Down Expand Up @@ -47,7 +47,7 @@ func main() {
clientScheme := runtime.NewScheme()
utilruntime.Must(clientgoscheme.AddToScheme(clientScheme))
utilruntime.Must(crsv1.AddToScheme(clientScheme))
utilruntime.Must(capiv1.AddToScheme(clientScheme))
utilruntime.Must(clusterv1.AddToScheme(clientScheme))
utilruntime.Must(caaphv1.AddToScheme(clientScheme))

mgrOptions := &ctrl.Options{
Expand Down
4 changes: 2 additions & 2 deletions common/pkg/capi/apis/schemes.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package apis
import (
"k8s.io/apimachinery/pkg/runtime"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
capiv1 "sigs.k8s.io/cluster-api/api/v1beta1"
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
bootstrapv1 "sigs.k8s.io/cluster-api/bootstrap/kubeadm/api/v1beta1"
controlplanev1 "sigs.k8s.io/cluster-api/controlplane/kubeadm/api/v1beta1"
capdv1 "sigs.k8s.io/cluster-api/test/infrastructure/docker/api/v1beta1"
Expand All @@ -25,7 +25,7 @@ func CAPIRegisterFuncs() []func(*runtime.Scheme) error {
return []func(*runtime.Scheme) error{
bootstrapv1.AddToScheme,
controlplanev1.AddToScheme,
capiv1.AddToScheme,
clusterv1.AddToScheme,
}
}

Expand Down
4 changes: 2 additions & 2 deletions common/pkg/capi/clustertopology/handlers/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
package handlers

import (
capiv1 "sigs.k8s.io/cluster-api/api/v1beta1"
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
runtimehooksv1 "sigs.k8s.io/cluster-api/exp/runtime/hooks/api/v1alpha1"
"sigs.k8s.io/controller-runtime/pkg/client"
)
Expand All @@ -13,7 +13,7 @@ func ClusterKeyFromReq(req *runtimehooksv1.GeneratePatchesRequest) client.Object
for i := range req.Items {
item := req.Items[i]
if item.HolderReference.Kind == "Cluster" &&
item.HolderReference.APIVersion == capiv1.GroupVersion.String() {
item.HolderReference.APIVersion == clusterv1.GroupVersion.String() {
return client.ObjectKey{
Namespace: item.HolderReference.Namespace,
Name: item.HolderReference.Name,
Expand Down
6 changes: 3 additions & 3 deletions common/pkg/testutils/capitest/patches.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
gomegatypes "github.com/onsi/gomega/types"
"gomodules.xyz/jsonpatch/v2"
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
capiv1 "sigs.k8s.io/cluster-api/api/v1beta1"
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
runtimehooksv1 "sigs.k8s.io/cluster-api/exp/runtime/hooks/api/v1alpha1"

"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/capi/clustertopology/handlers/mutation"
Expand Down Expand Up @@ -53,7 +53,7 @@ func ValidateGeneratePatches[T mutation.GeneratePatches](
tt.RequestItem,
{
HolderReference: runtimehooksv1.HolderReference{
APIVersion: capiv1.GroupVersion.String(),
APIVersion: clusterv1.GroupVersion.String(),
Kind: "Cluster",
Namespace: request.Namespace,
Name: request.ClusterName,
Expand Down Expand Up @@ -109,7 +109,7 @@ func AssertGeneratePatches[T mutation.GeneratePatches](
tt.RequestItem,
{
HolderReference: runtimehooksv1.HolderReference{
APIVersion: capiv1.GroupVersion.String(),
APIVersion: clusterv1.GroupVersion.String(),
Kind: "Cluster",
Namespace: request.Namespace,
Name: request.ClusterName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/go-logr/logr"
"github.com/spf13/pflag"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
capiv1 "sigs.k8s.io/cluster-api/api/v1beta1"
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
runtimehooksv1 "sigs.k8s.io/cluster-api/exp/runtime/hooks/api/v1alpha1"
ctrlclient "sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
Expand Down Expand Up @@ -90,7 +90,7 @@ func (s helmAddonStrategy) apply(
RepoURL: s.helmChart.Repository,
ChartName: s.helmChart.Name,
ClusterSelector: metav1.LabelSelector{
MatchLabels: map[string]string{capiv1.ClusterNameLabel: targetCluster.Name},
MatchLabels: map[string]string{clusterv1.ClusterNameLabel: targetCluster.Name},
},
ReleaseNamespace: req.Cluster.Namespace,
ReleaseName: fmt.Sprintf(defaultHelmReleaseNameTemplate, req.Cluster.Name),
Expand Down
10 changes: 5 additions & 5 deletions pkg/handlers/generic/lifecycle/cni/calico/strategy_crs.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured/unstructuredscheme"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/runtime/serializer/json"
capiv1 "sigs.k8s.io/cluster-api/api/v1beta1"
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
runtimehooksv1 "sigs.k8s.io/cluster-api/exp/runtime/hooks/api/v1alpha1"
ctrlclient "sigs.k8s.io/controller-runtime/pkg/client"

Expand Down Expand Up @@ -110,7 +110,7 @@ func (s crsStrategy) apply(

func (s crsStrategy) ensureCNICRSForCluster(
ctx context.Context,
cluster *capiv1.Cluster,
cluster *clusterv1.Cluster,
defaultsNamespace string,
defaultInstallationConfigMapName string,
tigeraConfigMap *corev1.ConfigMap,
Expand Down Expand Up @@ -163,7 +163,7 @@ func (s crsStrategy) ensureCNICRSForCluster(

func (s crsStrategy) ensureTigeraOperatorConfigMap(
ctx context.Context,
cluster *capiv1.Cluster,
cluster *clusterv1.Cluster,
defaultsNamespace string,
) (*corev1.ConfigMap, error) {
defaultTigeraOperatorConfigMap := &corev1.ConfigMap{
Expand Down Expand Up @@ -196,7 +196,7 @@ func (s crsStrategy) ensureTigeraOperatorConfigMap(
}

func generateTigeraOperatorConfigMap(
defaultTigeraOperatorConfigMap *corev1.ConfigMap, cluster *capiv1.Cluster,
defaultTigeraOperatorConfigMap *corev1.ConfigMap, cluster *clusterv1.Cluster,
) *corev1.ConfigMap {
namespacedTigeraConfigMap := &corev1.ConfigMap{
TypeMeta: metav1.TypeMeta{
Expand All @@ -216,7 +216,7 @@ func generateTigeraOperatorConfigMap(

func generateProviderCNIManifestsConfigMap(
installationConfigMap *corev1.ConfigMap,
cluster *capiv1.Cluster,
cluster *clusterv1.Cluster,
) (*corev1.ConfigMap, error) {
defaultManifestStrings := make([]string, 0, len(installationConfigMap.Data))
for _, v := range installationConfigMap.Data {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/spf13/pflag"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
capiv1 "sigs.k8s.io/cluster-api/api/v1beta1"
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
runtimehooksv1 "sigs.k8s.io/cluster-api/exp/runtime/hooks/api/v1alpha1"
ctrlclient "sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
Expand Down Expand Up @@ -93,7 +93,7 @@ func (s helmAddonStrategy) apply(
RepoURL: s.helmChart.Repository,
ChartName: s.helmChart.Name,
ClusterSelector: metav1.LabelSelector{
MatchLabels: map[string]string{capiv1.ClusterNameLabel: req.Cluster.Name},
MatchLabels: map[string]string{clusterv1.ClusterNameLabel: req.Cluster.Name},
},
ReleaseNamespace: defaultTigerOperatorNamespace,
ReleaseName: defaultTigeraOperatorReleaseName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/spf13/pflag"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
capiv1 "sigs.k8s.io/cluster-api/api/v1beta1"
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
runtimehooksv1 "sigs.k8s.io/cluster-api/exp/runtime/hooks/api/v1alpha1"
ctrlclient "sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
Expand Down Expand Up @@ -73,7 +73,7 @@ func (s helmAddonStrategy) apply(
RepoURL: s.helmChart.Repository,
ChartName: s.helmChart.Name,
ClusterSelector: metav1.LabelSelector{
MatchLabels: map[string]string{capiv1.ClusterNameLabel: req.Cluster.Name},
MatchLabels: map[string]string{clusterv1.ClusterNameLabel: req.Cluster.Name},
},
ReleaseNamespace: defaultCiliumNamespace,
ReleaseName: defaultCiliumReleaseName,
Expand Down
4 changes: 2 additions & 2 deletions pkg/handlers/generic/lifecycle/cni/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ package cni
import (
"errors"

capiv1 "sigs.k8s.io/cluster-api/api/v1beta1"
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
)

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

// PodCIDR will return the Pods network CIDR.
// If not set returns an empty string.
// If more than 1 CIDRBlocks is defined will return an error.
func PodCIDR(cluster *capiv1.Cluster) (string, error) {
func PodCIDR(cluster *clusterv1.Cluster) (string, error) {
var subnets []string
if cluster.Spec.ClusterNetwork != nil &&
cluster.Spec.ClusterNetwork.Pods != nil {
Expand Down
4 changes: 2 additions & 2 deletions pkg/handlers/generic/lifecycle/nfd/strategy_helmaddon.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/spf13/pflag"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
capiv1 "sigs.k8s.io/cluster-api/api/v1beta1"
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
runtimehooksv1 "sigs.k8s.io/cluster-api/exp/runtime/hooks/api/v1alpha1"
ctrlclient "sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
Expand Down Expand Up @@ -80,7 +80,7 @@ image:
RepoURL: s.helmChart.Repository,
ChartName: s.helmChart.Name,
ClusterSelector: metav1.LabelSelector{
MatchLabels: map[string]string{capiv1.ClusterNameLabel: req.Cluster.Name},
MatchLabels: map[string]string{clusterv1.ClusterNameLabel: req.Cluster.Name},
},
ReleaseNamespace: defaultHelmReleaseNamespace,
ReleaseName: defaultHelmReleaseName,
Expand Down
6 changes: 3 additions & 3 deletions pkg/handlers/generic/mutation/httpproxy/inject.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
capiv1 "sigs.k8s.io/cluster-api/api/v1beta1"
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
bootstrapv1 "sigs.k8s.io/cluster-api/bootstrap/kubeadm/api/v1beta1"
controlplanev1 "sigs.k8s.io/cluster-api/controlplane/kubeadm/api/v1beta1"
runtimehooksv1 "sigs.k8s.io/cluster-api/exp/runtime/hooks/api/v1alpha1"
Expand Down Expand Up @@ -133,7 +133,7 @@ func (h *httpProxyPatchHandler) detectNoProxy(
ctx context.Context,
clusterKey ctrlclient.ObjectKey,
) ([]string, error) {
cluster := &capiv1.Cluster{}
cluster := &clusterv1.Cluster{}
if err := h.client.Get(ctx, clusterKey, cluster); err != nil {
return nil, err
}
Expand All @@ -144,7 +144,7 @@ func (h *httpProxyPatchHandler) detectNoProxy(
// generateNoProxy creates default NO_PROXY values that should be applied on cluster
// in any environment and are preventing the use of proxy for cluster internal
// networking.
func generateNoProxy(cluster *capiv1.Cluster) []string {
func generateNoProxy(cluster *clusterv1.Cluster) []string {
noProxy := []string{
"localhost",
"127.0.0.1",
Expand Down
Loading
Loading