Skip to content

Commit

Permalink
added spectro changes
Browse files Browse the repository at this point in the history
logic to separate webhook and controller as separate pods

removed azuremanagedmachinepool delete webhook

fixed issues while update of azurecluster and azuremachinetemplate due to webhooks 

added credentials patch
  • Loading branch information
LochanRn committed Oct 27, 2021
1 parent 7f78c7b commit 3e22e02
Show file tree
Hide file tree
Showing 21 changed files with 6,983 additions and 72 deletions.
10 changes: 5 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,12 @@ KUBE_APISERVER=$(TOOLS_BIN_DIR)/kube-apiserver
ETCD=$(TOOLS_BIN_DIR)/etcd

# Define Docker related variables. Releases should modify and double check these vars.
REGISTRY ?= gcr.io/$(shell gcloud config get-value project)
REGISTRY ?= gcr.io/spectro-images-public/cluster-api-azure
STAGING_REGISTRY := gcr.io/k8s-staging-cluster-api-azure
PROD_REGISTRY := us.gcr.io/k8s-artifacts-prod/cluster-api-azure
IMAGE_NAME ?= cluster-api-azure-controller
CONTROLLER_IMG ?= $(REGISTRY)/$(IMAGE_NAME)
TAG ?= dev
TAG ?= spectro-v0.5.3-20211021
ARCH ?= amd64
ALL_ARCH = amd64 arm arm64 ppc64le s390x

Expand Down Expand Up @@ -357,13 +357,13 @@ docker-pull-prerequisites:

.PHONY: docker-build
docker-build: docker-pull-prerequisites ## Build the docker image for controller-manager
DOCKER_BUILDKIT=1 docker build --build-arg goproxy=$(GOPROXY) --build-arg ARCH=$(ARCH) --build-arg ldflags="$(LDFLAGS)" . -t $(CONTROLLER_IMG)-$(ARCH):$(TAG)
$(MAKE) set-manifest-image MANIFEST_IMG=$(CONTROLLER_IMG)-$(ARCH) MANIFEST_TAG=$(TAG) TARGET_RESOURCE="./config/default/manager_image_patch.yaml"
DOCKER_BUILDKIT=1 docker build --build-arg goproxy=$(GOPROXY) --build-arg ARCH=$(ARCH) --build-arg ldflags="$(LDFLAGS)" . -t $(CONTROLLER_IMG):$(TAG)
$(MAKE) set-manifest-image MANIFEST_IMG=$(CONTROLLER_IMG) MANIFEST_TAG=$(TAG) TARGET_RESOURCE="./config/default/manager_image_patch.yaml"
$(MAKE) set-manifest-pull-policy TARGET_RESOURCE="./config/default/manager_pull_policy.yaml"

.PHONY: docker-push
docker-push: ## Push the docker image
docker push $(CONTROLLER_IMG)-$(ARCH):$(TAG)
docker push $(CONTROLLER_IMG):$(TAG)

## --------------------------------------
## Docker — All ARCH
Expand Down
1 change: 1 addition & 0 deletions api/v1alpha4/azurecluster_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ func (c *AzureCluster) ValidateUpdate(oldRaw runtime.Object) error {
)
}

