Skip to content

Commit 49a49fd

Browse files
Cr 29017 skip hook (#789)
1 parent ac5b901 commit 49a49fd

File tree

6 files changed

+29
-11
lines changed

6 files changed

+29
-11
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
VERSION=v0.2.7
1+
VERSION=v0.2.8
22

33
OUT_DIR=dist
44
YEAR?=$(shell date +"%Y")

cmd/commands/account.go

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,10 @@ import (
1919
"fmt"
2020
"github.com/codefresh-io/cli-v2/internal/kube"
2121
"github.com/codefresh-io/cli-v2/internal/log"
22+
"github.com/codefresh-io/cli-v2/internal/store"
2223
"github.com/codefresh-io/cli-v2/internal/util"
2324
"github.com/codefresh-io/cli-v2/internal/util/helm"
25+
kubeutil "github.com/codefresh-io/cli-v2/internal/util/kube"
2426
"github.com/codefresh-io/go-sdk/pkg/codefresh"
2527
"github.com/codefresh-io/go-sdk/pkg/graphql"
2628
platmodel "github.com/codefresh-io/go-sdk/pkg/model/platform"
@@ -75,6 +77,9 @@ func NewValidateLimitsCommand() *cobra.Command {
7577
return cfConfig.RequireAuthentication(cmd, args)
7678
},
7779
Example: util.Doc("<BIN> account validate-usage"),
80+
PreRun: func(cmd *cobra.Command, _ []string) {
81+
opts.namespace = cmd.Flag("namespace").Value.String()
82+
},
7883
RunE: func(cmd *cobra.Command, _ []string) error {
7984
ctx := cmd.Context()
8085
if opts.hook {
@@ -86,13 +91,26 @@ func NewValidateLimitsCommand() *cobra.Command {
8691
err error
8792
)
8893
if opts.hook {
89-
client, err = createPlatformClientInRuntime(ctx, opts)
94+
runtimeToken, _ := kubeutil.GetValueFromSecret(ctx, opts.kubeFactory, opts.namespace, store.Get().CFTokenSecret, "token")
95+
if runtimeToken != "" {
96+
log.G(ctx).Infof("Skip hook execution. Runtime already exists.")
97+
return nil
98+
}
99+
client, err = createPlatformClientInRuntime(ctx, &opts.HelmValidateValuesOptions)
90100
if err != nil {
91101
return err
92102
}
93103
} else {
94104
client = cfConfig.NewClient()
95105
}
106+
user, err := client.GraphQL().User().GetCurrent(cmd.Context())
107+
if err != nil {
108+
return err
109+
}
110+
if v := user.ActiveAccount.Features.GitopsPlanEnforcement; v == nil || !*v {
111+
log.G(ctx).Infof("Skip hook execution. GitopsPlanEnforcement feature is disabled.")
112+
return nil
113+
}
96114
payments := client.GraphQL().Payments()
97115
err = runValidateLimits(cmd.Context(), opts, payments)
98116
if err != nil {

cmd/commands/common.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ func checkExistingRuntimes(ctx context.Context, runtime string) error {
299299
return fmt.Errorf("runtime \"%s\" already exists", runtime)
300300
}
301301

302-
func createPlatformClientInRuntime(ctx context.Context, opts *ValidateLimitsOptions) (codefresh.Codefresh, error) {
302+
func createPlatformClientInRuntime(ctx context.Context, opts *HelmValidateValuesOptions) (codefresh.Codefresh, error) {
303303
var cfClient codefresh.Codefresh
304304
valuesFile, err := opts.helm.GetValues(opts.valuesFile, !opts.hook)
305305
if err != nil {
@@ -314,7 +314,7 @@ func createPlatformClientInRuntime(ctx context.Context, opts *ValidateLimitsOpti
314314
runtimeToken, _ := kubeutil.GetValueFromSecret(ctx, opts.kubeFactory, opts.namespace, store.Get().CFTokenSecret, "token")
315315
if runtimeToken != "" {
316316
log.G(ctx).Info("Used runtime token to validate account usage")
317-
cfClient, err = getPlatformClient(ctx, &opts.HelmValidateValuesOptions, codefreshValues, runtimeToken)
317+
cfClient, err = getPlatformClient(ctx, opts, codefreshValues, runtimeToken)
318318
if err != nil {
319319
return nil, err
320320
}
@@ -336,13 +336,13 @@ func createPlatformClientInRuntime(ctx context.Context, opts *ValidateLimitsOpti
336336
return nil, errors.New("userToken must contain either a \"token\" field, or a \"secretKeyRef\"")
337337
}
338338

339-
userToken, err = getValueFromSecretKeyRef(ctx, &opts.HelmValidateValuesOptions, secretKeyRef)
339+
userToken, err = getValueFromSecretKeyRef(ctx, opts, secretKeyRef)
340340
if err != nil {
341341
return nil, fmt.Errorf("failed getting user token from secretKeyRef: %w", err)
342342
}
343343
}
344344

345-
cfClient, err = getPlatformClient(ctx, &opts.HelmValidateValuesOptions, codefreshValues, userToken)
345+
cfClient, err = getPlatformClient(ctx, opts, codefreshValues, userToken)
346346
if err != nil {
347347
return nil, fmt.Errorf("failed creating codefresh client using user token: %w", err)
348348
}

docs/releases/release_notes.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ cf version
1515

1616
```bash
1717
# download and extract the binary
18-
curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.2.7/cf-linux-amd64.tar.gz | tar zx
18+
curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.2.8/cf-linux-amd64.tar.gz | tar zx
1919

2020
# move the binary to your $PATH
2121
mv ./cf-linux-amd64 /usr/local/bin/cf
@@ -28,7 +28,7 @@ cf version
2828

2929
```bash
3030
# download and extract the binary
31-
curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.2.7/cf-darwin-amd64.tar.gz | tar zx
31+
curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.2.8/cf-darwin-amd64.tar.gz | tar zx
3232

3333
# move the binary to your $PATH
3434
mv ./cf-darwin-amd64 /usr/local/bin/cf

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ toolchain go1.23.4
77
require (
88
github.com/Masterminds/semver/v3 v3.3.1
99
github.com/argoproj/argo-cd/v2 v2.13.4
10-
github.com/codefresh-io/go-sdk v1.4.8
10+
github.com/codefresh-io/go-sdk v1.4.9
1111
github.com/fatih/color v1.18.0
1212
github.com/gobuffalo/packr v1.30.1
1313
github.com/golang/mock v1.6.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,8 @@ github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDk
106106
github.com/cloudflare/circl v1.3.7 h1:qlCDlTPz2n9fu58M0Nh1J/JzcFpfgkFHHX3O35r5vcU=
107107
github.com/cloudflare/circl v1.3.7/go.mod h1:sRTcRWXGLrKw6yIGJ+l7amYJFfAXbZG0kBSc8r4zxgA=
108108
github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
109-
github.com/codefresh-io/go-sdk v1.4.8 h1:N0HXSmhjrZ8rJiOXEqVLVoyLWdTZtS5fSaWhQR8ZzdA=
110-
github.com/codefresh-io/go-sdk v1.4.8/go.mod h1:9h1dhKQVupmt/66gWChokPfrGVFKfMMAxcfvPzh4r0U=
109+
github.com/codefresh-io/go-sdk v1.4.9 h1:W6Y4CmCTx8Y1jX24tkvdzfneAjKAE9w/ApAC6LT4BEY=
110+
github.com/codefresh-io/go-sdk v1.4.9/go.mod h1:9h1dhKQVupmt/66gWChokPfrGVFKfMMAxcfvPzh4r0U=
111111
github.com/containerd/cgroups v1.1.0 h1:v8rEWFl6EoqHB+swVNjVoCJE8o3jX7e8nqBGPLaDFBM=
112112
github.com/containerd/cgroups v1.1.0/go.mod h1:6ppBcbh/NOOUU+dMKrykgaBnK9lCIBxHqJDGwsa1mIw=
113113
github.com/containerd/containerd v1.7.27 h1:yFyEyojddO3MIGVER2xJLWoCIn+Up4GaHFquP7hsFII=

0 commit comments

Comments
 (0)