Skip to content

Commit

Permalink
Adding HTTPS support for managed cluster
Browse files Browse the repository at this point in the history
  • Loading branch information
mjnovice committed Aug 16, 2023
1 parent 3b81e27 commit cfac689
Show file tree
Hide file tree
Showing 7 changed files with 152 additions and 0 deletions.
17 changes: 17 additions & 0 deletions api/v1beta1/azuremanagedcontrolplane_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,23 @@ type AzureManagedControlPlaneSpec struct {
// For authentication with Azure Container Registry.
// +optional
KubeletUserAssignedIdentity string `json:"kubeletUserAssignedIdentity,omitempty"`

// HTTPProxyConfig is the HTTP proxy configuration for the cluster.
// Immutable.
// +optional
HTTPProxyConfig *HTTPProxyConfig `json:"httpProxyConfig,omitempty"`
}

// HTTPProxyConfig is the HTTP proxy configuration for the cluster.
type HTTPProxyConfig struct {
// HTTPProxy - The HTTP proxy server endpoint to use.
HTTPProxy *string `json:"httpProxy,omitempty"`
// HTTPSProxy - The HTTPS proxy server endpoint to use.
HTTPSProxy *string `json:"httpsProxy,omitempty"`
// NoProxy - The endpoints that should not go through proxy.
NoProxy *[]string `json:"noProxy,omitempty"`
// TrustedCa - Alternative CA cert to use for connecting to proxy servers.
TrustedCa *string `json:"trustedCa,omitempty"`
}

// AADProfile - AAD integration managed by AKS.
Expand Down
7 changes: 7 additions & 0 deletions api/v1beta1/azuremanagedcontrolplane_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,13 @@ func (mw *azureManagedControlPlaneWebhook) ValidateUpdate(ctx context.Context, o
allErrs = append(allErrs, err)
}

if err := webhookutils.ValidateImmutable(
field.NewPath("Spec", "HTTPProxyConfig"),
old.Spec.HTTPProxyConfig,
m.Spec.HTTPProxyConfig); err != nil {
allErrs = append(allErrs, err)
}

if err := webhookutils.ValidateImmutable(
field.NewPath("Spec", "AzureEnvironment"),
old.Spec.AzureEnvironment,
Expand Down
30 changes: 30 additions & 0 deletions api/v1beta1/azuremanagedcontrolplane_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1302,6 +1302,36 @@ func TestAzureManagedControlPlane_ValidateUpdate(t *testing.T) {
},
wantErr: true,
},
{
name: "AzureManagedControlPlane HTTPProxyConfig is immutable",
oldAMCP: &AzureManagedControlPlane{
ObjectMeta: metav1.ObjectMeta{
Name: "test-cluster",
},
Spec: AzureManagedControlPlaneSpec{
HTTPProxyConfig: &HTTPProxyConfig{
HTTPProxy: pointer.String("http://1.2.3.4:8080"),
HTTPSProxy: pointer.String("https://5.6.7.8:8443"),
NoProxy: &[]string{"endpoint1", "endpoint2"},
TrustedCa: pointer.String("ca"),
},
},
},
amcp: &AzureManagedControlPlane{
ObjectMeta: metav1.ObjectMeta{
Name: "test-cluster",
},
Spec: AzureManagedControlPlaneSpec{
HTTPProxyConfig: &HTTPProxyConfig{
HTTPProxy: pointer.String("http://10.20.3.4:8080"),
HTTPSProxy: pointer.String("https://5.6.7.8:8443"),
NoProxy: &[]string{"endpoint1", "endpoint2"},
TrustedCa: pointer.String("ca"),
},
},
},
wantErr: true,
},
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
Expand Down
44 changes: 44 additions & 0 deletions api/v1beta1/zz_generated.deepcopy.go

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

9 changes: 9 additions & 0 deletions azure/scope/managedcontrolplane.go
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,15 @@ func (s *ManagedControlPlaneScope) ManagedClusterSpec() azure.ResourceSpecGetter
}
}

if s.ControlPlane.Spec.HTTPProxyConfig != nil {
managedClusterSpec.HTTPProxyConfig = &managedclusters.HTTPProxyConfig{
HTTPProxy: s.ControlPlane.Spec.HTTPProxyConfig.HTTPProxy,
HTTPSProxy: s.ControlPlane.Spec.HTTPProxyConfig.HTTPSProxy,
NoProxy: s.ControlPlane.Spec.HTTPProxyConfig.NoProxy,
TrustedCa: s.ControlPlane.Spec.HTTPProxyConfig.TrustedCa,
}
}

return &managedClusterSpec
}

Expand Down
24 changes: 24 additions & 0 deletions azure/services/managedclusters/spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,21 @@ type ManagedClusterSpec struct {

// KubeletUserAssignedIdentity is the user-assigned identity for kubelet to authenticate to ACR.
KubeletUserAssignedIdentity string

// HTTPProxyConfig is the HTTP proxy configuration for the cluster.
HTTPProxyConfig *HTTPProxyConfig
}

// HTTPProxyConfig is the HTTP proxy configuration for the cluster.
type HTTPProxyConfig struct {
// HTTPProxy - The HTTP proxy server endpoint to use.
HTTPProxy *string `json:"httpProxy,omitempty"`
// HTTPSProxy - The HTTPS proxy server endpoint to use.
HTTPSProxy *string `json:"httpsProxy,omitempty"`
// NoProxy - The endpoints that should not go through proxy.
NoProxy *[]string `json:"noProxy,omitempty"`
// TrustedCa - Alternative CA cert to use for connecting to proxy servers.
TrustedCa *string `json:"trustedCa,omitempty"`
}

// AADProfile is Azure Active Directory configuration to integrate with AKS, for aad authentication.
Expand Down Expand Up @@ -414,6 +429,15 @@ func (s *ManagedClusterSpec) Parameters(ctx context.Context, existing interface{
}
}

if s.HTTPProxyConfig != nil {
managedCluster.HTTPProxyConfig = &containerservice.ManagedClusterHTTPProxyConfig{
HTTPProxy: s.HTTPProxyConfig.HTTPProxy,
HTTPSProxy: s.HTTPProxyConfig.HTTPSProxy,
NoProxy: s.HTTPProxyConfig.NoProxy,
TrustedCa: s.HTTPProxyConfig.TrustedCa,
}
}

if existing != nil {
existingMC, ok := existing.(containerservice.ManagedCluster)
if !ok {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,27 @@ spec:
DNS service. It must be within the Kubernetes service address range
specified in serviceCidr. Immutable.
type: string
httpProxyConfig:
description: HTTPProxyConfig is the HTTP proxy configuration for the
cluster. Immutable.
properties:
httpProxy:
description: HTTPProxy - The HTTP proxy server endpoint to use.
type: string
httpsProxy:
description: HTTPSProxy - The HTTPS proxy server endpoint to use.
type: string
noProxy:
description: NoProxy - The endpoints that should not go through
proxy.
items:
type: string
type: array
trustedCa:
description: TrustedCa - Alternative CA cert to use for connecting
to proxy servers.
type: string
type: object
identity:
description: Identity configuration used by the AKS control plane.
properties:
Expand Down

0 comments on commit cfac689

Please sign in to comment.