Skip to content
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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ create-management-cluster: $(KUSTOMIZE) $(ENVSUBST) $(KUBECTL) $(KIND) ## Create
./hack/create-custom-cloud-provider-config.sh

# Deploy CAPI
timeout --foreground 300 bash -c "until curl --retry $(CURL_RETRIES) -sSL https://github.com/kubernetes-sigs/cluster-api/releases/download/v1.7.5/cluster-api-components.yaml | $(ENVSUBST) | $(KUBECTL) apply -f -; do sleep 5; done"
timeout --foreground 300 bash -c "until curl --retry $(CURL_RETRIES) -sSL https://github.com/kubernetes-sigs/cluster-api/releases/download/v1.8.1/cluster-api-components.yaml | $(ENVSUBST) | $(KUBECTL) apply -f -; do sleep 5; done"

# Deploy CAAPH
timeout --foreground 300 bash -c "until curl --retry $(CURL_RETRIES) -sSL https://github.com/kubernetes-sigs/cluster-api-addon-provider-helm/releases/download/v0.2.5/addon-components.yaml | $(ENVSUBST) | $(KUBECTL) apply -f -; do sleep 5; done"
Expand Down
2 changes: 1 addition & 1 deletion Tiltfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ settings = {
"deploy_cert_manager": True,
"preload_images_for_kind": True,
"kind_cluster_name": "capz",
"capi_version": "v1.7.5",
"capi_version": "v1.8.1",
"caaph_version": "v0.2.5",
"cert_manager_version": "v1.15.2",
"kubernetes_version": "v1.28.3",
Expand Down
29 changes: 16 additions & 13 deletions api/v1beta1/azuremanagedcluster_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
. "github.com/onsi/gomega"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
utilfeature "k8s.io/component-base/featuregate/testing"
"k8s.io/utils/ptr"
"sigs.k8s.io/cluster-api-provider-azure/feature"
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
capifeature "sigs.k8s.io/cluster-api/feature"
Expand Down Expand Up @@ -135,27 +136,29 @@ func TestAzureManagedCluster_ValidateCreate(t *testing.T) {

func TestAzureManagedCluster_ValidateCreateFailure(t *testing.T) {
tests := []struct {
name string
amc *AzureManagedCluster
deferFunc func()
expectError bool
name string
amc *AzureManagedCluster
featureGateEnabled *bool
expectError bool
}{
{
name: "feature gate explicitly disabled",
amc: getKnownValidAzureManagedCluster(),
deferFunc: utilfeature.SetFeatureGateDuringTest(t, feature.Gates, capifeature.MachinePool, false),
expectError: true,
name: "feature gate explicitly disabled",
amc: getKnownValidAzureManagedCluster(),
featureGateEnabled: ptr.To(false),
expectError: true,
},
{
name: "feature gate implicitly enabled",
amc: getKnownValidAzureManagedCluster(),
deferFunc: func() {},
expectError: false,
name: "feature gate implicitly enabled",
amc: getKnownValidAzureManagedCluster(),
featureGateEnabled: nil,
expectError: false,
},
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
defer tc.deferFunc()
if tc.featureGateEnabled != nil {
defer utilfeature.SetFeatureGateDuringTest(t, feature.Gates, capifeature.MachinePool, *tc.featureGateEnabled)()
}
g := NewWithT(t)
_, err := tc.amc.ValidateCreate()
if tc.expectError {
Expand Down
28 changes: 15 additions & 13 deletions api/v1beta1/azuremanagedcontrolplane_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1662,29 +1662,31 @@ func TestAzureManagedControlPlane_ValidateCreate(t *testing.T) {

func TestAzureManagedControlPlane_ValidateCreateFailure(t *testing.T) {
tests := []struct {
name string
amcp *AzureManagedControlPlane
deferFunc func()
expectError bool
name string
amcp *AzureManagedControlPlane
featureGateEnabled *bool
expectError bool
}{
{
name: "feature gate explicitly disabled",
amcp: getKnownValidAzureManagedControlPlane(),
deferFunc: utilfeature.SetFeatureGateDuringTest(t, feature.Gates, capifeature.MachinePool, false),
expectError: true,
name: "feature gate explicitly disabled",
amcp: getKnownValidAzureManagedControlPlane(),
featureGateEnabled: ptr.To(false),
expectError: true,
},
{
name: "feature gate implicitly enabled",
amcp: getKnownValidAzureManagedControlPlane(),
deferFunc: func() {},
expectError: false,
name: "feature gate implicitly enabled",
amcp: getKnownValidAzureManagedControlPlane(),
featureGateEnabled: nil,
expectError: false,
},
}
client := mockClient{ReturnError: false}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
g := NewWithT(t)
defer tc.deferFunc()
if tc.featureGateEnabled != nil {
defer utilfeature.SetFeatureGateDuringTest(t, feature.Gates, capifeature.MachinePool, *tc.featureGateEnabled)()
}
mcpw := &azureManagedControlPlaneWebhook{
Client: client,
}
Expand Down
28 changes: 15 additions & 13 deletions api/v1beta1/azuremanagedmachinepool_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1307,27 +1307,29 @@ func TestAzureManagedMachinePool_ValidateCreate(t *testing.T) {

func TestAzureManagedMachinePool_ValidateCreateFailure(t *testing.T) {
tests := []struct {
name string
ammp *AzureManagedMachinePool
deferFunc func()
expectError bool
name string
ammp *AzureManagedMachinePool
featureGateEnabled *bool
expectError bool
}{
{
name: "feature gate explicitly disabled",
ammp: getKnownValidAzureManagedMachinePool(),
deferFunc: utilfeature.SetFeatureGateDuringTest(t, feature.Gates, capifeature.MachinePool, false),
expectError: true,
name: "feature gate explicitly disabled",
ammp: getKnownValidAzureManagedMachinePool(),
featureGateEnabled: ptr.To(false),
expectError: true,
},
{
name: "feature gate implicitly enabled",
ammp: getKnownValidAzureManagedMachinePool(),
deferFunc: func() {},
expectError: false,
name: "feature gate implicitly enabled",
ammp: getKnownValidAzureManagedMachinePool(),
featureGateEnabled: nil,
expectError: false,
},
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
defer tc.deferFunc()
if tc.featureGateEnabled != nil {
defer utilfeature.SetFeatureGateDuringTest(t, feature.Gates, capifeature.MachinePool, *tc.featureGateEnabled)()
}
g := NewWithT(t)
mw := &azureManagedMachinePoolWebhook{}
_, err := mw.ValidateCreate(context.Background(), tc.ammp)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,13 @@ spec:
items:
type: string
type: array
x-kubernetes-list-type: atomic
required:
- key
- operator
type: object
type: array
x-kubernetes-list-type: atomic
matchLabels:
additionalProperties:
type: string
Expand Down
4 changes: 2 additions & 2 deletions controllers/azureasomanagedmachinepool_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ func (r *AzureASOManagedMachinePoolReconciler) SetupWithManager(ctx context.Cont
).
Watches(
&expv1.MachinePool{},
handler.EnqueueRequestsFromMapFunc(utilexp.MachinePoolToInfrastructureMapFunc(
infrav1alpha.GroupVersion.WithKind(infrav1alpha.AzureASOManagedMachinePoolKind), log),
handler.EnqueueRequestsFromMapFunc(utilexp.MachinePoolToInfrastructureMapFunc(ctx,
infrav1alpha.GroupVersion.WithKind(infrav1alpha.AzureASOManagedMachinePoolKind)),
),
builder.WithPredicates(
predicates.ResourceHasFilterLabel(log, r.WatchFilterValue),
Expand Down
33 changes: 13 additions & 20 deletions controllers/azurejson_machinetemplate_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ import (
"sigs.k8s.io/cluster-api/util/annotations"
"sigs.k8s.io/cluster-api/util/predicates"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/builder"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/controller"
"sigs.k8s.io/controller-runtime/pkg/handler"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
"sigs.k8s.io/controller-runtime/pkg/source"
)

// AzureJSONTemplateReconciler reconciles Azure json secrets for AzureMachineTemplate objects.
Expand All @@ -65,29 +65,22 @@ func (r *AzureJSONTemplateReconciler) SetupWithManager(ctx context.Context, mgr
return errors.Wrap(err, "failed to create mapper for Cluster to AzureMachineTemplates")
}

c, err := ctrl.NewControllerManagedBy(mgr).
return ctrl.NewControllerManagedBy(mgr).
WithOptions(options).
For(&infrav1.AzureMachineTemplate{}).
WithEventFilter(predicates.ResourceNotPausedAndHasFilterLabel(log, r.WatchFilterValue)).
Owns(&corev1.Secret{}).
Build(r)

if err != nil {
return errors.Wrap(err, "failed to create controller")
}

// Add a watch on Clusters to requeue when the infraRef is set. This is needed because the infraRef is not initially
// set in Clusters created from a ClusterClass.
if err := c.Watch(
source.Kind(mgr.GetCache(), &clusterv1.Cluster{}),
handler.EnqueueRequestsFromMapFunc(azureMachineTemplateMapper),
predicates.ClusterUnpausedAndInfrastructureReady(log),
predicates.ResourceNotPausedAndHasFilterLabel(log, r.WatchFilterValue),
); err != nil {
return errors.Wrap(err, "failed adding a watch for Clusters")
}

return nil
// Add a watch on Clusters to requeue when the infraRef is set. This is needed because the infraRef is not initially
// set in Clusters created from a ClusterClass.
Watches(
&clusterv1.Cluster{},
handler.EnqueueRequestsFromMapFunc(azureMachineTemplateMapper),
builder.WithPredicates(
predicates.ClusterUnpausedAndInfrastructureReady(log),
predicates.ResourceNotPausedAndHasFilterLabel(log, r.WatchFilterValue),
),
).
Complete(r)
}

// Reconcile reconciles Azure json secrets for Azure machine templates.
Expand Down
3 changes: 1 addition & 2 deletions controllers/resource_reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/klog/v2"
infrav1alpha "sigs.k8s.io/cluster-api-provider-azure/api/v1alpha1"
Expand All @@ -48,7 +47,7 @@ type ResourceReconciler struct {
}

type watcher interface {
Watch(log logr.Logger, obj runtime.Object, handler handler.EventHandler, p ...predicate.Predicate) error
Watch(log logr.Logger, obj client.Object, handler handler.EventHandler, p ...predicate.Predicate) error
}

type resourceStatusObject interface {
Expand Down
2 changes: 1 addition & 1 deletion controllers/resource_reconciler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ type FakeWatcher struct {
watching map[string]struct{}
}

func (w *FakeWatcher) Watch(_ logr.Logger, obj runtime.Object, _ handler.EventHandler, _ ...predicate.Predicate) error {
func (w *FakeWatcher) Watch(_ logr.Logger, obj client.Object, _ handler.EventHandler, _ ...predicate.Predicate) error {
if w.watching == nil {
w.watching = make(map[string]struct{})
}
Expand Down
28 changes: 15 additions & 13 deletions exp/api/v1beta1/azuremachinepool_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -700,27 +700,29 @@ func TestAzureMachinePool_ValidateCreateFailure(t *testing.T) {
g := NewWithT(t)

tests := []struct {
name string
amp *AzureMachinePool
deferFunc func()
expectError bool
name string
amp *AzureMachinePool
featureGateEnabled *bool
expectError bool
}{
{
name: "feature gate explicitly disabled",
amp: getKnownValidAzureMachinePool(),
deferFunc: utilfeature.SetFeatureGateDuringTest(t, feature.Gates, capifeature.MachinePool, false),
expectError: true,
name: "feature gate explicitly disabled",
amp: getKnownValidAzureMachinePool(),
featureGateEnabled: ptr.To(false),
expectError: true,
},
{
name: "feature gate implicitly enabled",
amp: getKnownValidAzureMachinePool(),
deferFunc: func() {},
expectError: false,
name: "feature gate implicitly enabled",
amp: getKnownValidAzureMachinePool(),
featureGateEnabled: nil,
expectError: false,
},
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
defer tc.deferFunc()
if tc.featureGateEnabled != nil {
defer utilfeature.SetFeatureGateDuringTest(t, feature.Gates, capifeature.MachinePool, *tc.featureGateEnabled)()
}
ampw := &azureMachinePoolWebhook{}
_, err := ampw.ValidateCreate(context.Background(), tc.amp)
if tc.expectError {
Expand Down
Loading