Skip to content

Commit

Permalink
Update CAPI version in go.mod
Browse files Browse the repository at this point in the history
This is to ensure newer versions of interfaces from SharedIndexInformers
don't cause compile failures.

Update go version to v1.22 becasue cmp.Or is only available in go v1.22

update prism-go-client
  • Loading branch information
thunderboltsid committed May 7, 2024
1 parent 36bea0e commit d879fcc
Show file tree
Hide file tree
Showing 25 changed files with 1,340 additions and 275 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/build-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,14 @@ jobs:
- name: Setup Go
uses: actions/setup-go@v4
with:
go-version: "1.21"
go-version: "^1.22"

- name: Test build
run: make manifests generate fmt vet build

- name: Lint
run: make lint

- name: Run unit tests
run: make unit-test

Expand Down
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ PLATFORMS_E2E ?= linux/amd64
KIND_CLUSTER_NAME ?= capi-test

# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
ENVTEST_K8S_VERSION = 1.23
ENVTEST_K8S_VERSION = 1.26

#
# Directories.
Expand Down Expand Up @@ -365,7 +365,7 @@ GOTESTPKGS = $(shell go list ./... | grep -v /mocks | grep -v /templates)
.PHONY: unit-test
unit-test: setup-envtest ## Run unit tests.
ifeq ($(EXPORT_RESULT), true)
GO111MODULE=off $(GOGET) -u github.com/jstemmer/go-junit-report
$(GOCMD) install github.com/jstemmer/go-junit-report
$(eval OUTPUT_OPTIONS = | go-junit-report -set-exit-code > junit-report.xml)
endif
KUBEBUILDER_ASSETS="$(shell $(SETUP_ENVTEST) use $(ENVTEST_K8S_VERSION) --arch=amd64 -p path)" $(GOTEST) $(GOTESTPKGS) $(OUTPUT_OPTIONS)
Expand All @@ -375,8 +375,8 @@ coverage: setup-envtest ## Run the tests of the project and export the coverage
KUBEBUILDER_ASSETS="$(shell $(SETUP_ENVTEST) use $(ENVTEST_K8S_VERSION) --arch=amd64 -p path)" $(GOTEST) -cover -covermode=count -coverprofile=profile.cov $(GOTESTPKGS)
$(GOTOOL) cover -func profile.cov
ifeq ($(EXPORT_RESULT), true)
GO111MODULE=off $(GOGET) -u github.com/AlekSi/gocov-xml
GO111MODULE=off $(GOGET) -u github.com/axw/gocov/gocov
$(GOCMD) install github.com/AlekSi/gocov-xml
$(GOCMD) install github.com/axw/gocov/gocov
gocov convert profile.cov | gocov-xml > coverage.xml
endif

Expand Down
2 changes: 1 addition & 1 deletion api/v1alpha4/nutanixcluster_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package v1alpha4
import (
infrav1beta1 "github.com/nutanix-cloud-native/cluster-api-provider-nutanix/api/v1beta1"
apiconversion "k8s.io/apimachinery/pkg/conversion"
capiv1alpha4 "sigs.k8s.io/cluster-api/api/v1alpha4"
capiv1alpha4 "sigs.k8s.io/cluster-api/api/v1alpha4" //nolint:staticcheck // we know v1alpha4 is deprecated: release-v1.2 branch is not an active development branch
capiv1beta1 "sigs.k8s.io/cluster-api/api/v1beta1"
"sigs.k8s.io/controller-runtime/pkg/conversion"
)
Expand Down
2 changes: 1 addition & 1 deletion api/v1alpha4/nutanixcluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package v1alpha4
import (
credentialTypes "github.com/nutanix-cloud-native/prism-go-client/environment/credentials"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
capiv1 "sigs.k8s.io/cluster-api/api/v1alpha4"
capiv1 "sigs.k8s.io/cluster-api/api/v1alpha4" //nolint:staticcheck // we know v1alpha4 is deprecated: release-v1.2 branch is not an active development branch
"sigs.k8s.io/cluster-api/errors"
)