old.setAzureEnvironmentDefault()
if !reflect.DeepEqual(c.Spec.AzureEnvironment, old.Spec.AzureEnvironment) {
allErrs = append(allErrs,
field.Invalid(field.NewPath("spec", "AzureEnvironment"),
Expand Down
2 changes: 1 addition & 1 deletion api/v1alpha4/azuremachinetemplate_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func (r *AzureMachineTemplate) ValidateUpdate(oldRaw runtime.Object) error {
machinetemplatelog.Info("validate update", "name", r.Name)
var allErrs field.ErrorList
old := oldRaw.(*AzureMachineTemplate)

old.Default()
if !reflect.DeepEqual(r.Spec.Template.Spec, old.Spec.Template.Spec) {
allErrs = append(allErrs,
field.Invalid(field.NewPath("AzureMachineTemplate", "spec", "template", "spec"), r, AzureMachineTemplateImmutableMsg),
Expand Down
14 changes: 12 additions & 2 deletions azure/services/publicips/publicips.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,17 @@ func (s *Service) Reconcile(ctx context.Context) error {
}
}

err := s.Client.CreateOrUpdate(
existingIP, err := s.Client.Get(ctx, s.Scope.ResourceGroup(), ip.Name)
if err != nil && !azure.ResourceNotFound(err) {
return errors.Wrap(err, "failed to fetch existing ip")
}

zones := existingIP.Zones
if err != nil && azure.ResourceNotFound(err) {
zones = to.StringSlicePtr(s.Scope.FailureDomains())
}

err = s.Client.CreateOrUpdate(
ctx,
s.Scope.ResourceGroup(),
ip.Name,
Expand All @@ -94,7 +104,7 @@ func (s *Service) Reconcile(ctx context.Context) error {
PublicIPAllocationMethod: network.IPAllocationMethodStatic,
DNSSettings: dnsSettings,
},
Zones: to.StringSlicePtr(s.Scope.FailureDomains()),
Zones: zones,
},
)

Expand Down
35 changes: 35 additions & 0 deletions azure/services/publicips/publicips_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,18 @@ func TestReconcilePublicIP(t *testing.T) {
IsIPv6: true,
DNSName: "fakename.mydomain.io",
},
{
Name: "my-publicip",
DNSName: "fakedns.mydomain.io",
},
})
s.ResourceGroup().AnyTimes().Return("my-rg")
s.ClusterName().AnyTimes().Return("my-cluster")
s.AdditionalTags().AnyTimes().Return(infrav1.Tags{})
s.Location().AnyTimes().Return("testlocation")
s.FailureDomains().AnyTimes().Return([]string{"1,2,3"})
gomock.InOrder(
m.Get(gomockinternal.AContext(), "my-rg", "my-publicip").Return(network.PublicIPAddress{}, autorest.NewErrorWithResponse("", "", &http.Response{StatusCode: 404}, "Not Found")),
m.CreateOrUpdate(gomockinternal.AContext(), "my-rg", "my-publicip", gomockinternal.DiffEq(network.PublicIPAddress{
Name: to.StringPtr("my-publicip"),
Sku: &network.PublicIPAddressSku{Name: network.PublicIPAddressSkuNameStandard},
Expand All @@ -97,6 +102,7 @@ func TestReconcilePublicIP(t *testing.T) {
},
Zones: to.StringSlicePtr([]string{"1,2,3"}),
})).Times(1),
m.Get(gomockinternal.AContext(), "my-rg", "my-publicip-2").Return(network.PublicIPAddress{}, autorest.NewErrorWithResponse("", "", &http.Response{StatusCode: 404}, "Not Found")),
m.CreateOrUpdate(gomockinternal.AContext(), "my-rg", "my-publicip-2", gomockinternal.DiffEq(network.PublicIPAddress{
Name: to.StringPtr("my-publicip-2"),
Sku: &network.PublicIPAddressSku{Name: network.PublicIPAddressSkuNameStandard},
Expand All @@ -115,6 +121,7 @@ func TestReconcilePublicIP(t *testing.T) {
},
Zones: to.StringSlicePtr([]string{"1,2,3"}),
})).Times(1),
m.Get(gomockinternal.AContext(), "my-rg", "my-publicip-3").Return(network.PublicIPAddress{}, autorest.NewErrorWithResponse("", "", &http.Response{StatusCode: 404}, "Not Found")),
m.CreateOrUpdate(gomockinternal.AContext(), "my-rg", "my-publicip-3", gomockinternal.DiffEq(network.PublicIPAddress{
Name: to.StringPtr("my-publicip-3"),
Sku: &network.PublicIPAddressSku{Name: network.PublicIPAddressSkuNameStandard},
Expand All @@ -129,6 +136,7 @@ func TestReconcilePublicIP(t *testing.T) {
},
Zones: to.StringSlicePtr([]string{"1,2,3"}),
})).Times(1),
m.Get(gomockinternal.AContext(), "my-rg", "my-publicip-ipv6").Return(network.PublicIPAddress{}, autorest.NewErrorWithResponse("", "", &http.Response{StatusCode: 404}, "Not Found")),
m.CreateOrUpdate(gomockinternal.AContext(), "my-rg", "my-publicip-ipv6", gomockinternal.DiffEq(network.PublicIPAddress{
Name: to.StringPtr("my-publicip-ipv6"),
Sku: &network.PublicIPAddressSku{Name: network.PublicIPAddressSkuNameStandard},
Expand All @@ -147,6 +155,32 @@ func TestReconcilePublicIP(t *testing.T) {
},
Zones: to.StringSlicePtr([]string{"1,2,3"}),
})).Times(1),
m.Get(gomockinternal.AContext(), "my-rg", "my-publicip").Return(network.PublicIPAddress{
Name: to.StringPtr("my-publicip"),
Tags: map[string]*string{
"Name": to.StringPtr("my-publicip"),
"sigs.k8s.io_cluster-api-provider-azure_cluster_my-cluster": to.StringPtr("owned"),
},
Zones: to.StringSlicePtr([]string{"1,2"}),
}, nil),
m.CreateOrUpdate(gomockinternal.AContext(), "my-rg", "my-publicip", gomockinternal.DiffEq(network.PublicIPAddress{
Name: to.StringPtr("my-publicip"),
Sku: &network.PublicIPAddressSku{Name: network.PublicIPAddressSkuNameStandard},
Location: to.StringPtr("testlocation"),
Tags: map[string]*string{
"Name": to.StringPtr("my-publicip"),
"sigs.k8s.io_cluster-api-provider-azure_cluster_my-cluster": to.StringPtr("owned"),
},
PublicIPAddressPropertiesFormat: &network.PublicIPAddressPropertiesFormat{
PublicIPAddressVersion: network.IPVersionIPv4,
PublicIPAllocationMethod: network.IPAllocationMethodStatic,
DNSSettings: &network.PublicIPAddressDNSSettings{
DomainNameLabel: to.StringPtr("fakedns"),
Fqdn: to.StringPtr("fakedns.mydomain.io"),
},
},
Zones: to.StringSlicePtr([]string{"1,2"}),
})).Times(1),
)
},
},
Expand All @@ -166,6 +200,7 @@ func TestReconcilePublicIP(t *testing.T) {
s.AdditionalTags().AnyTimes().Return(infrav1.Tags{})
s.Location().AnyTimes().Return("testlocation")
s.FailureDomains().Times(1)
m.Get(gomockinternal.AContext(), "my-rg", "my-publicip").Return(network.PublicIPAddress{}, autorest.NewErrorWithResponse("", "", &http.Response{StatusCode: 404}, "Not Found"))
m.CreateOrUpdate(gomockinternal.AContext(), "my-rg", "my-publicip", gomock.AssignableToTypeOf(network.PublicIPAddress{})).Return(autorest.NewErrorWithResponse("", "", &http.Response{StatusCode: 500}, "Internal Server Error"))
},
},
Expand Down
12 changes: 6 additions & 6 deletions config/crd/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ patchesStrategicMerge:
- patches/webhook_in_azuremachinetemplates.yaml
- patches/webhook_in_azuremachinepools.yaml
- patches/webhook_in_azuremachinepoolmachines.yaml
# - patches/webhook_in_azuremanagedmachinepools.yaml
# - patches/webhook_in_azuremanagedclusters.yaml
# - patches/webhook_in_azuremanagedcontrolplanes.yaml
- patches/webhook_in_azuremanagedmachinepools.yaml
- patches/webhook_in_azuremanagedclusters.yaml
- patches/webhook_in_azuremanagedcontrolplanes.yaml
# +kubebuilder:scaffold:crdkustomizewebhookpatch

