Skip to content

Commit

Permalink
Merge pull request #281 from damdo/rebase-atop-v1.9.5
Browse files Browse the repository at this point in the history
  • Loading branch information
openshift-merge-robot committed Jul 14, 2023
2 parents 99b7673 + 444db59 commit 54469b7
Show file tree
Hide file tree
Showing 3,777 changed files with 1,081,586 additions and 549 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
8 changes: 6 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ create-management-cluster: $(KUSTOMIZE) $(ENVSUBST) $(KUBECTL) $(KIND) ## Create
./hack/create-custom-cloud-provider-config.sh

# Deploy CAPI
curl --retry $(CURL_RETRIES) -sSL https://github.com/kubernetes-sigs/cluster-api/releases/download/v1.4.2/cluster-api-components.yaml | $(ENVSUBST) | $(KUBECTL) apply -f -
curl --retry $(CURL_RETRIES) -sSL https://github.com/kubernetes-sigs/cluster-api/releases/download/v1.4.3/cluster-api-components.yaml | $(ENVSUBST) | $(KUBECTL) apply -f -

# Deploy CAPZ
$(KIND) load docker-image $(CONTROLLER_IMG)-$(ARCH):$(TAG) --name=$(KIND_CLUSTER_NAME)
Expand Down Expand Up @@ -479,14 +479,18 @@ generate-addons: fetch-calico-manifests ## Generate metric-server, calico calico
$(KUSTOMIZE) build $(ADDONS_DIR)/calico-dual-stack > $(ADDONS_DIR)/calico-dual-stack.yaml

# When updating this, make sure to also update the Windows image version in templates/addons/windows/calico.
CALICO_VERSION := v3.25.0
export CALICO_VERSION := v3.25.1
# Where all downloaded Calico manifests are unpacked and stored.
CALICO_RELEASES := $(ARTIFACTS)/calico
# Path to manifests directory in a Calico release archive.
CALICO_RELEASE_MANIFESTS_DIR := release-$(CALICO_VERSION)/manifests
# Path where Calico manifests are stored which should be used for addons generation.
CALICO_MANIFESTS_DIR := $(ARTIFACTS)/calico/$(CALICO_RELEASE_MANIFESTS_DIR)

.PHONY: get-calico-version
get-calico-version: ## Print the Calico version used for CNI in the repo.
@echo $(CALICO_VERSION)

