Skip to content

Commit 4c25ce7

Browse files
move runtime definition from cli-v2 to csdp-official (#620)
* move runtime definition from cli-v2 to csdp-official * wip * codegen * fix * fix * fix * fix * add cli version constraint * fix constraint * fix * add script to get manifests location * fixes according to code review * fix
1 parent 7f5259e commit 4c25ce7

34 files changed

+126
-330
lines changed

Makefile

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
VERSION=v0.0.569
1+
VERSION=v0.1.0
22

33
OUT_DIR=dist
44
YEAR?=$(shell date +"%Y")
@@ -7,11 +7,12 @@ CLI_NAME?=cf
77
IMAGE_REPOSITORY?=quay.io
88
IMAGE_NAMESPACE?=codefresh
99

10-
RUNTIME_DEF_URL="https://github.com/codefresh-io/cli-v2/releases/latest/download/runtime.yaml"
10+
RUNTIME_DEF_URL="https://raw.githubusercontent.com/codefresh-io/csdp-official/stable/csdp/hybrid/basic/runtime.yaml"
1111
ADD_CLUSTER_DEF_URL="https://github.com/codefresh-io/csdp-official/add-cluster/kustomize"
1212
FALLBACK_ADD_CLUSTER_DEF_URL="https://github.com/codefresh-io/cli-v2/manifests/add-cluster/kustomize"
1313

14-
DEV_RUNTIME_DEF_URL="manifests/runtime.yaml"
14+
# when developing, point this to your local clone of csdp-official
15+
DEV_RUNTIME_DEF_URL="https://raw.githubusercontent.com/codefresh-io/csdp-official/stable/csdp/hybrid/basic/runtime.yaml"
1516
DEV_ADD_CLUSTER_DEF_URL="https://github.com/codefresh-io/csdp-official/add-cluster/kustomize" # specify dev branch using ?ref=<branch> here if you want to test a change
1617

1718
CLI_SRCS := $(shell find . -name '*.go')

cmd/commands/git-source.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ import (
2727
"github.com/codefresh-io/cli-v2/pkg/store"
2828
"github.com/codefresh-io/cli-v2/pkg/util"
2929
apu "github.com/codefresh-io/cli-v2/pkg/util/aputil"
30-
eventsutil "github.com/codefresh-io/cli-v2/pkg/util/events"
3130
routingutil "github.com/codefresh-io/cli-v2/pkg/util/routing"
3231
wfutil "github.com/codefresh-io/cli-v2/pkg/util/workflow"
3332

@@ -1161,10 +1160,6 @@ func createDemoGitlabSensor() *sensorsv1alpha1.Sensor {
11611160
func createDemoEventSource(name string) *eventsourcev1alpha1.EventSource {
11621161
tpl := &eventsourcev1alpha1.Template{Container: &corev1.Container{}}
11631162

1164-
if store.Get().SetDefaultResources {
1165-
eventsutil.SetDefaultResourceRequirements(tpl.Container)
1166-
}
1167-
11681163
return &eventsourcev1alpha1.EventSource{
11691164
TypeMeta: metav1.TypeMeta{
11701165
Kind: eventsourcereg.Kind,
@@ -1186,10 +1181,6 @@ func createDemoSensor(name string, triggers []sensorsv1alpha1.Trigger, dependenc
11861181
ServiceAccountName: store.Get().WorkflowTriggerServiceAccount,
11871182
}
11881183

1189-
if store.Get().SetDefaultResources {
1190-
eventsutil.SetDefaultResourceRequirements(tpl.Container)
1191-
}
1192-
11931184
return &sensorsv1alpha1.Sensor{
11941185
TypeMeta: metav1.TypeMeta{
11951186
Kind: sensorreg.Kind,

cmd/commands/runtime.go

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -768,7 +768,6 @@ func deleteRuntimeFromPlatform(ctx context.Context, opts *RuntimeUninstallOption
768768

769769
func NewRuntimeUpgradeCommand() *cobra.Command {
770770
var (
771-
versionStr string
772771
finalParameters map[string]string
773772
opts = &RuntimeUpgradeOptions{
774773
featuresToInstall: make([]runtime.InstallFeature, 0),
@@ -813,8 +812,12 @@ func NewRuntimeUpgradeCommand() *cobra.Command {
813812
"Repository URL": opts.CloneOpts.Repo,
814813
}
815814

816-
if versionStr != "" {
817-
finalParameters["Version"] = versionStr
815+
if opts.versionStr != "" {
816+
finalParameters["Version"] = opts.versionStr
817+
}
818+
819+
if opts.runtimeDef == "" {
820+
opts.runtimeDef = runtime.GetRuntimeDefURL(opts.versionStr)
818821
}
819822

820823
err = validateVersionIfExists(opts.versionStr)
@@ -844,15 +847,15 @@ func NewRuntimeUpgradeCommand() *cobra.Command {
844847
},
845848
}
846849

847-
cmd.Flags().StringVar(&opts.versionStr, "version", "", "The runtime version to upgrade to, defaults to latest")
850+
cmd.Flags().StringVar(&opts.versionStr, "version", "", "The runtime version to upgrade to, defaults to stable")
848851
cmd.Flags().StringVar(&opts.SuggestedSharedConfigRepo, "shared-config-repo", "", "URL to the shared configurations repo. (default: <installation-repo> or the existing one for this account)")
849852
cmd.Flags().BoolVar(&opts.DisableTelemetry, "disable-telemetry", false, "If true, will disable analytics reporting for the upgrade process")
850853
cmd.Flags().BoolVar(&store.Get().SetDefaultResources, "set-default-resources", false, "If true, will set default requests and limits on all of the runtime components")
851-
cmd.Flags().StringVar(&opts.runtimeDef, "runtime-def", store.RuntimeDefURL, "Install runtime from a specific manifest")
854+
cmd.Flags().StringVar(&opts.runtimeDef, "runtime-def", "", "Install runtime from a specific manifest")
852855
cmd.Flags().BoolVar(&opts.SkipIngress, "skip-ingress", false, "Skips the creation of ingress resources")
853856
opts.CloneOpts = apu.AddCloneFlags(cmd, &apu.CloneFlagsOptions{CloneForWrite: true})
854-
855857
util.Die(cmd.Flags().MarkHidden("runtime-def"))
858+
util.Die(cmd.Flags().MarkHidden("set-default-resources"))
856859
cmd.MarkFlagsMutuallyExclusive("version", "runtime-def")
857860

858861
return cmd
@@ -870,14 +873,19 @@ func runRuntimeUpgrade(ctx context.Context, opts *RuntimeUpgradeOptions) error {
870873
return fmt.Errorf("failed to download runtime definition: %w", err)
871874
}
872875

873-
if newRt.Spec.DefVersion.GreaterThan(store.Get().MaxDefVersion) {
876+
if newRt.Spec.DefVersion != nil && newRt.Spec.DefVersion.GreaterThan(store.Get().MaxDefVersion) {
874877
err = fmt.Errorf("please upgrade your cli version before upgrading to %s", newRt.Spec.Version)
875878
}
876879
handleCliStep(reporter.UpgradeStepRunPreCheckEnsureCliVersion, "Checking CLI version", err, true, false)
877880
if err != nil {
878881
return err
879882
}
880883

884+
err = runtime.CheckRuntimeVersionCompatible(newRt.Spec.RequiredCLIVersion)
885+
if err != nil {
886+
return err
887+
}
888+
881889
log.G(ctx).Info("Cloning installation repository")
882890
r, fs, err := opts.CloneOpts.GetRepo(ctx)
883891
handleCliStep(reporter.UpgradeStepGetRepo, "Getting repository", err, true, false)

cmd/commands/runtime_install.go

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,10 @@ func NewRuntimeInstallCommand() *cobra.Command {
222222
return util.DecorateErrorWithDocsLink(fmt.Errorf("pre installation error: %w", err), store.Get().RequirementsLink)
223223
}
224224

225+
if installationOpts.runtimeDef == "" {
226+
installationOpts.runtimeDef = runtime.GetRuntimeDefURL(installationOpts.versionStr)
227+
}
228+
225229
finalParameters = map[string]string{
226230
"Codefresh context": cfConfig.CurrentContext,
227231
"Kube context": installationOpts.kubeContext,
@@ -253,7 +257,7 @@ func NewRuntimeInstallCommand() *cobra.Command {
253257
cmd.Flags().StringVar(&installationOpts.GatewayNamespace, "gateway-namespace", "", "The namespace of the gateway")
254258
cmd.Flags().StringVar(&installationOpts.GitIntegrationRegistrationOpts.Token, "personal-git-token", "", "The Personal git token for your user")
255259
cmd.Flags().StringVar(&installationOpts.GitIntegrationRegistrationOpts.Username, "personal-git-user", "", "The Personal git user that match the token, required for bitbucket cloud")
256-
cmd.Flags().StringVar(&installationOpts.versionStr, "version", "", "The runtime version to install (default: latest)")
260+
cmd.Flags().StringVar(&installationOpts.versionStr, "version", "", "The runtime version to install (default: stable)")
257261
cmd.Flags().StringVar(&installationOpts.SuggestedSharedConfigRepo, "shared-config-repo", "", "URL to the shared configurations repo. (default: <installation-repo> or the existing one for this account)")
258262
cmd.Flags().BoolVar(&installationOpts.InstallDemoResources, "demo-resources", true, "Installs demo resources (default: true)")
259263
cmd.Flags().BoolVar(&installationOpts.SkipClusterChecks, "skip-cluster-checks", false, "Skips the cluster's checks")
@@ -268,7 +272,7 @@ func NewRuntimeInstallCommand() *cobra.Command {
268272
cmd.Flags().StringToStringVar(&installationOpts.NamespaceLabels, "namespace-labels", nil, "Optional labels that will be set on the namespace resource. (e.g. \"key1=value1,key2=value2\"")
269273
cmd.Flags().StringToStringVar(&installationOpts.InternalIngressAnnotation, "internal-ingress-annotation", nil, "Add annotations to the internal ingress")
270274
cmd.Flags().StringToStringVar(&installationOpts.ExternalIngressAnnotation, "external-ingress-annotation", nil, "Add annotations to the external ingress")
271-
cmd.Flags().StringVar(&installationOpts.runtimeDef, "runtime-def", store.RuntimeDefURL, "Install runtime from a specific manifest")
275+
cmd.Flags().StringVar(&installationOpts.runtimeDef, "runtime-def", "", "Install runtime from a specific manifest")
272276
cmd.Flags().StringVar(&accessMode, "access-mode", string(platmodel.AccessModeIngress), "The access mode to the cluster, one of: ingress|tunnel")
273277
cmd.Flags().StringVar(&installationOpts.TunnelRegisterHost, "tunnel-register-host", "register-tunnels.cf-cd.com", "The host name for registering a new tunnel")
274278
cmd.Flags().StringVar(&installationOpts.TunnelDomain, "tunnel-domain", "tunnels.cf-cd.com", "The base domain for the tunnels")
@@ -293,6 +297,7 @@ func NewRuntimeInstallCommand() *cobra.Command {
293297
util.Die(cmd.Flags().MarkHidden("tunnel-domain"))
294298
util.Die(cmd.Flags().MarkHidden("ips-allow-list"))
295299
util.Die(cmd.Flags().MarkHidden("runtime-def"))
300+
util.Die(cmd.Flags().MarkHidden("set-default-resources"))
296301
cmd.MarkFlagsMutuallyExclusive("runtime-def", "version")
297302
cmd.MarkFlagsMutuallyExclusive("runtime-def", "set-default-resources")
298303

@@ -1141,8 +1146,15 @@ func preInstallationChecks(ctx context.Context, opts *RuntimeInstallOptions) (*r
11411146
return nil, fmt.Errorf("failed to download runtime definition: %w", err)
11421147
}
11431148

1144-
if rt.Spec.DefVersion.GreaterThan(store.Get().MaxDefVersion) {
1145-
err = fmt.Errorf("your cli version is out of date. please upgrade to the latest version before installing")
1149+
if rt.Spec.DefVersion != nil {
1150+
if rt.Spec.DefVersion.GreaterThan(store.Get().MaxDefVersion) {
1151+
err = fmt.Errorf("your cli version is out of date. please upgrade to the latest version before installing")
1152+
} else if rt.Spec.DefVersion.LessThan(store.Get().MaxDefVersion) {
1153+
val := store.Get().DefVersionToLastCLIVersion[rt.Spec.DefVersion.String()]
1154+
err = fmt.Errorf("to install this version, please downgrade your cli to version %s", val)
1155+
}
1156+
} else {
1157+
err = runtime.CheckRuntimeVersionCompatible(rt.Spec.RequiredCLIVersion)
11461158
}
11471159

11481160
handleCliStep(reporter.InstallStepRunPreCheckEnsureCliVersion, "Checking CLI version", err, true, false)
@@ -2115,7 +2127,7 @@ func (opts *RuntimeInstallOptions) shouldInstallIngress() bool {
21152127
}
21162128

21172129
func (opts *RuntimeInstallOptions) IsCustomInstall() bool {
2118-
return opts.runtimeDef != store.RuntimeDefURL
2130+
return opts.runtimeDef != store.RuntimeDefURL && opts.runtimeDef != store.OldRuntimeDefURL
21192131
}
21202132

21212133
func getRuntimeDef(runtimeDef, versionStr string) string {
@@ -2135,6 +2147,9 @@ func getRuntimeDef(runtimeDef, versionStr string) string {
21352147
return runtimeDef
21362148
}
21372149

2138-
// specific version means the runtimeDef is the default value in cli-v2 repo
2139-
return strings.Replace(runtimeDef, "/releases/latest/download", "/releases/download/v"+version.String(), 1)
2150+
// specific version means the runtimeDef is the default value in cli-v2/csdp-official repo
2151+
if strings.Contains(runtimeDef, "cli-v2") {
2152+
return strings.Replace(runtimeDef, "/releases/latest/download", "/releases/download/v"+version.String(), 1)
2153+
}
2154+
return runtimeDef + "?ref=v" + version.String()
21402155
}

docs/commands/cli-v2_runtime_install.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,11 @@ cli-v2 runtime install [runtime_name] [flags]
5151
--provider string The git provider, one of: azure|bitbucket|bitbucket-server|gitea|github|gitlab
5252
--provider-api-url string Git provider API url
5353
--repo string Repository URL [GIT_REPO]
54-
--set-default-resources If true, will set default requests and limits on all of the runtime components
5554
--shared-config-repo string URL to the shared configurations repo. (default: <installation-repo> or the existing one for this account)
5655
--skip-cluster-checks Skips the cluster's checks
5756
--skip-ingress Skips the creation of ingress resources
5857
-b, --upsert-branch If true will try to checkout the specified branch and create it if it doesn't exist
59-
--version string The runtime version to install (default: latest)
58+
--version string The runtime version to install (default: stable)
6059
--wait-timeout duration How long to wait for the runtime components to be ready (default 8m0s)
6160
```
6261

docs/commands/cli-v2_runtime_upgrade.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,10 @@ cli-v2 runtime upgrade [RUNTIME_NAME] [flags]
3333
-u, --git-user string Your git provider user name [GIT_USER] (not required in GitHub)
3434
-h, --help help for upgrade
3535
--repo string Repository URL [GIT_REPO]
36-
--set-default-resources If true, will set default requests and limits on all of the runtime components
3736
--shared-config-repo string URL to the shared configurations repo. (default: <installation-repo> or the existing one for this account)
3837
--skip-ingress Skips the creation of ingress resources
3938
-b, --upsert-branch If true will try to checkout the specified branch and create it if it doesn't exist
40-
--version string The runtime version to upgrade to, defaults to latest
39+
--version string The runtime version to upgrade to, defaults to stable
4140
```
4241

4342
### Options inherited from parent commands

docs/releases/release_notes.md

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

2424
```bash
2525
# download and extract the binary
26-
curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.0.569/cf-linux-amd64.tar.gz | tar zx
26+
curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.1.0/cf-linux-amd64.tar.gz | tar zx
2727

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

3737
```bash
3838
# download and extract the binary
39-
curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.0.569/cf-darwin-amd64.tar.gz | tar zx
39+
curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.1.0/cf-darwin-amd64.tar.gz | tar zx
4040

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

hack/build.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,5 @@ go build -ldflags=" \
1616
-X 'github.com/codefresh-io/cli-v2/pkg/store.RuntimeDefURL=${RUNTIME_DEF_URL}' \
1717
-X 'github.com/codefresh-io/cli-v2/pkg/store.AddClusterDefURL=${ADD_CLUSTER_DEF_URL}' \
1818
-X 'github.com/codefresh-io/cli-v2/pkg/store.FallbackAddClusterDefURL=${FALLBACK_ADD_CLUSTER_DEF_URL}' \
19-
-X 'github.com/codefresh-io/cli-v2/pkg/store.SegmentWriteKey=${SEGMENT_WRITE_KEY}' \
20-
-X 'github.com/codefresh-io/cli-v2/pkg/store.devMode=${DEV_MODE}'" \
19+
-X 'github.com/codefresh-io/cli-v2/pkg/store.SegmentWriteKey=${SEGMENT_WRITE_KEY}'" \
2120
-v -o ${OUT_FILE} ${MAIN}

hack/get-manifests-location.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/bash
2+
3+
REPO="https://github.com/codefresh-io/csdp-official"
4+
BRANCH="$1"
5+
6+
DEFAULT_MANIFESTS_LOCATION="https://raw.githubusercontent.com/codefresh-io/csdp-official/stable/csdp/hybrid/basic/runtime.yaml"
7+
CUSTOM_MANIFESTS_LOCATION="https://github.com/codefresh-io/csdp-official/csdp/hybrid/basic/runtime.yaml?ref=$BRANCH"
8+
9+
git ls-remote --heads ${REPO} ${BRANCH} | grep ${BRANCH} >/dev/null
10+
11+
if [ "$?" == "1" ]; then
12+
# No matching branch was found in csdp-official
13+
echo "$DEFAULT_MANIFESTS_LOCATION"
14+
exit 0
15+
fi
16+
17+
echo "$CUSTOM_MANIFESTS_LOCATION"

manifests/default-resources/app-proxy/kustomization.yaml

Lines changed: 0 additions & 4 deletions
This file was deleted.

manifests/default-resources/argo-cd/argocd-resources.argocd-application-controller.jsonpatch.yaml

Lines changed: 0 additions & 9 deletions
This file was deleted.

manifests/default-resources/argo-cd/argocd-resources.argocd-applicationset-controller.jsonpatch.yaml

Lines changed: 0 additions & 9 deletions
This file was deleted.

manifests/default-resources/argo-cd/argocd-resources.argocd-dex-server.jsonpatch.yaml

Lines changed: 0 additions & 9 deletions
This file was deleted.

manifests/default-resources/argo-cd/argocd-resources.argocd-redis.jsonpatch.yaml

Lines changed: 0 additions & 9 deletions
This file was deleted.

manifests/default-resources/argo-cd/argocd-resources.argocd-repo-server.jsonpatch.yaml

Lines changed: 0 additions & 9 deletions
This file was deleted.

manifests/default-resources/argo-cd/argocd-resources.argocd-server.jsonpatch.yaml

Lines changed: 0 additions & 9 deletions
This file was deleted.

manifests/default-resources/argo-cd/kustomization.yaml

Lines changed: 0 additions & 42 deletions
This file was deleted.

manifests/default-resources/argo-events/eventbus-controller.jsonpatch.yaml

Lines changed: 0 additions & 9 deletions
This file was deleted.

manifests/default-resources/argo-events/eventbus.jsonpatch.yaml

Lines changed: 0 additions & 9 deletions
This file was deleted.

manifests/default-resources/argo-events/events-webhook.jsonpatch.yaml

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)