Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Proxy Support #196

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions apis/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ type ProviderConfigSpec struct {
// example by configuring a bearer token source such as OAuth.
// +optional
Identity *Identity `json:"identity,omitempty"`

// Proxy used to connect to the Kubernetes API.
// +optional
Proxy string `json:"proxy,omitempty"`
}

// ProviderCredentials required to authenticate.
Expand Down
4 changes: 4 additions & 0 deletions apis/v1beta1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ type ProviderConfigSpec struct {
// example by configuring a bearer token source such as OAuth.
// +optional
Identity *Identity `json:"identity,omitempty"`

// Proxy used to connect to the Kubernetes API.
// +optional
Proxy string `json:"proxy,omitempty"`
}

// ProviderCredentials required to authenticate.
Expand Down
6 changes: 6 additions & 0 deletions package/crds/helm.crossplane.io_providerconfigs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,9 @@ spec:
- source
- type
type: object
proxy:
description: Proxy used to connect to the Kubernetes API.
type: string
required:
- credentials
type: object
Expand Down Expand Up @@ -358,6 +361,9 @@ spec:
- source
- type
type: object
proxy:
description: Proxy used to connect to the Kubernetes API.
type: string
required:
- credentials
type: object
Expand Down
11 changes: 11 additions & 0 deletions pkg/controller/release/release.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ package release

import (
"context"
"net/http"
"net/url"
"time"

"github.com/crossplane/crossplane-runtime/pkg/logging"
Expand Down Expand Up @@ -80,6 +82,7 @@ const (
errFailedToSetName = "failed to update chart spec with the name from URL"
errFailedToSetVersion = "failed to update chart spec with the latest version"
errFailedToCreateNamespace = "failed to create namespace for release"
errFailedToParseProxy = "failed to parse proxy url"
)

// Setup adds a controller that reconciles Release managed resources.
Expand Down Expand Up @@ -202,6 +205,14 @@ func (c *connector) Connect(ctx context.Context, mg resource.Managed) (managed.E
}
}

if proxy := p.Spec.Proxy; proxy != "" {
Copy link
Collaborator

@turkenh turkenh Aug 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it work by passing proxy/no_proxy environment variables via a ControllerConfig ? https://www.oreilly.com/library/view/security-with-go/9781788627917/5ea6a02b-3d96-44b1-ad3c-6ab60fcbbe4f.xhtml

Go's default HTTP client will respect the system's HTTP(S) proxy if set through environment variables. Go uses the HTTP_PROXY, HTTPS_PROXY and NO_PROXY environment variables. The lowercase versions are also valid.

Copy link
Author

@oskisk oskisk Aug 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would work when we only need to connect to a single proxy instance per controller.

In our case, we use a single Crossplane/Helm provider instance to manage many clusters in various VPC networks. As a result, we have to connect to a different proxy instance depending on the specific Cluster/Vpc.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @turkenh ,

Is there any update on this PR?

u, err := url.Parse(proxy)
if err != nil {
return nil, errors.Wrap(err, errFailedToParseProxy)
}
rc.Proxy = http.ProxyURL(u)
}

k, err := c.newKubeClientFn(rc)
if err != nil {
return nil, errors.Wrap(err, errNewKubernetesClient)
Expand Down