.PHONY: fetch-calico-manifests
fetch-calico-manifests: $(CALICO_MANIFESTS_DIR) ## Get Calico release manifests and unzip them.
cp $(CALICO_MANIFESTS_DIR)/calico-vxlan.yaml $(ADDONS_DIR)/calico
Expand Down
9 changes: 6 additions & 3 deletions Tiltfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ settings = {
"deploy_cert_manager": True,
"preload_images_for_kind": True,
"kind_cluster_name": "capz",
"capi_version": "v1.4.2",
"cert_manager_version": "v1.11.1",
"capi_version": "v1.4.3",
"cert_manager_version": "v1.12.1",
"kubernetes_version": "v1.24.6",
"aks_kubernetes_version": "v1.24.6",
"flatcar_version": "3374.2.1",
Expand Down Expand Up @@ -373,9 +373,12 @@ def deploy_worker_templates(template, substitutions):
calico_values = "./templates/addons/calico-dual-stack/values.yaml"
else:
calico_values = "./templates/addons/calico/values.yaml"
flavor_cmd += "; " + helm_cmd + " repo add projectcalico https://docs.tigera.io/calico/charts; " + helm_cmd + " --kubeconfig ./${CLUSTER_NAME}.kubeconfig install calico projectcalico/tigera-operator -f " + calico_values + " --namespace tigera-operator --create-namespace"
flavor_cmd += "; " + helm_cmd + " repo add projectcalico https://docs.tigera.io/calico/charts; " + helm_cmd + " --kubeconfig ./${CLUSTER_NAME}.kubeconfig install --version ${CALICO_VERSION} calico projectcalico/tigera-operator -f " + calico_values + " --namespace tigera-operator --create-namespace"
if "intree-cloud-provider" not in flavor_name:
flavor_cmd += "; " + helm_cmd + " --kubeconfig ./${CLUSTER_NAME}.kubeconfig install --repo https://raw.githubusercontent.com/kubernetes-sigs/cloud-provider-azure/master/helm/repo cloud-provider-azure --generate-name --set infra.clusterName=${CLUSTER_NAME}"
if "flatcar" in flavor_name: # append caCetDir location to the cloud-provider-azure helm install command for flatcar flavor
flavor_cmd += " --set-string cloudControllerManager.caCertDir=/usr/share/ca-certificates"

local_resource(
name = flavor_name,
cmd = flavor_cmd,
Expand Down
7 changes: 4 additions & 3 deletions api/v1beta1/azurecluster_default.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,10 @@ func (c *AzureCluster) setSubnetDefaults() {
subnet.RouteTable.Name = generateNodeRouteTableName(c.ObjectMeta.Name)
}

if !subnet.IsIPv6Enabled() {
// NAT gateway supports the use of IPv4 public IP addresses for outbound connectivity.
// So default use the NAT gateway for outbound traffic in IPv4 cluster instead of loadbalancer.
// NAT gateway only supports the use of IPv4 public IP addresses for outbound connectivity.
// So default use the NAT gateway for outbound traffic in IPv4 cluster instead of loadbalancer.
// We assume that if the ID is set, the subnet already exists so we shouldn't add a NAT gateway.
if !subnet.IsIPv6Enabled() && subnet.ID == "" {
if subnet.NatGateway.Name == "" {
subnet.NatGateway.Name = withIndex(generateNatGatewayName(c.ObjectMeta.Name), nodeSubnetCounter)
}
Expand Down
67 changes: 67 additions & 0 deletions api/v1beta1/azurecluster_default_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -724,6 +724,73 @@ func TestSubnetDefaults(t *testing.T) {
},
},
},
{
name: "don't default NAT Gateway if subnet already exists",
cluster: &AzureCluster{
ObjectMeta: metav1.ObjectMeta{
Name: "cluster-test",
},
Spec: AzureClusterSpec{
NetworkSpec: NetworkSpec{
Subnets: Subnets{
{
SubnetClassSpec: SubnetClassSpec{
Role: SubnetControlPlane,
Name: "cluster-test-controlplane-subnet",
},
ID: "my-subnet-id",
},
{
SubnetClassSpec: SubnetClassSpec{
Role: SubnetNode,
Name: "cluster-test-node-subnet",
},
ID: "my-subnet-id-2",
},
},
},
},
},
output: &AzureCluster{
ObjectMeta: metav1.ObjectMeta{
Name: "cluster-test",
},
Spec: AzureClusterSpec{
NetworkSpec: NetworkSpec{
Subnets: Subnets{
{
SubnetClassSpec: SubnetClassSpec{
Role: SubnetControlPlane,
CIDRBlocks: []string{DefaultControlPlaneSubnetCIDR},
Name: "cluster-test-controlplane-subnet",
},
ID: "my-subnet-id",
SecurityGroup: SecurityGroup{Name: "cluster-test-controlplane-nsg"},
RouteTable: RouteTable{},
},
{
SubnetClassSpec: SubnetClassSpec{
Role: SubnetNode,
CIDRBlocks: []string{DefaultNodeSubnetCIDR},
Name: "cluster-test-node-subnet",
},
ID: "my-subnet-id-2",
SecurityGroup: SecurityGroup{Name: "cluster-test-node-nsg"},
RouteTable: RouteTable{Name: "cluster-test-node-routetable"},
NatGateway: NatGateway{
NatGatewayClassSpec: NatGatewayClassSpec{
Name: "",
},
NatGatewayIP: PublicIPSpec{
Name: "",
},
},
},
},
},
},
},
},
}

for _, c := range cases {
Expand Down
2 changes: 1 addition & 1 deletion api/v1beta1/types_class.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ type AzureClusterClassSpec struct {
// CloudProviderConfigOverrides is an optional set of configuration values that can be overridden in azure cloud provider config.
// This is only a subset of options that are available in azure cloud provider config.
// Some values for the cloud provider config are inferred from other parts of cluster api provider azure spec, and may not be available for overrides.
// See: https://kubernetes-sigs.github.io/cloud-provider-azure/install/configs
// See: https://cloud-provider-azure.sigs.k8s.io/install/configs
// Note: All cloud provider config values can be customized by creating the secret beforehand. CloudProviderConfigOverrides is only used when the secret is managed by the Azure Provider.
// +optional
CloudProviderConfigOverrides *CloudProviderConfigOverrides `json:"cloudProviderConfigOverrides,omitempty"`
Expand Down
6 changes: 6 additions & 0 deletions azure/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ const (
// for annotation formatting rules.
ManagedClusterTagsLastAppliedAnnotation = "sigs.k8s.io/cluster-api-provider-azure-last-applied-tags-managedcluster"

// SecurityRuleLastAppliedAnnotation is the key for the Azure Cluster
// object annotation which tracks the security rules for security groups.
// See https://kubernetes.io/docs/concepts/overview/working-with-objects/annotations/
// for annotation formatting rules.
SecurityRuleLastAppliedAnnotation = "sigs.k8s.io/cluster-api-provider-azure-last-applied-security-rules"

// CustomDataHashAnnotation is the key for the machine object annotation
// which tracks the hash of the custom data.
// See https://kubernetes.io/docs/concepts/overview/working-with-objects/annotations/
Expand Down
7 changes: 7 additions & 0 deletions azure/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ package azure
import (
"fmt"
"net/http"
"strings"

"github.com/Azure/azure-sdk-for-go/sdk/azcore/arm"
"github.com/Azure/go-autorest/autorest"
"sigs.k8s.io/cluster-api-provider-azure/util/tele"
"sigs.k8s.io/cluster-api-provider-azure/version"
Expand Down Expand Up @@ -361,3 +363,8 @@ func msCorrelationIDSendDecorator(snd autorest.Sender) autorest.Sender {
return snd.Do(r)
})
}

// ParseResourceID parses a string to an *arm.ResourceID, first removing any "azure://" prefix.
func ParseResourceID(id string) (*arm.ResourceID, error) {
return arm.ParseResourceID(strings.TrimPrefix(id, ProviderIDPrefix))
}
52 changes: 52 additions & 0 deletions azure/defaults_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,55 @@ func TestMSCorrelationIDSendDecorator(t *testing.T) {
receivedReq.Header.Get(string(tele.CorrIDKeyVal)),
).To(Equal(string(corrID)))
}

func TestParseResourceID(t *testing.T) {
g := NewWithT(t)

tests := []struct {
name string
id string
expectedName string
errExpected bool
}{
{
name: "invalid",
id: "invalid",
expectedName: "",
errExpected: true,
},
{
name: "invalid: must start with slash",
id: "subscriptions/123/resourceGroups/rg/providers/Microsoft.Compute/virtualMachines/vm",
expectedName: "",
errExpected: true,
},
{
name: "invalid: must start with subscriptions or providers",
id: "/prescriptions/123/resourceGroups/rg/providers/Microsoft.Compute/virtualMachines/vm",
expectedName: "",
errExpected: true,
},
{
name: "valid",
id: "/subscriptions/123/resourceGroups/rg/providers/Microsoft.Compute/virtualMachines/vm",
expectedName: "vm",
},
{
name: "valid with provider prefix",
id: "azure:///subscriptions/123/resourceGroups/rg/providers/Microsoft.Compute/virtualMachines/vm",
expectedName: "vm",
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
resourceID, err := ParseResourceID(tt.id)
if tt.errExpected {
g.Expect(err).To(HaveOccurred())
} else {
g.Expect(err).NotTo(HaveOccurred())
g.Expect(resourceID.Name).To(Equal(tt.expectedName))
}
})
}
}
2 changes: 1 addition & 1 deletion azure/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ type NetworkDescriber interface {
ControlPlaneRouteTable() infrav1.RouteTable
APIServerLB() *infrav1.LoadBalancerSpec
APIServerLBName() string
APIServerLBPoolName(string) string
APIServerLBPoolName() string
IsAPIServerPrivate() bool
GetPrivateDNSZoneName() string
OutboundLBName(string) string
Expand Down
16 changes: 8 additions & 8 deletions azure/mock_azure/azure_mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

64 changes: 42 additions & 22 deletions azure/scope/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -351,12 +351,13 @@ func (s *ClusterScope) NSGSpecs() []azure.ResourceSpecGetter {
nsgspecs := make([]azure.ResourceSpecGetter, len(s.AzureCluster.Spec.NetworkSpec.Subnets))
for i, subnet := range s.AzureCluster.Spec.NetworkSpec.Subnets {
nsgspecs[i] = &securitygroups.NSGSpec{
Name: subnet.SecurityGroup.Name,
SecurityRules: subnet.SecurityGroup.SecurityRules,
ResourceGroup: s.ResourceGroup(),
Location: s.Location(),
ClusterName: s.ClusterName(),
AdditionalTags: s.AdditionalTags(),
Name: subnet.SecurityGroup.Name,
SecurityRules: subnet.SecurityGroup.SecurityRules,
ResourceGroup: s.ResourceGroup(),
Location: s.Location(),
ClusterName: s.ClusterName(),
AdditionalTags: s.AdditionalTags(),
LastAppliedSecurityRules: s.getLastAppliedSecurityRules(subnet.SecurityGroup.Name),
}
}

Expand Down Expand Up @@ -692,33 +693,37 @@ func (s *ClusterScope) GetPrivateDNSZoneName() string {
}

// APIServerLBPoolName returns the API Server LB backend pool name.
func (s *ClusterScope) APIServerLBPoolName(loadBalancerName string) string {
return azure.GenerateBackendAddressPoolName(loadBalancerName)
func (s *ClusterScope) APIServerLBPoolName() string {
return s.APIServerLB().BackendPool.Name
}

// OutboundLBName returns the name of the outbound LB.
func (s *ClusterScope) OutboundLBName(role string) string {
// OutboundLB returns the outbound LB.
func (s *ClusterScope) outboundLB(role string) *infrav1.LoadBalancerSpec {
if role == infrav1.Node {
if s.NodeOutboundLB() == nil {
return ""
}
return s.NodeOutboundLB().Name
return s.NodeOutboundLB()
}
if s.IsAPIServerPrivate() {
if s.ControlPlaneOutboundLB() == nil {
return ""
}
return s.ControlPlaneOutboundLB().Name
return s.ControlPlaneOutboundLB()
}
return s.APIServerLB()
}

// OutboundLBName returns the name of the outbound LB.
func (s *ClusterScope) OutboundLBName(role string) string {
lb := s.outboundLB(role)
if lb == nil {
return ""
}
return s.APIServerLBName()
return lb.Name
}

// OutboundPoolName returns the outbound LB backend pool name.
func (s *ClusterScope) OutboundPoolName(loadBalancerName string) string {
if loadBalancerName == "" {
func (s *ClusterScope) OutboundPoolName(role string) string {
lb := s.outboundLB(role)
if lb == nil {
return ""
}
return azure.GenerateOutboundBackendAddressPoolName(loadBalancerName)
return lb.BackendPool.Name
}

// ResourceGroup returns the cluster resource group.
Expand Down Expand Up @@ -1100,3 +1105,18 @@ func (s *ClusterScope) getPrivateEndpoints(subnet infrav1.SubnetSpec) []azure.Re

return privateEndpointSpecs
}

func (s *ClusterScope) getLastAppliedSecurityRules(nsgName string) map[string]interface{} {
// Retrieve the last applied security rules for all NSGs.
lastAppliedSecurityRulesAll, err := s.AnnotationJSON(azure.SecurityRuleLastAppliedAnnotation)
if err != nil {
return map[string]interface{}{}
}

// Retrieve the last applied security rules for this NSG.
lastAppliedSecurityRules, ok := lastAppliedSecurityRulesAll[nsgName].(map[string]interface{})
if !ok {
lastAppliedSecurityRules = map[string]interface{}{}
}
return lastAppliedSecurityRules
}

0 comments on commit 54469b7

Please sign in to comment.