Skip to content

Commit

Permalink
Merge pull request #3847 from mjnovice/mj/proxy-support
Browse files Browse the repository at this point in the history
Adding HTTP Proxy support for managed cluster
  • Loading branch information
k8s-ci-robot authored Aug 18, 2023
2 parents a050247 + a13fa67 commit 0bc07db
Show file tree
Hide file tree
Showing 8 changed files with 209 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
40 changes: 40 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
47 changes: 47 additions & 0 deletions azure/services/managedclusters/spec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,53 @@ func TestParameters(t *testing.T) {
g.Expect(*(*result.(containerservice.ManagedCluster).LinuxProfile.SSH.PublicKeys)[0].KeyData).To(Equal("test-ssh-key"))
},
},
{
name: "set HTTPProxyConfig if set",
existing: nil,
spec: &ManagedClusterSpec{
Name: "test-managedcluster",
ResourceGroup: "test-rg",
Location: "test-location",
Tags: nil,
Version: "v1.22.0",
LoadBalancerSKU: "Standard",
HTTPProxyConfig: &HTTPProxyConfig{
HTTPProxy: ptr.To("http://proxy.com"),
HTTPSProxy: ptr.To("https://proxy.com"),
},
GetAllAgentPools: func() ([]azure.ResourceSpecGetter, error) {
return []azure.ResourceSpecGetter{}, nil
},
},
expect: func(g *WithT, result interface{}) {
g.Expect(result).To(BeAssignableToTypeOf(containerservice.ManagedCluster{}))
g.Expect(result.(containerservice.ManagedCluster).HTTPProxyConfig).To(Not(BeNil()))
g.Expect((*result.(containerservice.ManagedCluster).HTTPProxyConfig.HTTPProxy)).To(Equal("http://proxy.com"))
},
},
{
name: "set HTTPProxyConfig if set with no proxy list",
existing: nil,
spec: &ManagedClusterSpec{
Name: "test-managedcluster",
ResourceGroup: "test-rg",
Location: "test-location",
Tags: nil,
Version: "v1.22.0",
LoadBalancerSKU: "Standard",
HTTPProxyConfig: &HTTPProxyConfig{
NoProxy: []string{"noproxy1", "noproxy2"},
},
GetAllAgentPools: func() ([]azure.ResourceSpecGetter, error) {
return []azure.ResourceSpecGetter{}, nil
},
},
expect: func(g *WithT, result interface{}) {
g.Expect(result).To(BeAssignableToTypeOf(containerservice.ManagedCluster{}))
g.Expect(result.(containerservice.ManagedCluster).HTTPProxyConfig).To(Not(BeNil()))
g.Expect((*result.(containerservice.ManagedCluster).HTTPProxyConfig.NoProxy)).To(Equal([]string{"noproxy1", "noproxy2"}))
},
},
{
name: "skip Linux profile if SSH key is not set",
existing: nil,
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 0bc07db

Please sign in to comment.