Skip to content

Commit

Permalink
Merge pull request #104 from ctrox/wait-timeout
Browse files Browse the repository at this point in the history
Add WaitTimeout field
  • Loading branch information
turkenh authored Sep 6, 2021
2 parents bca01f3 + 3ea3967 commit 2dcbdd0
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 5 deletions.
3 changes: 3 additions & 0 deletions apis/release/v1beta1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ type ReleaseParameters struct {
SkipCreateNamespace bool `json:"skipCreateNamespace,omitempty"`
// Wait for the release to become ready.
Wait bool `json:"wait,omitempty"`
// WaitTimeout is the duration Helm will wait for the release to become
// ready. Only applies if wait is also set. Defaults to 5m.
WaitTimeout *metav1.Duration `json:"waitTimeout,omitempty"`
// PatchesFrom describe patches to be applied to the rendered manifests.
PatchesFrom []ValueFromSource `json:"patchesFrom,omitempty"`
// ValuesSpec defines the Helm value overrides spec for a Release.
Expand Down
6 changes: 6 additions & 0 deletions apis/release/v1beta1/zz_generated.deepcopy.go

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

5 changes: 5 additions & 0 deletions package/crds/helm.crossplane.io_releases.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,11 @@ spec:
wait:
description: Wait for the release to become ready.
type: boolean
waitTimeout:
description: WaitTimeout is the duration Helm will wait for the
release to become ready. Only applies if wait is also set. Defaults
to 5m.
type: string
required:
- chart
- namespace
Expand Down
6 changes: 5 additions & 1 deletion pkg/clients/helm/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"path"
"path/filepath"
"strings"
"time"

"github.com/crossplane/crossplane-runtime/pkg/logging"
"github.com/pkg/errors"
Expand Down Expand Up @@ -73,7 +74,7 @@ type client struct {
}

// NewClient returns a new Helm Client with provided config
func NewClient(log logging.Logger, config *rest.Config, namespace string, wait bool) (Client, error) {
func NewClient(log logging.Logger, config *rest.Config, namespace string, wait bool, timeout time.Duration) (Client, error) {
rg := newRESTClientGetter(config, namespace)

actionConfig := new(action.Configuration)
Expand Down Expand Up @@ -101,14 +102,17 @@ func NewClient(log logging.Logger, config *rest.Config, namespace string, wait b
ic := action.NewInstall(actionConfig)
ic.Namespace = namespace
ic.Wait = wait
ic.Timeout = timeout

uc := action.NewUpgrade(actionConfig)
uc.Wait = wait
uc.Timeout = timeout

uic := action.NewUninstall(actionConfig)

rb := action.NewRollback(actionConfig)
rb.Wait = wait
rb.Timeout = timeout

return &client{
log: log,
Expand Down
13 changes: 11 additions & 2 deletions pkg/controller/release/release.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ const (
resyncPeriod = 10 * time.Minute
reconcileTimeout = 10 * time.Minute

defaultWaitTimeout = 5 * time.Minute

helmReleaseNameAnnotation = "meta.helm.sh/release-name"
helmReleaseNamespaceAnnotation = "meta.helm.sh/release-namespace"
helmNamespaceLabel = "app.kubernetes.io/managed-by"
Expand Down Expand Up @@ -119,7 +121,7 @@ type connector struct {
usage resource.Tracker
newRestConfigFn func(kubeconfig []byte) (*rest.Config, error)
newKubeClientFn func(config *rest.Config) (client.Client, error)
newHelmClientFn func(log logging.Logger, config *rest.Config, namespace string, wait bool) (helmClient.Client, error)
newHelmClientFn func(log logging.Logger, config *rest.Config, namespace string, wait bool, timeout time.Duration) (helmClient.Client, error)
}

func (c *connector) Connect(ctx context.Context, mg resource.Managed) (managed.ExternalClient, error) {
Expand Down Expand Up @@ -184,7 +186,7 @@ func (c *connector) Connect(ctx context.Context, mg resource.Managed) (managed.E
return nil, errors.Wrap(err, errNewKubernetesClient)
}

h, err := c.newHelmClientFn(c.logger, rc, cr.Spec.ForProvider.Namespace, cr.Spec.ForProvider.Wait)
h, err := c.newHelmClientFn(c.logger, rc, cr.Spec.ForProvider.Namespace, cr.Spec.ForProvider.Wait, waitTimeout(cr))
if err != nil {
return nil, errors.Wrap(err, errNewKubernetesClient)
}
Expand Down Expand Up @@ -404,3 +406,10 @@ func (e *helmExternal) createNamespace(ctx context.Context, name string) error {
}
return e.kube.Create(ctx, ns)
}

func waitTimeout(cr *v1beta1.Release) time.Duration {
if cr.Spec.ForProvider.WaitTimeout != nil {
return cr.Spec.ForProvider.WaitTimeout.Duration
}
return defaultWaitTimeout
}
5 changes: 3 additions & 2 deletions pkg/controller/release/release_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"testing"
"time"

"github.com/google/go-cmp/cmp"
"github.com/pkg/errors"
Expand Down Expand Up @@ -145,7 +146,7 @@ func Test_connector_Connect(t *testing.T) {
client client.Client
newRestConfigFn func(kubeconfig []byte) (*rest.Config, error)
newKubeClientFn func(config *rest.Config) (client.Client, error)
newHelmClientFn func(log logging.Logger, config *rest.Config, namespace string, wait bool) (helmClient.Client, error)
newHelmClientFn func(log logging.Logger, config *rest.Config, namespace string, wait bool, timeout time.Duration) (helmClient.Client, error)
usage resource.Tracker
mg resource.Managed
}
Expand Down Expand Up @@ -332,7 +333,7 @@ func Test_connector_Connect(t *testing.T) {
newKubeClientFn: func(config *rest.Config) (c client.Client, err error) {
return &test.MockClient{}, nil
},
newHelmClientFn: func(log logging.Logger, config *rest.Config, namespace string, wait bool) (h helmClient.Client, err error) {
newHelmClientFn: func(log logging.Logger, config *rest.Config, namespace string, wait bool, timeout time.Duration) (h helmClient.Client, err error) {
return &MockHelmClient{}, nil
},
usage: resource.TrackerFn(func(ctx context.Context, mg resource.Managed) error { return nil }),
Expand Down

0 comments on commit 2dcbdd0

Please sign in to comment.