Expand Down
2 changes: 1 addition & 1 deletion api/v1alpha4/nutanixmachine_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
capiv1 "sigs.k8s.io/cluster-api/api/v1alpha4"
capiv1 "sigs.k8s.io/cluster-api/api/v1alpha4" //nolint:staticcheck // we know v1alpha4 is deprecated: release-v1.2 branch is not an active development branch
"sigs.k8s.io/cluster-api/errors"
)

Expand Down
2 changes: 1 addition & 1 deletion api/v1alpha4/nutanixmachinetemplate_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package v1alpha4
import (
infrav1beta1 "github.com/nutanix-cloud-native/cluster-api-provider-nutanix/api/v1beta1"
apiconversion "k8s.io/apimachinery/pkg/conversion"
capiv1alpha4 "sigs.k8s.io/cluster-api/api/v1alpha4"
capiv1alpha4 "sigs.k8s.io/cluster-api/api/v1alpha4" //nolint:staticcheck // we know v1alpha4 is deprecated: release-v1.2 branch is not an active development branch
capiv1beta1 "sigs.k8s.io/cluster-api/api/v1beta1"
utilconversion "sigs.k8s.io/cluster-api/util/conversion"
"sigs.k8s.io/controller-runtime/pkg/conversion"
Expand Down
2 changes: 1 addition & 1 deletion api/v1alpha4/nutanixmachinetemplate_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package v1alpha4

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
capiv1 "sigs.k8s.io/cluster-api/api/v1alpha4"
capiv1 "sigs.k8s.io/cluster-api/api/v1alpha4" //nolint:staticcheck // we know v1alpha4 is deprecated: release-v1.2 branch is not an active development branch
)

// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.
Expand Down
19 changes: 14 additions & 5 deletions controllers/nutanixcluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func (r *NutanixClusterReconciler) SetupWithManager(ctx context.Context, mgr ctr

if err = c.Watch(
// Watch the CAPI resource that owns this infrastructure resource.
source.Kind(mgr.GetCache(), &capiv1.Cluster{}),
&source.Kind{Type: &capiv1.Cluster{}},
handler.EnqueueRequestsFromMapFunc(
capiutil.ClusterToInfrastructureMapFunc(
ctx,
Expand Down Expand Up @@ -364,35 +364,44 @@ func (r *NutanixClusterReconciler) reconcileCredentialRef(ctx context.Context, n
Name: credentialRef.Name,
}

log.V(1).Info(fmt.Sprintf("fetching secret for cluster %s", nutanixCluster.Name))
if err := r.Client.Get(ctx, secretKey, secret); err != nil {
errorMsg := fmt.Errorf("error occurred while fetching cluster %s secret for credential ref: %v", nutanixCluster.Name, err)
log.Error(errorMsg, "error occurred fetching cluster")
return errorMsg
}

log.V(1).Info(fmt.Sprintf("fetched secret for cluster %s", nutanixCluster.Name))
// Check if ownerRef is already set on nutanixCluster object
if !capiutil.IsOwnedByObject(secret, nutanixCluster) {
if len(secret.GetOwnerReferences()) > 0 {
return fmt.Errorf("secret for cluster %s already has other owners set", nutanixCluster.Name)
// Check if another nutanixCluster already has set ownerRef. Secret can only be owned by one nutanixCluster object
if capiutil.HasOwner(secret.OwnerReferences, infrav1.GroupVersion.String(), []string{
nutanixCluster.Kind,
}) {
log.V(1).Info(fmt.Sprintf("fetched secret has owner reference for cluster %s: %+v", nutanixCluster.Name, secret.GetOwnerReferences()))
return fmt.Errorf("secret %s already owned by another nutanixCluster object", secret.Name)
}
secret.SetOwnerReferences([]metav1.OwnerReference{{
// Set nutanixCluster ownerRef on the secret
secret.OwnerReferences = capiutil.EnsureOwnerRef(secret.OwnerReferences, metav1.OwnerReference{
APIVersion: infrav1.GroupVersion.String(),
Kind: nutanixCluster.Kind,
UID: nutanixCluster.UID,
Name: nutanixCluster.Name,
}})
})
}

if !ctrlutil.ContainsFinalizer(secret, infrav1.NutanixClusterCredentialFinalizer) {
ctrlutil.AddFinalizer(secret, infrav1.NutanixClusterCredentialFinalizer)
}

log.V(1).Info(fmt.Sprintf("updating secret for cluster %s", nutanixCluster.Name))
err = r.Client.Update(ctx, secret)
if err != nil {
errorMsg := fmt.Errorf("failed to update secret for cluster %s: %v", nutanixCluster.Name, err)
log.Error(errorMsg, "failed to update secret")
return errorMsg
}
log.V(1).Info(fmt.Sprintf("updated secret for cluster %s", nutanixCluster.Name))

return nil
}
Expand Down
7 changes: 5 additions & 2 deletions controllers/nutanixcluster_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ func TestNutanixClusterReconciler(t *testing.T) {
g := NewWithT(t)

_ = Describe("NutanixClusterReconciler", func() {
const (
// To be replaced with capiv1.ClusterKind
clusterKind = "Cluster"
)
var (
ntnxCluster *infrav1.NutanixCluster
ctx context.Context
Expand Down Expand Up @@ -276,7 +280,7 @@ func TestNutanixClusterReconciler(t *testing.T) {
ntnxSecret.OwnerReferences = []metav1.OwnerReference{
{
APIVersion: capiv1.GroupVersion.String(),
Kind: capiv1.ClusterKind,
Kind: clusterKind,
UID: ntnxCluster.UID,
Name: r,
},
Expand All @@ -296,7 +300,6 @@ func TestNutanixClusterReconciler(t *testing.T) {

// Check if secret is owned by the NutanixCluster
g.Expect(capiutil.IsOwnedByObject(ntnxSecret, ntnxCluster)).To(BeTrue())

g.Expect(len(ntnxSecret.OwnerReferences)).To(Equal(2))
})
It("should error if secret does not exist", func() {
Expand Down
8 changes: 5 additions & 3 deletions controllers/nutanixmachine_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import (
"strings"
"time"

"sigs.k8s.io/controller-runtime/pkg/source"

"github.com/google/uuid"
"github.com/nutanix-cloud-native/prism-go-client/utils"
prismclientv3 "github.com/nutanix-cloud-native/prism-go-client/v3"
Expand Down Expand Up @@ -104,21 +106,21 @@ func (r *NutanixMachineReconciler) SetupWithManager(ctx context.Context, mgr ctr
For(&infrav1.NutanixMachine{}).
// Watch the CAPI resource that owns this infrastructure resource.
Watches(
&capiv1.Machine{},
&source.Kind{Type: &capiv1.Machine{}},
handler.EnqueueRequestsFromMapFunc(
capiutil.MachineToInfrastructureMapFunc(
infrav1.GroupVersion.WithKind("NutanixMachine"))),
).
Watches(
&infrav1.NutanixCluster{},
&source.Kind{Type: &infrav1.NutanixCluster{}},
handler.EnqueueRequestsFromMapFunc(r.mapNutanixClusterToNutanixMachines(ctx)),
).
WithOptions(controller.Options{MaxConcurrentReconciles: r.controllerConfig.MaxConcurrentReconciles}).
Complete(r)
}

func (r *NutanixMachineReconciler) mapNutanixClusterToNutanixMachines(ctx context.Context) handler.MapFunc {
return func(ctx context.Context, o client.Object) []ctrl.Request {
return func(o client.Object) []ctrl.Request {
log := ctrl.LoggerFrom(ctx)
nutanixCluster, ok := o.(*infrav1.NutanixCluster)
if !ok {
Expand Down
87 changes: 44 additions & 43 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
module github.com/nutanix-cloud-native/cluster-api-provider-nutanix

go 1.21
go 1.22

require (
github.com/AlekSi/gocov-xml v1.1.0
github.com/blang/semver v3.5.1+incompatible
github.com/go-logr/logr v1.4.1
github.com/golang/mock v1.6.0
github.com/google/uuid v1.3.1
github.com/jstemmer/go-junit-report v1.0.0
github.com/nutanix-cloud-native/prism-go-client v0.4.0
github.com/onsi/ginkgo/v2 v2.17.0
github.com/onsi/gomega v1.30.0
github.com/onsi/ginkgo/v2 v2.17.2
github.com/onsi/gomega v1.33.1
github.com/stretchr/testify v1.8.4
go.uber.org/zap v1.25.0
golang.org/x/time v0.3.0
k8s.io/api v0.28.9
k8s.io/apimachinery v0.28.9
k8s.io/client-go v0.28.9
k8s.io/utils v0.0.0-20240102154912-e7106e64919e
k8s.io/api v0.26.10
k8s.io/apimachinery v0.26.10
k8s.io/client-go v0.26.10
k8s.io/utils v0.0.0-20240502163921-fe8a2dddb1d0
sigs.k8s.io/cluster-api v1.4.7
sigs.k8s.io/cluster-api/test v1.4.7
sigs.k8s.io/controller-runtime v0.14.7
Expand All @@ -32,16 +34,17 @@ require (
github.com/PaesslerAG/gval v1.0.0 // indirect
github.com/PaesslerAG/jsonpath v0.1.1 // indirect
github.com/alessio/shellescape v1.4.1 // indirect
github.com/antlr/antlr4/runtime/Go/antlr/v4 v4.0.0-20230305170008-8188dc5388df // indirect
github.com/antlr/antlr4/runtime/Go/antlr v1.4.10 // indirect
github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a // indirect
github.com/axw/gocov v1.1.0 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/blang/semver/v4 v4.0.0 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/coredns/caddy v1.1.0 // indirect
github.com/coredns/corefile-migration v1.0.21 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/docker/distribution v2.8.2+incompatible // indirect
github.com/docker/docker v24.0.9+incompatible // indirect
github.com/docker/docker v24.0.5+incompatible // indirect
github.com/docker/go-connections v0.4.0 // indirect
github.com/docker/go-units v0.4.0 // indirect
github.com/drone/envsubst/v2 v2.0.0-20210730161058-179042472c46 // indirect
Expand All @@ -53,18 +56,19 @@ require (
github.com/go-openapi/jsonpointer v0.19.6 // indirect
github.com/go-openapi/jsonreference v0.20.2 // indirect
github.com/go-openapi/swag v0.22.3 // indirect
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 // indirect
github.com/go-task/slim-sprig/v3 v3.0.0 // indirect
github.com/gobuffalo/flect v1.0.2 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/google/cel-go v0.16.1 // indirect
github.com/google/gnostic-models v0.6.8 // indirect
github.com/google/cel-go v0.12.7 // indirect
github.com/google/gnostic v0.7.0 // indirect
github.com/google/gnostic-models v0.6.9-0.20230804172637-c7be7c783f49 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/google/go-github/v48 v48.2.0 // indirect
github.com/google/go-querystring v1.1.0 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1 // indirect
github.com/google/pprof v0.0.0-20240424215950-a892ee059fd6 // indirect
github.com/google/safetext v0.0.0-20220905092116-b49f7bc46da2 // indirect
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
Expand All @@ -76,7 +80,7 @@ require (
github.com/magiconair/properties v1.8.7 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattn/go-isatty v0.0.17 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.2 // indirect
github.com/mitchellh/copystructure v1.2.0 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/mitchellh/reflectwalk v1.0.2 // indirect
Expand All @@ -86,53 +90,50 @@ require (
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.0.2 // indirect
github.com/pelletier/go-toml v1.9.5 // indirect
github.com/pelletier/go-toml/v2 v2.0.8 // indirect
github.com/pelletier/go-toml/v2 v2.0.6 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_golang v1.16.0 // indirect
github.com/prometheus/client_model v0.4.0 // indirect
github.com/prometheus/common v0.44.0 // indirect
github.com/prometheus/procfs v0.10.1 // indirect
github.com/prometheus/client_golang v1.14.0 // indirect
github.com/prometheus/client_model v0.3.0 // indirect
github.com/prometheus/common v0.37.0 // indirect
github.com/prometheus/procfs v0.8.0 // indirect
github.com/shopspring/decimal v1.3.1 // indirect
github.com/spf13/afero v1.9.5 // indirect
github.com/spf13/cast v1.5.1 // indirect
github.com/spf13/cobra v1.7.0 // indirect
github.com/spf13/afero v1.9.3 // indirect
github.com/spf13/cast v1.5.0 // indirect
github.com/spf13/cobra v1.6.1 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/spf13/viper v1.16.0 // indirect
github.com/spf13/viper v1.15.0 // indirect
github.com/stoewer/go-strcase v1.2.0 // indirect
github.com/subosito/gotenv v1.4.2 // indirect
github.com/valyala/fastjson v1.6.4 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/crypto v0.21.0 // indirect
golang.org/x/exp v0.0.0-20220722155223-a9213eeb770e // indirect
golang.org/x/net v0.23.0 // indirect
golang.org/x/oauth2 v0.11.0 // indirect
golang.org/x/sync v0.6.0 // indirect
golang.org/x/sys v0.18.0 // indirect
golang.org/x/term v0.18.0 // indirect
go.uber.org/multierr v1.10.0 // indirect
golang.org/x/crypto v0.22.0 // indirect
golang.org/x/net v0.24.0 // indirect
golang.org/x/oauth2 v0.8.0 // indirect
golang.org/x/sys v0.19.0 // indirect
golang.org/x/term v0.19.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/tools v0.17.0 // indirect
gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect
golang.org/x/tools v0.20.0 // indirect
gomodules.xyz/jsonpatch/v2 v2.2.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20230822172742-b8732ec3820d // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230822172742-b8732ec3820d // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20230525234035-dd9d682886f9 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230525234030-28d5490b6b19 // indirect
google.golang.org/protobuf v1.33.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
gotest.tools/v3 v3.5.1 // indirect
k8s.io/apiextensions-apiserver v0.28.9 // indirect
k8s.io/apiserver v0.28.9 // indirect
k8s.io/cluster-bootstrap v0.27.2 // indirect
k8s.io/component-base v0.28.9 // indirect
k8s.io/klog/v2 v2.110.1 // indirect
k8s.io/kube-openapi v0.0.0-20230717233707-2695361300d9 // indirect
k8s.io/apiextensions-apiserver v0.26.10 // indirect
k8s.io/apiserver v0.26.10 // indirect
k8s.io/cluster-bootstrap v0.25.0 // indirect
k8s.io/component-base v0.26.10 // indirect
k8s.io/klog/v2 v2.120.1 // indirect
k8s.io/kube-openapi v0.0.0-20240430033511-f0e62f92d13f // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
sigs.k8s.io/kind v0.20.0 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect
sigs.k8s.io/yaml v1.3.0 // indirect
)

replace golang.org/x/net v0.0.0-20220812174116-3211cb980234 => golang.org/x/net v0.0.0-20220906165146-f3363e06e74c
//replace golang.org/x/net v0.0.0-20220812174116-3211cb980234 => golang.org/x/net v0.0.0-20220906165146-f3363e06e74c
Loading

0 comments on commit d879fcc

Please sign in to comment.