|
| 1 | +// Copyright (c) Microsoft Corporation. |
| 2 | +// Licensed under the MIT license. |
| 3 | +package customizations |
| 4 | + |
| 5 | +import ( |
| 6 | + "context" |
| 7 | + |
| 8 | + "github.com/go-logr/logr" |
| 9 | + "github.com/pkg/errors" |
| 10 | + "sigs.k8s.io/controller-runtime/pkg/conversion" |
| 11 | + |
| 12 | + network "github.com/Azure/azure-service-operator/v2/api/network/v1api20240301/storage" |
| 13 | + "github.com/Azure/azure-service-operator/v2/internal/genericarmclient" |
| 14 | + "github.com/Azure/azure-service-operator/v2/internal/resolver" |
| 15 | + "github.com/Azure/azure-service-operator/v2/pkg/genruntime" |
| 16 | + "github.com/Azure/azure-service-operator/v2/pkg/genruntime/extensions" |
| 17 | +) |
| 18 | + |
| 19 | +var _ extensions.PostReconciliationChecker = &PrivateEndpointExtension{} |
| 20 | + |
| 21 | +func (extension *VirtualNetworksSubnetExtension) PostReconcileCheck( |
| 22 | + _ context.Context, |
| 23 | + obj genruntime.MetaObject, |
| 24 | + _ genruntime.MetaObject, |
| 25 | + _ *resolver.Resolver, |
| 26 | + _ *genericarmclient.GenericClient, |
| 27 | + _ logr.Logger, |
| 28 | + _ extensions.PostReconcileCheckFunc, |
| 29 | +) (extensions.PostReconcileCheckResult, error) { |
| 30 | + subnet, ok := obj.(*network.VirtualNetworksSubnet) |
| 31 | + if !ok { |
| 32 | + return extensions.PostReconcileCheckResult{}, |
| 33 | + errors.Errorf("cannot run on unknown resource type %T, expected *network.VirtualNetworksSubnet", obj) |
| 34 | + } |
| 35 | + |
| 36 | + // Type assert that we are the hub type. This will fail to compile if |
| 37 | + // the hub type has been changed but this extension has not |
| 38 | + var _ conversion.Hub = subnet |
| 39 | + |
| 40 | + // Subnets can have a HUGE number of ipConfigurations in some modes. So many that it can cause Kubernetes to be unable |
| 41 | + // to fit the resource. We have to omit them after some point to avoid blowing out the resource size and causing |
| 42 | + // kube-apiserver to reject us. See https://github.com/Azure/azure-service-operator/issues/4428. |
| 43 | + |
| 44 | + // This limit was chosen based on a 300 character long IPConfiguration ID, |
| 45 | + // which would be 300 bytes in UTF-8. 2000*300 = ~.6mb, which is about around 1/3rd the max allowed size of a |
| 46 | + // Kubernetes object. |
| 47 | + if len(subnet.Status.IpConfigurations) > 2000 { |
| 48 | + subnet.Status.IpConfigurations = nil |
| 49 | + } |
| 50 | + |
| 51 | + return extensions.PostReconcileCheckResultSuccess(), nil |
| 52 | +} |
0 commit comments