Skip to content

Commit 0b952d8

Browse files
authored
Git source fix (#36)
* updated argo-rollouts@1.0.4 updated argo-workflows@3.1.3 * wip * fixed appset field name * bumped to version 0.0.42 * ran codegen
1 parent e815602 commit 0b952d8

File tree

11 files changed

+32
-24
lines changed

11 files changed

+32
-24
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
VERSION=v0.0.41
1+
VERSION=v0.0.42
22
OUT_DIR=dist
33
YEAR?=$(shell date +"%Y")
44

cmd/commands/runtime.go

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ func RunRuntimeInstall(ctx context.Context, opts *RuntimeInstallOptions) error {
187187
if err != nil {
188188
return fmt.Errorf("failed to get a runtime creation response: %w", err)
189189
}
190+
190191
opts.RuntimeToken = runtimeCreationResponse.NewAccessToken
191192

192193
log.G(ctx).WithField("version", rt.Spec.Version).Infof("installing runtime '%s'", opts.RuntimeName)
@@ -203,14 +204,17 @@ func RunRuntimeInstall(ctx context.Context, opts *RuntimeInstallOptions) error {
203204
err = apcmd.RunProjectCreate(ctx, &apcmd.ProjectCreateOptions{
204205
CloneOpts: opts.insCloneOpts,
205206
ProjectName: opts.RuntimeName,
207+
Labels: map[string]string{
208+
store.Get().LabelKeyCFType: fmt.Sprintf("{{ labels.%s }}", util.EscapeAppsetFieldName(store.Get().LabelKeyCFType)),
209+
},
206210
})
207211
if err != nil {
208212
return fmt.Errorf("failed to create project: %w", err)
209213
}
210214

211215
for _, component := range rt.Spec.Components {
212216
log.G(ctx).Infof("creating component '%s'", component.Name)
213-
if err = component.CreateApp(ctx, opts.KubeFactory, opts.insCloneOpts, opts.RuntimeName, rt.Spec.Version); err != nil {
217+
if err = component.CreateApp(ctx, opts.KubeFactory, opts.insCloneOpts, opts.RuntimeName, store.Get().CFComponentType, rt.Spec.Version); err != nil {
214218
return fmt.Errorf("failed to create '%s' application: %w", component.Name, err)
215219
}
216220
}
@@ -464,7 +468,7 @@ func RunRuntimeUpgrade(ctx context.Context, opts *RuntimeUpgradeOptions) error {
464468

465469
for _, component := range newComponents {
466470
log.G(ctx).Infof("Creating app '%s'", component.Name)
467-
if err = component.CreateApp(ctx, nil, opts.CloneOpts, opts.RuntimeName, newRt.Spec.Version); err != nil {
471+
if err = component.CreateApp(ctx, nil, opts.CloneOpts, opts.RuntimeName, store.Get().CFComponentType, newRt.Spec.Version); err != nil {
468472
return fmt.Errorf("failed to create '%s' application: %w", component.Name, err)
469473
}
470474
}
@@ -504,7 +508,7 @@ func createComponentsReporter(ctx context.Context, cloneOpts *git.CloneOptions,
504508
Type: application.AppTypeDirectory,
505509
URL: cloneOpts.URL() + "/" + resPath,
506510
}
507-
if err := appDef.CreateApp(ctx, opts.KubeFactory, cloneOpts, opts.RuntimeName, nil); err != nil {
511+
if err := appDef.CreateApp(ctx, opts.KubeFactory, cloneOpts, opts.RuntimeName, store.Get().CFComponentType, nil); err != nil {
508512
return err
509513
}
510514

@@ -543,18 +547,10 @@ func updateProject(repofs fs.FS, runtimeName string) error {
543547
return err
544548
}
545549

546-
if appset.Spec.Template.Labels == nil {
547-
appset.Spec.Template.Labels = make(map[string]string)
548-
}
549-
if appset.Labels == nil {
550-
appset.Labels = make(map[string]string)
551-
}
552-
553550
if project.ObjectMeta.Labels == nil {
554551
project.ObjectMeta.Labels = make(map[string]string)
555552
}
556553

557-
appset.Spec.Template.Labels[store.Get().LabelKeyCFType] = store.Get().CFComponentType
558554
project.ObjectMeta.Labels[store.Get().LabelKeyCFType] = store.Get().CFRuntimeType
559555
return repofs.WriteYamls(projPath, project, appset)
560556
}
@@ -884,7 +880,7 @@ func createGitSource(ctx context.Context, insCloneOpts *git.CloneOptions, gsClon
884880
Type: application.AppTypeDirectory,
885881
URL: insCloneOpts.URL() + insFs.Join(insFs.Root(), resPath),
886882
}
887-
if err = appDef.CreateApp(ctx, nil, insCloneOpts, runtimeName, nil); err != nil {
883+
if err = appDef.CreateApp(ctx, nil, insCloneOpts, runtimeName, store.Get().CFGitSourceType, nil); err != nil {
888884
return fmt.Errorf("failed to create git-source: %w", err)
889885
}
890886

docs/releases/release_notes.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
### Linux
99
```bash
1010
# download and extract the binary
11-
curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.0.41/cf-linux-amd64.tar.gz | tar zx
11+
curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.0.42/cf-linux-amd64.tar.gz | tar zx
1212

1313
# move the binary to your $PATH
1414
mv ./cf-linux-amd64 /usr/local/bin/cf
@@ -20,7 +20,7 @@ cf version
2020
### Mac
2121
```bash
2222
# download and extract the binary
23-
curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.0.41/cf-darwin-amd64.tar.gz | tar zx
23+
curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.0.42/cf-darwin-amd64.tar.gz | tar zx
2424

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

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ go 1.16
55
require (
66
github.com/Masterminds/semver/v3 v3.1.1
77
github.com/argoproj-labs/applicationset v0.1.0
8-
github.com/argoproj-labs/argocd-autopilot v0.2.11
8+
github.com/argoproj-labs/argocd-autopilot v0.2.12
99
github.com/argoproj/argo-cd/v2 v2.0.3
1010
github.com/argoproj/argo-events v1.3.1
1111
github.com/argoproj/argo-workflows/v3 v3.1.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,8 @@ github.com/ardielle/ardielle-go v1.5.2/go.mod h1:I4hy1n795cUhaVt/ojz83SNVCYIGsAF
167167
github.com/ardielle/ardielle-tools v1.5.4/go.mod h1:oZN+JRMnqGiIhrzkRN9l26Cej9dEx4jeNG6A+AdkShk=
168168
github.com/argoproj-labs/applicationset v0.0.0-20210614145856-2c62537a8e5a h1:8Nm2KtOu/G7NtoAgucj4TkX8rghzwgFJGXNrAmuz7gc=
169169
github.com/argoproj-labs/applicationset v0.0.0-20210614145856-2c62537a8e5a/go.mod h1:5rxggh8ymYXedQDIYylNzIHe6jdshDNasIBCVJuR1iU=
170-
github.com/argoproj-labs/argocd-autopilot v0.2.11 h1:ysxOnVuRtvEe0Qj9apPMHcYi77oxTeu9LuZVDcOupl4=
171-
github.com/argoproj-labs/argocd-autopilot v0.2.11/go.mod h1:o+e85vsYHC7FqUgxgQMAcIOmlRmVvcAwCw/fPXPz3xY=
170+
github.com/argoproj-labs/argocd-autopilot v0.2.12 h1:xQoGlXAr6+BSRTRKg1xtAkSVBaHNoq9YvEiv6ASC31g=
171+
github.com/argoproj-labs/argocd-autopilot v0.2.12/go.mod h1:o+e85vsYHC7FqUgxgQMAcIOmlRmVvcAwCw/fPXPz3xY=
172172
github.com/argoproj/argo-cd v1.8.1/go.mod h1:Vfl7OGgBC83dVWgq58wU6UR3kG864h0dtHEIQ8xqw4s=
173173
github.com/argoproj/argo-cd v1.8.7 h1:CkIu8p/gcTY/fOZWM2tHuSCIAV2HggXjJftrT1IIT3k=
174174
github.com/argoproj/argo-cd v1.8.7/go.mod h1:tqFZW5Lr9KBCDsvOaE5Fh8M1eJ1ThvR58pyyLv8Zqvs=

manifests/argo-rollouts/kustomization.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
apiVersion: kustomize.config.k8s.io/v1beta1
22
kind: Kustomization
33
resources:
4-
- https://github.com/argoproj/argo-rollouts/releases/download/v1.0.2/install.yaml
4+
- https://github.com/argoproj/argo-rollouts/releases/download/v1.0.4/install.yaml
55
patches:
66
- target:
77
group: apiextensions.k8s.io

manifests/argo-workflows/kustomization.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
apiVersion: kustomize.config.k8s.io/v1beta1
22
kind: Kustomization
33
resources:
4-
- https://github.com/argoproj/argo-workflows/releases/download/v3.1.2/install.yaml
4+
- https://github.com/argoproj/argo-workflows/releases/download/v3.1.3/install.yaml
55

66
patches:
77
# reset the crbs to `subject.namespace: default`, so that argo-workflows will later change them to the actual ns

manifests/runtime.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ metadata:
55
namespace: "{{ namespace }}"
66
spec:
77
defVersion: 1.0.0
8-
version: 0.0.41
8+
version: 0.0.42
99
bootstrapSpecifier: github.com/codefresh-io/cli-v2/manifests/argo-cd
1010
components:
1111
- name: events

pkg/runtime/runtime.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525

2626
"github.com/codefresh-io/cli-v2/pkg/log"
2727
"github.com/codefresh-io/cli-v2/pkg/store"
28+
"github.com/codefresh-io/cli-v2/pkg/util"
2829

2930
"github.com/Masterminds/semver/v3"
3031
apcmd "github.com/argoproj-labs/argocd-autopilot/cmd/commands"
@@ -210,7 +211,7 @@ func (r *RuntimeSpec) FullSpecifier() string {
210211
return buildFullURL(r.BootstrapSpecifier, r.Version)
211212
}
212213

213-
func (a *AppDef) CreateApp(ctx context.Context, f kube.Factory, cloneOpts *git.CloneOptions, projectName string, version *semver.Version) error {
214+
func (a *AppDef) CreateApp(ctx context.Context, f kube.Factory, cloneOpts *git.CloneOptions, projectName, cfType string, version *semver.Version) error {
214215
timeout := time.Duration(0)
215216
if a.Wait {
216217
timeout = store.Get().WaitTimeout
@@ -225,6 +226,9 @@ func (a *AppDef) CreateApp(ctx context.Context, f kube.Factory, cloneOpts *git.C
225226
AppSpecifier: buildFullURL(a.URL, version),
226227
AppType: a.Type,
227228
DestNamespace: projectName,
229+
Labels: map[string]string{
230+
util.EscapeAppsetFieldName(store.Get().LabelKeyCFType): cfType,
231+
},
228232
},
229233
KubeFactory: f,
230234
Timeout: timeout,

pkg/store/store.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ type Version struct {
4545
type Store struct {
4646
BinaryName string
4747
CFComponentType string
48+
CFGitSourceType string
4849
CFRuntimeDefType string
4950
CFRuntimeType string
5051
CFTokenSecret string
@@ -72,6 +73,7 @@ func Get() *Store {
7273
func init() {
7374
s.BinaryName = binaryName
7475
s.CFComponentType = "component"
76+
s.CFGitSourceType = "git-source"
7577
s.CFRuntimeDefType = "runtimeDef"
7678
s.CFRuntimeType = "runtime"
7779
s.CFTokenSecret = "codefresh-token"

pkg/util/util.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"fmt"
2020
"os"
2121
"os/signal"
22+
"regexp"
2223
"strings"
2324
"sync"
2425
"time"
@@ -34,8 +35,9 @@ const (
3435
)
3536

3637
var (
37-
spinnerCharSet = spinner.CharSets[26]
38-
spinnerDuration = time.Millisecond * 500
38+
spinnerCharSet = spinner.CharSets[26]
39+
spinnerDuration = time.Millisecond * 500
40+
appsetFieldRegexp = regexp.MustCompile(`[\./]`)
3941
)
4042

4143
// ContextWithCancelOnSignals returns a context that is canceled when one of the specified signals
@@ -149,3 +151,7 @@ func (ar *AsyncRunner) Wait() error {
149151
return nil
150152
}
151153
}
154+
155+
func EscapeAppsetFieldName(field string) string {
156+
return appsetFieldRegexp.ReplaceAllString(field, "_")
157+
}

0 commit comments

Comments
 (0)