# [CERTMANAGER] To enable webhook, uncomment all the sections with [CERTMANAGER] prefix.
Expand All @@ -39,9 +39,9 @@ patchesStrategicMerge:
- patches/cainjection_in_azuremachinetemplates.yaml
- patches/cainjection_in_azuremachinepools.yaml
- patches/cainjection_in_azuremachinepoolmachines.yaml
# - patches/cainjection_in_azuremanagedmachinepools.yaml
# - patches/cainjection_in_azuremanagedclusters.yaml
# - patches/cainjection_in_azuremanagedcontrolplanes.yaml
- patches/cainjection_in_azuremanagedmachinepools.yaml
- patches/cainjection_in_azuremanagedclusters.yaml
- patches/cainjection_in_azuremanagedcontrolplanes.yaml
# +kubebuilder:scaffold:crdkustomizecainjectionpatch

# the following config is for teaching kustomize how to do kustomization for CRDs.
Expand Down
2 changes: 1 addition & 1 deletion config/default/manager_image_patch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ spec:
spec:
containers:
# Change the value of image field below to your controller image URL
- image: gcr.io/k8s-staging-cluster-api-azure/cluster-api-azure-controller:latest
- image: gcr.io/spectro-images-public/cluster-api-azure/cluster-api-azure-controller:spectro-v0.5.3-20211021
name: manager
28 changes: 14 additions & 14 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ go 1.16

