Skip to content
Open
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
2 changes: 1 addition & 1 deletion cluster/images/provider-helm/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM gcr.io/distroless/static@sha256:1f580b0a1922c3e54ae15b0758b5747b260bd99d39d40c2edb3e7f6e2452298b
FROM europe-west3-docker.pkg.dev/xxxl-artifact-repo/gcr-io-proxy/distroless/static@sha256:1f580b0a1922c3e54ae15b0758b5747b260bd99d39d40c2edb3e7f6e2452298b

ARG TARGETOS
ARG TARGETARCH
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
16 changes: 14 additions & 2 deletions pkg/controller/release/release.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ package release

import (
"context"
"time"

"github.com/crossplane/crossplane-runtime/pkg/logging"
"github.com/pkg/errors"
"helm.sh/helm/v3/pkg/chart"
Expand All @@ -30,9 +28,12 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/rest"
"net/http"
"net/url"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
ktype "sigs.k8s.io/kustomize/api/types"
"time"

xpv1 "github.com/crossplane/crossplane-runtime/apis/common/v1"
"github.com/crossplane/crossplane-runtime/pkg/controller"
Expand Down Expand Up @@ -80,6 +81,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 All @@ -96,6 +98,7 @@ func Setup(mgr ctrl.Manager, o controller.Options, timeout time.Duration) error
kcfgExtractorFn: resource.CommonCredentialExtractor,
gcpExtractorFn: resource.CommonCredentialExtractor,
gcpInjectorFn: gke.WrapRESTConfig,
parseURLFn: url.Parse,
newRestConfigFn: clients.NewRESTConfig,
newKubeClientFn: clients.NewKubeClient,
newHelmClientFn: helmClient.NewClient,
Expand All @@ -121,6 +124,7 @@ type connector struct {
kcfgExtractorFn func(ctx context.Context, src xpv1.CredentialsSource, c client.Client, ccs xpv1.CommonCredentialSelectors) ([]byte, error)
gcpExtractorFn func(ctx context.Context, src xpv1.CredentialsSource, c client.Client, ccs xpv1.CommonCredentialSelectors) ([]byte, error)
gcpInjectorFn func(ctx context.Context, rc *rest.Config, credentials []byte, scopes ...string) error
parseURLFn func(str string) (url *url.URL, err error)
newRestConfigFn func(kubeconfig []byte) (*rest.Config, error)
newKubeClientFn func(config *rest.Config) (client.Client, error)
newHelmClientFn func(log logging.Logger, config *rest.Config, helmArgs ...helmClient.ArgsApplier) (helmClient.Client, error)
Expand Down Expand Up @@ -202,6 +206,14 @@ func (c *connector) Connect(ctx context.Context, mg resource.Managed) (managed.E
}
}

if proxy := p.Spec.Proxy; proxy != "" {
u, err := c.parseURLFn(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
46 changes: 46 additions & 0 deletions pkg/controller/release/release_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package release

import (
"context"
"net/url"
"testing"

"github.com/google/go-cmp/cmp"
Expand Down Expand Up @@ -123,6 +124,7 @@ func Test_connector_Connect(t *testing.T) {
Source: xpv1.CredentialsSourceNone,
},
},
Proxy: "10.1.1.0",
},
}

Expand All @@ -131,6 +133,7 @@ func Test_connector_Connect(t *testing.T) {
kcfgExtractorFn func(ctx context.Context, src xpv1.CredentialsSource, c client.Client, ccs xpv1.CommonCredentialSelectors) ([]byte, error)
gcpExtractorFn func(ctx context.Context, src xpv1.CredentialsSource, c client.Client, ccs xpv1.CommonCredentialSelectors) ([]byte, error)
gcpInjectorFn func(ctx context.Context, rc *rest.Config, credentials []byte, scopes ...string) error
parseURL func(rawURL string) (*url.URL, error)
newRestConfigFn func(kubeconfig []byte) (*rest.Config, error)
newKubeClientFn func(config *rest.Config) (client.Client, error)
newHelmClientFn func(log logging.Logger, config *rest.Config, helmArgs ...helmClient.ArgsApplier) (helmClient.Client, error)
Expand Down Expand Up @@ -281,6 +284,39 @@ func Test_connector_Connect(t *testing.T) {
err: errors.Wrap(errBoom, errFailedToInjectGoogleCredentials),
},
},
"FailedToParseProxyURL": {
args: args{
client: &test.MockClient{
MockGet: func(ctx context.Context, key client.ObjectKey, obj client.Object) error {
if key.Name == providerName {
*obj.(*helmv1beta1.ProviderConfig) = providerConfig
return nil
}
return errBoom
},
},
kcfgExtractorFn: func(ctx context.Context, src xpv1.CredentialsSource, c client.Client, ccs xpv1.CommonCredentialSelectors) ([]byte, error) {
return nil, nil
},
newRestConfigFn: func(kubeconfig []byte) (config *rest.Config, err error) {
return nil, nil
},
gcpExtractorFn: func(ctx context.Context, src xpv1.CredentialsSource, c client.Client, ccs xpv1.CommonCredentialSelectors) ([]byte, error) {
return nil, nil
},
gcpInjectorFn: func(ctx context.Context, rc *rest.Config, credentials []byte, scopes ...string) error {
return nil
},
parseURL: func(rawURL string) (*url.URL, error) {
return nil, errBoom
},
usage: resource.TrackerFn(func(ctx context.Context, mg resource.Managed) error { return nil }),
mg: helmRelease(),
},
want: want{
err: errors.Wrap(errBoom, errFailedToParseProxy),
},
},
"FailedToCreateNewKubernetesClient": {
args: args{
client: &test.MockClient{
Expand All @@ -304,6 +340,9 @@ func Test_connector_Connect(t *testing.T) {
gcpInjectorFn: func(ctx context.Context, rc *rest.Config, credentials []byte, scopes ...string) error {
return nil
},
parseURL: func(rawURL string) (*url.URL, error) {
return nil, nil
},
newRestConfigFn: func(kubeconfig []byte) (config *rest.Config, err error) {
return &rest.Config{}, nil
},
Expand Down Expand Up @@ -340,6 +379,9 @@ func Test_connector_Connect(t *testing.T) {
gcpInjectorFn: func(ctx context.Context, rc *rest.Config, credentials []byte, scopes ...string) error {
return nil
},
parseURL: func(rawURL string) (*url.URL, error) {
return nil, nil
},
newRestConfigFn: func(kubeconfig []byte) (config *rest.Config, err error) {
return &rest.Config{}, nil
},
Expand Down Expand Up @@ -381,6 +423,9 @@ func Test_connector_Connect(t *testing.T) {
gcpInjectorFn: func(ctx context.Context, rc *rest.Config, credentials []byte, scopes ...string) error {
return nil
},
parseURL: func(rawURL string) (*url.URL, error) {
return nil, nil
},
newRestConfigFn: func(kubeconfig []byte) (config *rest.Config, err error) {
return &rest.Config{}, nil
},
Expand All @@ -406,6 +451,7 @@ func Test_connector_Connect(t *testing.T) {
kcfgExtractorFn: tc.args.kcfgExtractorFn,
gcpExtractorFn: tc.args.gcpExtractorFn,
gcpInjectorFn: tc.args.gcpInjectorFn,
parseURLFn: tc.args.parseURL,
newRestConfigFn: tc.args.newRestConfigFn,
newKubeClientFn: tc.args.newKubeClientFn,
newHelmClientFn: tc.args.newHelmClientFn,
Expand Down