From dd12f046d13b404a5d1edfe11fef73b51aed8a39 Mon Sep 17 00:00:00 2001 From: danielm-codefresh Date: Sat, 5 Nov 2022 21:57:43 +0200 Subject: [PATCH] wip --- Makefile | 6 +++--- cmd/commands/runtime.go | 12 +++++++++-- cmd/commands/runtime_install.go | 18 +++++++++++++--- docs/releases/release_notes.md | 4 ++-- manifests/runtime.yaml | 4 ++-- pkg/runtime/runtime.go | 25 ++++++++++++---------- pkg/store/store.go | 38 +++++++++++++++++++++++++++++---- 7 files changed, 80 insertions(+), 27 deletions(-) diff --git a/Makefile b/Makefile index 3b665fd98..27475f134 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -VERSION=v0.0.569 +VERSION=v0.0.570 OUT_DIR=dist YEAR?=$(shell date +"%Y") @@ -7,11 +7,11 @@ CLI_NAME?=cf IMAGE_REPOSITORY?=quay.io IMAGE_NAMESPACE?=codefresh -RUNTIME_DEF_URL="https://github.com/codefresh-io/cli-v2/releases/latest/download/runtime.yaml" +RUNTIME_DEF_URL="https://raw.githubusercontent.com/codefresh-io/csdp-official/stable/csdp/hybrid/basic/runtime.yaml" ADD_CLUSTER_DEF_URL="https://github.com/codefresh-io/csdp-official/add-cluster/kustomize" FALLBACK_ADD_CLUSTER_DEF_URL="https://github.com/codefresh-io/cli-v2/manifests/add-cluster/kustomize" -DEV_RUNTIME_DEF_URL="/csdp/hybrid/runtime.yaml" +DEV_RUNTIME_DEF_URL="/stable/csdp/hybrid/basic/runtime.yaml" DEV_ADD_CLUSTER_DEF_URL="https://github.com/codefresh-io/csdp-official/add-cluster/kustomize" # specify dev branch using ?ref= here if you want to test a change CLI_SRCS := $(shell find . -name '*.go') diff --git a/cmd/commands/runtime.go b/cmd/commands/runtime.go index 4896ca10b..d924608f7 100644 --- a/cmd/commands/runtime.go +++ b/cmd/commands/runtime.go @@ -817,6 +817,8 @@ func NewRuntimeUpgradeCommand() *cobra.Command { finalParameters["Version"] = versionStr } + opts.runtimeDef = store.GetRuntimeDefURL(opts.versionStr) + err = validateVersionIfExists(opts.versionStr) if err != nil { return err @@ -847,10 +849,9 @@ func NewRuntimeUpgradeCommand() *cobra.Command { cmd.Flags().StringVar(&opts.versionStr, "version", "", "The runtime version to upgrade to, defaults to stable") cmd.Flags().StringVar(&opts.SuggestedSharedConfigRepo, "shared-config-repo", "", "URL to the shared configurations repo. (default: or the existing one for this account)") cmd.Flags().BoolVar(&opts.DisableTelemetry, "disable-telemetry", false, "If true, will disable analytics reporting for the upgrade process") - cmd.Flags().StringVar(&opts.runtimeDef, "runtime-def", store.RuntimeDefURL, "Install runtime from a specific manifest") + cmd.Flags().StringVar(&opts.runtimeDef, "runtime-def", "", "Install runtime from a specific manifest") cmd.Flags().BoolVar(&opts.SkipIngress, "skip-ingress", false, "Skips the creation of ingress resources") opts.CloneOpts = apu.AddCloneFlags(cmd, &apu.CloneFlagsOptions{CloneForWrite: true}) - util.Die(cmd.Flags().MarkHidden("runtime-def")) cmd.MarkFlagsMutuallyExclusive("version", "runtime-def") @@ -877,6 +878,13 @@ func runRuntimeUpgrade(ctx context.Context, opts *RuntimeUpgradeOptions) error { return err } + if newRt.Spec.RequiredCLIVersion.GreaterThan(store.Get().Version.Version) { + err = fmt.Errorf("please upgrade your cli version before upgrading to %s", newRt.Spec.Version) + } + if err != nil { + return err + } + log.G(ctx).Info("Cloning installation repository") r, fs, err := opts.CloneOpts.GetRepo(ctx) handleCliStep(reporter.UpgradeStepGetRepo, "Getting repository", err, true, false) diff --git a/cmd/commands/runtime_install.go b/cmd/commands/runtime_install.go index f8a210692..67f7c058b 100644 --- a/cmd/commands/runtime_install.go +++ b/cmd/commands/runtime_install.go @@ -222,6 +222,8 @@ func NewRuntimeInstallCommand() *cobra.Command { return util.DecorateErrorWithDocsLink(fmt.Errorf("pre installation error: %w", err), store.Get().RequirementsLink) } + installationOpts.runtimeDef = store.GetRuntimeDefURL(installationOpts.versionStr) + finalParameters = map[string]string{ "Codefresh context": cfConfig.CurrentContext, "Kube context": installationOpts.kubeContext, @@ -267,7 +269,7 @@ func NewRuntimeInstallCommand() *cobra.Command { cmd.Flags().StringToStringVar(&installationOpts.NamespaceLabels, "namespace-labels", nil, "Optional labels that will be set on the namespace resource. (e.g. \"key1=value1,key2=value2\"") cmd.Flags().StringToStringVar(&installationOpts.InternalIngressAnnotation, "internal-ingress-annotation", nil, "Add annotations to the internal ingress") cmd.Flags().StringToStringVar(&installationOpts.ExternalIngressAnnotation, "external-ingress-annotation", nil, "Add annotations to the external ingress") - cmd.Flags().StringVar(&installationOpts.runtimeDef, "runtime-def", store.RuntimeDefURL, "Install runtime from a specific manifest") + cmd.Flags().StringVar(&installationOpts.runtimeDef, "runtime-def", "", "Install runtime from a specific manifest") cmd.Flags().StringVar(&accessMode, "access-mode", string(platmodel.AccessModeIngress), "The access mode to the cluster, one of: ingress|tunnel") cmd.Flags().StringVar(&installationOpts.TunnelRegisterHost, "tunnel-register-host", "register-tunnels.cf-cd.com", "The host name for registering a new tunnel") cmd.Flags().StringVar(&installationOpts.TunnelDomain, "tunnel-domain", "tunnels.cf-cd.com", "The base domain for the tunnels") @@ -1139,8 +1141,18 @@ func preInstallationChecks(ctx context.Context, opts *RuntimeInstallOptions) (*r return nil, fmt.Errorf("failed to download runtime definition: %w", err) } - if rt.Spec.DefVersion.GreaterThan(store.Get().MaxDefVersion) { + if rt.Spec.RequiredCLIVersion == nil { + rt.Spec.RequiredCLIVersion = store.Get().Version.Version + } + + if rt.Spec.DefVersion.GreaterThan(store.Get().MaxDefVersion) || rt.Spec.RequiredCLIVersion.GreaterThan(store.Get().Version.Version) { err = fmt.Errorf("your cli version is out of date. please upgrade to the latest version before installing") + } else if rt.Spec.DefVersion.LessThan(store.Get().MaxDefVersion) || rt.Spec.RequiredCLIVersion.LessThan(store.Get().Version.Version) { + val, ok := store.Get().DefVersionComptability[rt.Spec.DefVersion.String()] + if !ok { + val = rt.Spec.RequiredCLIVersion.String() + } + err = fmt.Errorf("to install this version, please downgrade your cli to version %s", val) } handleCliStep(reporter.InstallStepRunPreCheckEnsureCliVersion, "Checking CLI version", err, true, false) @@ -2113,7 +2125,7 @@ func (opts *RuntimeInstallOptions) shouldInstallIngress() bool { } func (opts *RuntimeInstallOptions) IsCustomInstall() bool { - return opts.runtimeDef != store.RuntimeDefURL + return opts.runtimeDef != store.RuntimeDefURL && opts.runtimeDef != store.OldRuntimeDefURL } func getRuntimeDef(runtimeDef, versionStr string) string { diff --git a/docs/releases/release_notes.md b/docs/releases/release_notes.md index 48b971144..77faed688 100644 --- a/docs/releases/release_notes.md +++ b/docs/releases/release_notes.md @@ -23,7 +23,7 @@ cf version ```bash # download and extract the binary -curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.0.569/cf-linux-amd64.tar.gz | tar zx +curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.0.570/cf-linux-amd64.tar.gz | tar zx # move the binary to your $PATH mv ./cf-linux-amd64 /usr/local/bin/cf @@ -36,7 +36,7 @@ cf version ```bash # download and extract the binary -curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.0.569/cf-darwin-amd64.tar.gz | tar zx +curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.0.570/cf-darwin-amd64.tar.gz | tar zx # move the binary to your $PATH mv ./cf-darwin-amd64 /usr/local/bin/cf diff --git a/manifests/runtime.yaml b/manifests/runtime.yaml index 6f33c419e..f87fa9b99 100644 --- a/manifests/runtime.yaml +++ b/manifests/runtime.yaml @@ -4,8 +4,8 @@ metadata: name: "{{ name }}" namespace: "{{ namespace }}" spec: - defVersion: 2.1.1 - version: 0.0.569 + defVersion: 2.1.2 + version: 0.0.570 bootstrapSpecifier: github.com/codefresh-io/cli-v2.git/manifests/argo-cd components: - name: events diff --git a/pkg/runtime/runtime.go b/pkg/runtime/runtime.go index 3a7ea253d..beb978e98 100644 --- a/pkg/runtime/runtime.go +++ b/pkg/runtime/runtime.go @@ -63,6 +63,7 @@ type ( RuntimeSpec struct { DefVersion *semver.Version `json:"defVersion"` + RequiredCLIVersion *semver.Version `json:"requiredCLIVersion"` Version *semver.Version `json:"version"` BootstrapSpecifier string `json:"bootstrapSpecifier"` Components []AppDef `json:"components"` @@ -136,14 +137,14 @@ func Download(runtimeDef, name string, featuresToInstall []InstallFeature) (*Run runtime.Name = name runtime.Namespace = name - if store.Get().DevMode { - devVersion, err := runtime.Spec.Version.SetPrerelease("dev") - if err != nil { - return nil, fmt.Errorf("failed making dev prerelease version: %w", err) - } + // if store.Get().DevMode { + // devVersion, err := runtime.Spec.Version.SetPrerelease("dev") + // if err != nil { + // return nil, fmt.Errorf("failed making dev prerelease version: %w", err) + // } - runtime.Spec.Version = &devVersion - } + // runtime.Spec.Version = &devVersion + // } filteredComponets := make([]AppDef, 0) for i := range runtime.Spec.Components { @@ -487,9 +488,8 @@ func buildFullURL(urlString, ref string) string { return urlString } - host, orgRepo, _, _, _, suffix, _ := apaputil.ParseGitUrl(urlString) - repoUrl := host + orgRepo + suffix - if repoUrl != store.Get().DefaultRuntimeDefRepoURL() { + _, orgRepo, _, _, _, _, _ := apaputil.ParseGitUrl(urlString) + if store.Get().IsCustomDefURL(orgRepo) { // if the url is not from codefresh-io/cli-v2 - don't change it return urlString } @@ -497,7 +497,10 @@ func buildFullURL(urlString, ref string) string { urlObj, _ := url.Parse(urlString) v := urlObj.Query() if v.Get("ref") == "" { - v.Add("ref", "v"+ref) + if strings.Contains(urlString, "cli-v2") { + ref = "v" + ref + } + v.Add("ref", ref) urlObj.RawQuery = v.Encode() } diff --git a/pkg/store/store.go b/pkg/store/store.go index bb4eafe01..a0a54700c 100644 --- a/pkg/store/store.go +++ b/pkg/store/store.go @@ -32,10 +32,12 @@ var ( gitCommit = "" SegmentWriteKey = "" maxDefVersion = "2.1.2" - RuntimeDefURL = "https://github.com/codefresh-io/csdp-official/csdp/hybrid/runtime.yaml" + RuntimeDefURL = "https://raw.githubusercontent.com/codefresh-io/csdp-official/stable/csdp/hybrid/basic/runtime.yaml" + OldRuntimeDefURL = "https://github.com/codefresh-io/cli-v2/releases/latest/download/runtime.yaml" AddClusterDefURL = "https://github.com/codefresh-io/csdp-official/add-cluster/kustomize" FallbackAddClusterDefURL = "https://github.com/codefresh-io/cli-v2/manifests/add-cluster/kustomize" devMode = "true" + lastRuntimeVersionInCLI = "v0.0.569" ) type Version struct { @@ -89,7 +91,9 @@ type Store struct { MarketplaceGitSourceName string MarketplaceRepo string MaxDefVersion *semver.Version + LastRuntimeVersionInCLI *semver.Version RuntimeDefURL string + OldRuntimeDefURL string Version Version WaitTimeout time.Duration WorkflowName string @@ -150,6 +154,7 @@ type Store struct { IngressHost string IscRuntimesDir string DevMode bool + DefVersionComptability map[string]string } // Get returns the global store @@ -157,9 +162,25 @@ func Get() *Store { return &s } -func (s *Store) DefaultRuntimeDefRepoURL() string { - host, orgRepo, _, _, _, suffix, _ := apaputil.ParseGitUrl(s.RuntimeDefURL) - return host + orgRepo + suffix +func (s *Store) IsCustomDefURL(orgRepo string) bool { + _, runtimeDefOrgRepo, _, _, _, _, _ := apaputil.ParseGitUrl(s.RuntimeDefURL) + _, oldRuntimeDefOrgRepo, _, _, _, _, _ := apaputil.ParseGitUrl(s.OldRuntimeDefURL) + + return orgRepo != runtimeDefOrgRepo && orgRepo != oldRuntimeDefOrgRepo +} + +func GetRuntimeDefURL(versionStr string) string { + runtimeDefURL := s.RuntimeDefURL + if versionStr == "" { + return runtimeDefURL + } + + version := semver.MustParse(versionStr) + if version.Compare(s.LastRuntimeVersionInCLI) <= 0 { + runtimeDefURL = OldRuntimeDefURL + } + + return runtimeDefURL } func init() { @@ -202,7 +223,9 @@ func init() { s.LabelSelectorSealedSecret = "codefresh.io/sealing-key=true" s.AnnotationKeySyncWave = "argocd.argoproj.io/sync-wave" s.MaxDefVersion = semver.MustParse(maxDefVersion) + s.LastRuntimeVersionInCLI = semver.MustParse(lastRuntimeVersionInCLI) s.RuntimeDefURL = RuntimeDefURL + s.OldRuntimeDefURL = OldRuntimeDefURL s.MarketplaceGitSourceName = "marketplace-git-source" s.MarketplaceRepo = "https://github.com/codefresh-io/argo-hub.git" s.WaitTimeout = 8 * time.Minute @@ -258,6 +281,13 @@ func init() { s.InCluster = "https://kubernetes.default.svc" s.IscRuntimesDir = "runtimes" s.DevMode = devMode == "true" + s.DefVersionComptability = map[string]string{ + "1.0.0": "0.0.237", + "1.0.1": "0.0.510", + "2.0.0": "0.0.541", + "2.1.0": "0.0.548", + "2.1.1": "0.0.569", + } initVersion() }