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 0c70abe commit 7eb5cec
Show file tree
Hide file tree
Showing 7 changed files with 166 additions and 0 deletions.
24 changes: 24 additions & 0 deletions api/v1beta1/azuremanagedcontrolplane_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,30 @@ 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 is the HTTP proxy server endpoint to use.
// +optional
HTTPProxy *string `json:"httpProxy,omitempty"`

// HTTPSProxy is the HTTPS proxy server endpoint to use.
// +optional
HTTPSProxy *string `json:"httpsProxy,omitempty"`

// NoProxy indicates the endpoints that should not go through proxy.
// +optional
NoProxy []string `json:"noProxy,omitempty"`

// TrustedCA is the alternative CA cert to use for connecting to proxy servers.
// +optional
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 @@ -200,6 +200,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 @@ -1387,6 +1387,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: ptr.To("http://1.2.3.4:8080"),
HTTPSProxy: ptr.To("https://5.6.7.8:8443"),
NoProxy: &[]string{"endpoint1", "endpoint2"},
TrustedCA: ptr.To("ca"),
},
},
},
amcp: &AzureManagedControlPlane{
ObjectMeta: metav1.ObjectMeta{
Name: "test-cluster",
},
Spec: AzureManagedControlPlaneSpec{
HTTPProxyConfig: &HTTPProxyConfig{
HTTPProxy: ptr.To("http://10.20.3.4:8080"),
HTTPSProxy: ptr.To("https://5.6.7.8:8443"),
NoProxy: &[]string{"endpoint1", "endpoint2"},
TrustedCA: ptr.To("ca"),
},
},
},
wantErr: true,
},
}
client := mockClient{ReturnError: false}
for _, tc := range tests {
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
30 changes: 30 additions & 0 deletions azure/services/managedclusters/spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,24 @@ 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 is the HTTP proxy server endpoint to use.
HTTPProxy *string `json:"httpProxy,omitempty"`

// HTTPSProxy is the HTTPS proxy server endpoint to use.
HTTPSProxy *string `json:"httpsProxy,omitempty"`

// NoProxy is the endpoints that should not go through proxy.
NoProxy []string `json:"noProxy,omitempty"`

// TrustedCA is the 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 +432,18 @@ 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,
TrustedCa: s.HTTPProxyConfig.TrustedCA,
}
}

if s.HTTPProxyConfig.NoProxy != nil {
managedCluster.HTTPProxyConfig.NoProxy = &s.HTTPProxyConfig.NoProxy
}

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,28 @@ 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 is the HTTP proxy server endpoint to use.
type: string
httpsProxy:
description: HTTPSProxy is the HTTPS proxy server endpoint to
use.
type: string
noProxy:
description: NoProxy indicates the endpoints that should not go
through proxy.
items:
type: string
type: array
trustedCa:
description: TrustedCA is the 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 7eb5cec

Please sign in to comment.