Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
danielm-codefresh committed Nov 5, 2022
1 parent 32c0bc8 commit dd12f04
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 27 deletions.
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION=v0.0.569
VERSION=v0.0.570

OUT_DIR=dist
YEAR?=$(shell date +"%Y")
Expand All @@ -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-official-clone>/csdp/hybrid/runtime.yaml"
DEV_RUNTIME_DEF_URL="<local-clone-of-csdp-official>/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=<branch> here if you want to test a change

CLI_SRCS := $(shell find . -name '*.go')
Expand Down
12 changes: 10 additions & 2 deletions cmd/commands/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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: <installation-repo> 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")

Expand All @@ -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)
Expand Down
18 changes: 15 additions & 3 deletions cmd/commands/runtime_install.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions docs/releases/release_notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions manifests/runtime.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 14 additions & 11 deletions pkg/runtime/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -487,17 +488,19 @@ 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
}

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()
}

Expand Down
38 changes: 34 additions & 4 deletions pkg/store/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -150,16 +154,33 @@ type Store struct {
IngressHost string
IscRuntimesDir string
DevMode bool
DefVersionComptability map[string]string
}

// Get returns the global store
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() {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()
}
Expand Down

0 comments on commit dd12f04

Please sign in to comment.