require (
github.com/Azure/aad-pod-identity v1.8.0
github.com/Azure/azure-sdk-for-go v55.8.0+incompatible
github.com/Azure/go-autorest/autorest v0.11.18
github.com/Azure/go-autorest/autorest/adal v0.9.13
github.com/Azure/azure-sdk-for-go v57.3.0+incompatible
github.com/Azure/go-autorest/autorest v0.11.21
github.com/Azure/go-autorest/autorest/adal v0.9.16
github.com/Azure/go-autorest/autorest/azure/auth v0.5.3
github.com/Azure/go-autorest/autorest/to v0.4.0
github.com/Azure/go-autorest/autorest/validation v0.3.0 // indirect
github.com/Azure/go-autorest/autorest/validation v0.3.1 // indirect
github.com/Azure/go-autorest/tracing v0.6.0
github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d
github.com/blang/semver v3.5.1+incompatible
Expand All @@ -25,16 +25,16 @@ require (
github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.11.0
github.com/spf13/pflag v1.0.5
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.23.0
go.opentelemetry.io/otel v1.0.0
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.0.0
go.opentelemetry.io/otel/exporters/prometheus v0.23.0
go.opentelemetry.io/otel/metric v0.23.0
go.opentelemetry.io/otel/sdk v1.0.0
go.opentelemetry.io/otel/sdk/export/metric v0.23.0
go.opentelemetry.io/otel/sdk/metric v0.23.0
go.opentelemetry.io/otel/trace v1.0.0
golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.22.0
go.opentelemetry.io/otel v1.0.0-RC2
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.0.0-RC2
go.opentelemetry.io/otel/exporters/prometheus v0.22.0
go.opentelemetry.io/otel/metric v0.22.0
go.opentelemetry.io/otel/sdk v1.0.0-RC2
go.opentelemetry.io/otel/sdk/export/metric v0.22.0
go.opentelemetry.io/otel/sdk/metric v0.22.0
go.opentelemetry.io/otel/trace v1.0.0-RC2
golang.org/x/crypto v0.0.0-20210915214749-c084706c2272
golang.org/x/mod v0.4.2
k8s.io/api v0.21.4
k8s.io/apimachinery v0.21.4
Expand Down
Loading

0 comments on commit 3e22e02

Please sign in to comment.