Skip to content

Commit 752b573

Browse files
CR-21047-helm-migrate (#717)
## What added "migrate" command ## Why migrate cli-runtime resources to helm-runtime structure (git-sources and remote argo-rollouts installations) ## Notes also updated go.mod and dockerfile to use golang 1.21.3 --------- Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
1 parent c4160f4 commit 752b573

30 files changed

+1349
-266
lines changed

CODEOWNERS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1+

Dockerfile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM golang:1.19-alpine3.16 as base
1+
FROM golang:1.21.4-alpine3.18 as base
22

33
WORKDIR /go/src/github.com/codefresh-io/cli-v2
44

@@ -26,7 +26,7 @@ RUN go mod verify
2626

2727
############################### CLI ###############################
2828
### Compile
29-
FROM golang:1.19-alpine3.16 as codefresh-build
29+
FROM golang:1.21.4-alpine3.18 as codefresh-build
3030

3131
WORKDIR /go/src/github.com/codefresh-io/cli-v2
3232

@@ -44,7 +44,7 @@ ARG SEGMENT_WRITE_KEY
4444
RUN make local DEV_MODE=false SEGMENT_WRITE_KEY=${SEGMENT_WRITE_KEY}
4545

4646
### Run
47-
FROM alpine:3.16 as codefresh
47+
FROM alpine:3.18 as codefresh
4848

4949
WORKDIR /go/src/github.com/codefresh-io/cli-v2
5050

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
VERSION=v0.1.51
1+
VERSION=v0.1.52
22

33
OUT_DIR=dist
44
YEAR?=$(shell date +"%Y")
@@ -176,4 +176,4 @@ $(GOBIN)/mockgen:
176176
$(GOBIN)/golangci-lint:
177177
@mkdir dist || true
178178
@echo installing: golangci-lint
179-
@curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(GOBIN) v1.52.2
179+
@curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(GOBIN) v1.55.2

build/Dockerfile.helper

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM golang:1.21.1-alpine3.18
1+
FROM golang:1.21.4-alpine3.18
22

33
RUN apk -U add --no-cache \
44
bash \
@@ -12,14 +12,14 @@ RUN apk -U add --no-cache \
1212
openssl \
1313
&& update-ca-certificates
1414

15-
ARG GH_VERSION=2.35.0
15+
ARG GH_VERSION=2.38.0
1616
RUN curl -L https://github.com/cli/cli/releases/download/v${GH_VERSION}/gh_${GH_VERSION}_linux_amd64.tar.gz --output gh.tar.gz \
1717
&& tar -xzf gh.tar.gz \
1818
&& mv gh_${GH_VERSION}_linux_amd64/bin/gh /usr/local/bin \
1919
&& rm gh.tar.gz \
2020
&& rm -rf gh_${GH_VERSION}_linux_amd64
2121

22-
ARG KUSTOMIZE_VERSION=5.1.1
22+
ARG KUSTOMIZE_VERSION=5.2.1
2323
RUN curl -Ls https://github.com/kubernetes-sigs/kustomize/releases/download/kustomize%2Fv${KUSTOMIZE_VERSION}/kustomize_v${KUSTOMIZE_VERSION}_linux_amd64.tar.gz --output kustomize.tar.gz \
2424
&& tar -xzf kustomize.tar.gz \
2525
&& mv ./kustomize /usr/bin \

build/ci.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ steps:
2020
prepare_env_vars: &deps
2121
stage: Prepare
2222
title: prepare-env
23-
image: quay.io/codefresh/golang-ci-helper:1.20.3
23+
image: quay.io/codefresh/golang-ci-helper:1.21.4
2424
commands:
2525
- cf_export GO111MODULE=on
2626
- cf_export GOCACHE=/codefresh/volume/gocache # change gopath to codefresh shared volume

cmd/commands/cluster.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ func newClusterAddCommand() *cobra.Command {
121121

122122
ctx := cmd.Context()
123123

124-
opts.runtimeName, err = ensureRuntimeName(ctx, args, true)
124+
opts.runtimeName, err = ensureRuntimeName(ctx, args, nil)
125125
if err != nil {
126126
return err
127127
}
@@ -451,7 +451,7 @@ func newClusterRemoveCommand() *cobra.Command {
451451

452452
ctx := cmd.Context()
453453

454-
opts.runtimeName, err = ensureRuntimeName(ctx, args, true)
454+
opts.runtimeName, err = ensureRuntimeName(ctx, args, nil)
455455
if err != nil {
456456
return err
457457
}
@@ -523,12 +523,12 @@ func runClusterList(ctx context.Context, runtimeName string) error {
523523

524524
sort.SliceStable(clusters, func(i, j int) bool {
525525
c1 := clusters[i]
526-
if c1.Metadata.Name == "in-cluster" {
526+
if c1.Metadata.Name == store.Get().InClusterName {
527527
return true
528528
}
529529

530530
c2 := clusters[j]
531-
if c2.Metadata.Name == "in-cluster" {
531+
if c2.Metadata.Name == store.Get().InClusterName {
532532
return false
533533
}
534534

@@ -597,7 +597,7 @@ func newClusterCreateArgoRolloutsCommand() *cobra.Command {
597597
PreRunE: func(cmd *cobra.Command, args []string) error {
598598
var err error
599599

600-
opts.runtimeName, err = ensureRuntimeName(cmd.Context(), args, true)
600+
opts.runtimeName, err = ensureRuntimeName(cmd.Context(), args, nil)
601601
return err
602602
},
603603
RunE: func(cmd *cobra.Command, _ []string) error {

cmd/commands/common.go

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ func getRepoFromUserInput(cmd *cobra.Command) error {
179179
return cmd.Flags().Set("repo", repoInput)
180180
}
181181

182-
func ensureRuntimeName(ctx context.Context, args []string, allowManaged bool) (string, error) {
182+
func ensureRuntimeName(ctx context.Context, args []string, filter func(runtime *platmodel.Runtime) bool) (string, error) {
183183
var (
184184
runtimeName string
185185
err error
@@ -190,7 +190,7 @@ func ensureRuntimeName(ctx context.Context, args []string, allowManaged bool) (s
190190
}
191191

192192
if !store.Get().Silent {
193-
runtimeName, err = getRuntimeNameFromUserSelect(ctx, allowManaged)
193+
runtimeName, err = getRuntimeNameFromUserSelect(ctx, filter)
194194
if err != nil {
195195
return "", err
196196
}
@@ -203,7 +203,7 @@ func ensureRuntimeName(ctx context.Context, args []string, allowManaged bool) (s
203203
return runtimeName, nil
204204
}
205205

206-
func getRuntimeNameFromUserSelect(ctx context.Context, allowManaged bool) (string, error) {
206+
func getRuntimeNameFromUserSelect(ctx context.Context, filter func(runtime *platmodel.Runtime) bool) (string, error) {
207207
runtimes, err := cfConfig.NewClient().V2().Runtime().List(ctx)
208208
if err != nil {
209209
return "", err
@@ -213,35 +213,34 @@ func getRuntimeNameFromUserSelect(ctx context.Context, allowManaged bool) (strin
213213
return "", fmt.Errorf("no runtimes were found")
214214
}
215215

216-
var runtimeNames []string
217-
218-
for _, rt := range runtimes {
219-
rtDisplay := rt.Metadata.Name
220-
if rt.Managed {
221-
if !allowManaged {
222-
// preventing hosted runtimes to prompt
223-
continue
216+
var filteredRuntimes []platmodel.Runtime
217+
if filter != nil {
218+
filteredRuntimes = make([]platmodel.Runtime, 0)
219+
for _, rt := range runtimes {
220+
if filter(&rt) {
221+
filteredRuntimes = append(filteredRuntimes, rt)
224222
}
225-
rtDisplay = fmt.Sprintf("%s (hosted)", rtDisplay)
226223
}
227-
runtimeNames = append(runtimeNames, rtDisplay)
224+
} else {
225+
filteredRuntimes = runtimes
228226
}
229227

230228
templates := &promptui.SelectTemplates{
231-
Selected: "{{ . | yellow }} ",
229+
Active: fmt.Sprintf("%s {{ .Metadata.Name | underline }}{{ if ne .InstallationType \"HELM\" }}{{ printf \" (%%s)\" .InstallationType | underline }}{{ end }}", promptui.IconSelect),
230+
Inactive: " {{ .Metadata.Name }}{{ if ne .InstallationType \"HELM\" }}{{ printf \" (%s)\" .InstallationType }}{{ end }}",
231+
Selected: "{{ .Metadata.Name | yellow }}",
232232
}
233233

234234
labelStr := fmt.Sprintf("%vSelect runtime%v", CYAN, COLOR_RESET)
235235

236236
prompt := promptui.Select{
237237
Label: labelStr,
238-
Items: runtimeNames,
238+
Items: filteredRuntimes,
239239
Templates: templates,
240240
}
241241

242-
_, result, err := prompt.Run()
243-
resultSplit := strings.Split(result, " ")
244-
return resultSplit[0], err
242+
i, _, err := prompt.Run()
243+
return filteredRuntimes[i].Metadata.Name, err
245244
}
246245

247246
func getRuntimeNameFromUserInput() (string, error) {

cmd/commands/git-source.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ func RunGitSourceCreate(ctx context.Context, opts *GitSourceCreateOptions) error
236236
err = appProxy.AppProxyGitSources().Create(ctx, &apmodel.CreateGitSourceInput{
237237
AppName: opts.GsName,
238238
AppSpecifier: appSpecifier,
239-
DestServer: store.Get().InCluster,
239+
DestServer: store.Get().InClusterServerURL,
240240
DestNamespace: &opts.RuntimeNamespace,
241241
IsInternal: &isInternal,
242242
Include: &opts.Include,

cmd/commands/helm.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626

2727
cfgit "github.com/codefresh-io/cli-v2/pkg/git"
2828
"github.com/codefresh-io/cli-v2/pkg/log"
29+
"github.com/codefresh-io/cli-v2/pkg/store"
2930
"github.com/codefresh-io/cli-v2/pkg/util"
3031
"github.com/codefresh-io/cli-v2/pkg/util/helm"
3132
"github.com/codefresh-io/cli-v2/pkg/util/kube"
@@ -49,10 +50,6 @@ type (
4950
}
5051
)
5152

52-
const (
53-
CODEFRESH_TOKEN = "codefresh-token"
54-
)
55-
5653
var (
5754
ErrRuntimeTokenNotFound = errors.New("runtime token not found")
5855
)
@@ -97,7 +94,7 @@ func NewHelmValidateValuesCommand() *cobra.Command {
9794

9895
cmd.Flags().StringVarP(&opts.valuesFile, "values", "f", "", "specify values in a YAML file or a URL")
9996
cmd.Flags().BoolVar(&opts.hook, "hook", false, "set to true when running inside a helm-hook")
100-
opts.helm = helm.AddFlags(cmd.Flags())
97+
opts.helm, _ = helm.AddFlags(cmd.Flags())
10198
opts.kubeFactory = apkube.AddFlags(cmd.Flags())
10299

103100
util.Die(cmd.Flags().MarkHidden("hook"))
@@ -165,7 +162,7 @@ func checkPlatform(ctx context.Context, opts *HelmValidateValuesOptions, values
165162
}
166163

167164
func validateWithRuntimeToken(ctx context.Context, opts *HelmValidateValuesOptions, codefreshValues chartutil.Values, runtimeName string) error {
168-
runtimeToken, _ := kube.GetValueFromSecret(ctx, opts.kubeFactory, opts.namespace, CODEFRESH_TOKEN, "token")
165+
runtimeToken, _ := kube.GetValueFromSecret(ctx, opts.kubeFactory, opts.namespace, store.Get().CFTokenSecret, "token")
169166
if runtimeToken == "" {
170167
return ErrRuntimeTokenNotFound
171168
}
@@ -201,7 +198,7 @@ func validateWithUserToken(ctx context.Context, opts *HelmValidateValuesOptions,
201198
return "", "", err
202199
}
203200

204-
if !user.IsActiveAccountAdmin() {
201+
if !user.IsActiveAccountAdmin() {
205202
return "", "", fmt.Errorf("user \"%s\" does not have Admin role in account \"%s\"", user.Name, *user.ActiveAccount.Name)
206203
}
207204

@@ -565,3 +562,7 @@ func getValueFromSecretKeyRef(ctx context.Context, opts *HelmValidateValuesOptio
565562

566563
return kube.GetValueFromSecret(ctx, opts.kubeFactory, opts.namespace, name, key)
567564
}
565+
566+
func filterOnlyClidRuntime(rt *platmodel.Runtime) bool {
567+
return rt.InstallationType == platmodel.InstallationTypeCli
568+
}

0 commit comments

Comments
 (0)