Skip to content

Commit b8bdf28

Browse files
authored
CR-14855-custom-runtime-manifest (#598)
* support --runtime-def flag
1 parent 947b0ae commit b8bdf28

File tree

11 files changed

+125
-85
lines changed

11 files changed

+125
-85
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.539
1+
VERSION=v0.0.540
22

33
OUT_DIR=dist
44
YEAR?=$(shell date +"%Y")
@@ -99,15 +99,16 @@ $(OUT_DIR)/$(CLI_NAME)-%.sha256:
9999

100100
$(OUT_DIR)/$(CLI_NAME)-%: $(CLI_SRCS)
101101
@GO_FLAGS=$(GO_FLAGS) \
102-
BUILD_DATE=$(BUILD_DATE) \
103102
BINARY_NAME=$(CLI_NAME) \
104103
VERSION=$(VERSION) \
104+
BUILD_DATE=$(BUILD_DATE) \
105105
GIT_COMMIT=$(GIT_COMMIT) \
106-
OUT_FILE=$(OUT_DIR)/$(CLI_NAME)-$* \
107106
RUNTIME_DEF_URL=$(RUNTIME_DEF_URL) \
108107
ADD_CLUSTER_DEF_URL=$(ADD_CLUSTER_DEF_URL) \
109108
FALLBACK_ADD_CLUSTER_DEF_URL=$(FALLBACK_ADD_CLUSTER_DEF_URL) \
110109
SEGMENT_WRITE_KEY=$(SEGMENT_WRITE_KEY) \
110+
DEV_MODE=$(DEV_MODE) \
111+
OUT_FILE=$(OUT_DIR)/$(CLI_NAME)-$* \
111112
MAIN=./cmd \
112113
./hack/build.sh
113114

cmd/commands/runtime.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ type (
7474
CommonConfig *runtime.CommonConfig
7575
SuggestedSharedConfigRepo string
7676
DisableTelemetry bool
77+
runtimeDef string
7778

7879
featuresToInstall []runtime.InstallFeature
7980
}
@@ -819,8 +820,12 @@ func NewRuntimeUpgradeCommand() *cobra.Command {
819820
cmd.Flags().StringVar(&opts.SuggestedSharedConfigRepo, "shared-config-repo", "", "URL to the shared configurations repo. (default: <installation-repo> or the existing one for this account)")
820821
cmd.Flags().BoolVar(&opts.DisableTelemetry, "disable-telemetry", false, "If true, will disable analytics reporting for the upgrade process")
821822
cmd.Flags().BoolVar(&store.Get().SetDefaultResources, "set-default-resources", false, "If true, will set default requests and limits on all of the runtime components")
823+
cmd.Flags().StringVar(&opts.runtimeDef, "runtime-def", store.RuntimeDefURL, "Install runtime from a specific manifest")
822824
opts.CloneOpts = apu.AddCloneFlags(cmd, &apu.CloneFlagsOptions{CloneForWrite: true})
823825

826+
util.Die(cmd.Flags().MarkHidden("runtime-def"))
827+
cmd.MarkFlagsMutuallyExclusive("version", "runtime-def")
828+
824829
return cmd
825830
}
826831

@@ -829,7 +834,8 @@ func runRuntimeUpgrade(ctx context.Context, opts *RuntimeUpgradeOptions) error {
829834

830835
log.G(ctx).Info("Downloading runtime definition")
831836

832-
newRt, err := runtime.Download(opts.Version, opts.RuntimeName, opts.featuresToInstall)
837+
runtimeDef := getRuntimeDef(opts.runtimeDef, opts.Version.String())
838+
newRt, err := runtime.Download(runtimeDef, opts.RuntimeName, opts.featuresToInstall)
833839
handleCliStep(reporter.UpgradeStepDownloadRuntimeDefinition, "Downloading runtime definition", err, true, false)
834840
if err != nil {
835841
return fmt.Errorf("failed to download runtime definition: %w", err)

cmd/commands/runtime_install.go

Lines changed: 57 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@ type (
9393
DisableRollback bool
9494
DisableTelemetry bool
9595
FromRepo bool
96-
Version *semver.Version
9796
GsCloneOpts *apgit.CloneOptions
9897
InsCloneOpts *apgit.CloneOptions
9998
GitIntegrationCreationOpts *apmodel.AddGitIntegrationArgs
@@ -119,6 +118,7 @@ type (
119118
gitProvider cfgit.Provider
120119
useGatewayAPI bool
121120
featuresToInstall []runtime.InstallFeature
121+
runtimeDef string
122122
}
123123

124124
tunnelServer struct {
@@ -254,6 +254,7 @@ func NewRuntimeInstallCommand() *cobra.Command {
254254
cmd.Flags().StringToStringVar(&installationOpts.InternalIngressAnnotation, "internal-ingress-annotation", nil, "Add annotations to the internal ingress")
255255
cmd.Flags().StringToStringVar(&installationOpts.ExternalIngressAnnotation, "external-ingress-annotation", nil, "Add annotations to the external ingress")
256256
cmd.Flags().BoolVar(&installationOpts.EnableGitProviders, "enable-git-providers", false, "Enable git providers (bitbucket|bitbucket-server|gitlab)")
257+
cmd.Flags().StringVar(&installationOpts.runtimeDef, "runtime-def", store.RuntimeDefURL, "Install runtime from a specific manifest")
257258
cmd.Flags().StringVar(&accessMode, "access-mode", string(platmodel.AccessModeIngress), "The access mode to the cluster, one of: ingress|tunnel")
258259
cmd.Flags().StringVar(&installationOpts.TunnelRegisterHost, "tunnel-register-host", "register-tunnels.cf-cd.com", "The host name for registering a new tunnel")
259260
cmd.Flags().StringVar(&installationOpts.TunnelDomain, "tunnel-domain", "tunnels.cf-cd.com", "The base domain for the tunnels")
@@ -278,6 +279,9 @@ func NewRuntimeInstallCommand() *cobra.Command {
278279
util.Die(cmd.Flags().MarkHidden("tunnel-register-host"))
279280
util.Die(cmd.Flags().MarkHidden("tunnel-domain"))
280281
util.Die(cmd.Flags().MarkHidden("ips-allow-list"))
282+
util.Die(cmd.Flags().MarkHidden("runtime-def"))
283+
cmd.MarkFlagsMutuallyExclusive("runtime-def", "version")
284+
cmd.MarkFlagsMutuallyExclusive("runtime-def", "set-default-resources")
281285

282286
return cmd
283287
}
@@ -288,12 +292,8 @@ func runtimeInstallCommandPreRunHandler(cmd *cobra.Command, opts *RuntimeInstall
288292

289293
handleCliStep(reporter.InstallPhasePreCheckStart, "Starting pre checks", nil, true, false)
290294

291-
opts.Version, err = getVersionIfExists(opts.versionStr)
295+
err = validateVersionIfExists(opts.versionStr)
292296
handleCliStep(reporter.InstallStepPreCheckValidateRuntimeVersion, "Validating runtime version", err, true, false)
293-
if err != nil {
294-
return err
295-
}
296-
297297
if opts.RuntimeName == "" {
298298
if !store.Get().Silent {
299299
opts.RuntimeName, err = getRuntimeNameFromUserInput()
@@ -597,19 +597,14 @@ func createRuntimeOnPlatform(ctx context.Context, opts *RuntimeInstallOptions, r
597597
}
598598

599599
func runRuntimeInstall(ctx context.Context, opts *RuntimeInstallOptions) error {
600-
err := preInstallationChecks(ctx, opts)
600+
rt, err := preInstallationChecks(ctx, opts)
601601
handleCliStep(reporter.InstallPhaseRunPreCheckFinish, "Pre run installation checks", err, true, true)
602602
if err != nil {
603603
return fmt.Errorf("pre installation checks failed: %w", err)
604604
}
605605

606606
handleCliStep(reporter.InstallPhaseStart, "Runtime installation phase started", nil, false, true)
607607

608-
rt, err := runtimeInstallPreparations(opts)
609-
if err != nil {
610-
return err
611-
}
612-
613608
if opts.FromRepo {
614609
// in case of a runtime recovery, we don't want to clear the repo when failure occures
615610
opts.DisableRollback = true
@@ -781,22 +776,6 @@ To complete the installation:
781776
return nil
782777
}
783778

784-
func runtimeInstallPreparations(opts *RuntimeInstallOptions) (*runtime.Runtime, error) {
785-
rt, err := runtime.Download(opts.Version, opts.RuntimeName, opts.featuresToInstall)
786-
handleCliStep(reporter.InstallStepDownloadRuntimeDefinition, "Downloading runtime definition", err, false, true)
787-
if err != nil {
788-
return nil, fmt.Errorf("failed to download runtime definition: %w", err)
789-
}
790-
791-
rt.Spec.Cluster, err = util.KubeServerByContextName(opts.kubeContext, opts.kubeconfig)
792-
handleCliStep(reporter.InstallStepGetServerAddress, "Getting kube server address", err, false, true)
793-
if err != nil {
794-
return nil, fmt.Errorf("failed to get current server address: %w", err)
795-
}
796-
797-
return rt, nil
798-
}
799-
800779
func createRuntimeComponents(ctx context.Context, opts *RuntimeInstallOptions, rt *runtime.Runtime) error {
801780
var err error
802781

@@ -1104,22 +1083,24 @@ func installComponents(ctx context.Context, opts *RuntimeInstallOptions, rt *run
11041083
return nil
11051084
}
11061085

1107-
func preInstallationChecks(ctx context.Context, opts *RuntimeInstallOptions) error {
1086+
func preInstallationChecks(ctx context.Context, opts *RuntimeInstallOptions) (*runtime.Runtime, error) {
11081087
var err error
1088+
11091089
log.G(ctx).Debug("running pre-installation checks...")
11101090

11111091
handleCliStep(reporter.InstallPhaseRunPreCheckStart, "Running pre run installation checks", nil, true, false)
11121092

11131093
err = checkIscProvider(ctx, opts.InsCloneOpts)
11141094
handleCliStep(reporter.InstallStepRunPreCheckGitProvider, "Checking Account Git Provider", err, true, true)
11151095
if err != nil {
1116-
return err
1096+
return nil, err
11171097
}
11181098

1119-
rt, err := runtime.Download(opts.Version, opts.RuntimeName, nil) // no need to send featuresToInstall, since we only use the runtime to get the DefVersion anyway
1099+
runtimeDef := getRuntimeDef(opts.runtimeDef, opts.versionStr)
1100+
rt, err := runtime.Download(runtimeDef, opts.RuntimeName, nil)
11201101
handleCliStep(reporter.InstallStepRunPreCheckDownloadRuntimeDefinition, "Downloading runtime definition", err, true, true)
11211102
if err != nil {
1122-
return fmt.Errorf("failed to download runtime definition: %w", err)
1103+
return nil, fmt.Errorf("failed to download runtime definition: %w", err)
11231104
}
11241105

11251106
if rt.Spec.DefVersion.GreaterThan(store.Get().MaxDefVersion) {
@@ -1128,38 +1109,47 @@ func preInstallationChecks(ctx context.Context, opts *RuntimeInstallOptions) err
11281109

11291110
handleCliStep(reporter.InstallStepRunPreCheckEnsureCliVersion, "Checking CLI version", err, true, false)
11301111
if err != nil {
1131-
return util.DecorateErrorWithDocsLink(err, store.Get().DownloadCliLink)
1112+
return nil, util.DecorateErrorWithDocsLink(err, store.Get().DownloadCliLink)
11321113
}
11331114

11341115
err = checkRuntimeCollisions(ctx, opts.KubeFactory, opts.RuntimeName)
11351116
handleCliStep(reporter.InstallStepRunPreCheckRuntimeCollision, "Checking for runtime collisions", err, true, false)
11361117
if err != nil {
1137-
return fmt.Errorf("runtime collision check failed: %w", err)
1118+
return nil, fmt.Errorf("runtime collision check failed: %w", err)
1119+
}
1120+
1121+
rt.Spec.Cluster, err = util.KubeServerByContextName(opts.kubeContext, opts.kubeconfig)
1122+
handleCliStep(reporter.InstallStepGetServerAddress, "Getting kube server address", err, false, true)
1123+
if err != nil {
1124+
return nil, fmt.Errorf("failed to get current server address: %w", err)
11381125
}
11391126

11401127
if !opts.FromRepo {
11411128
err = checkExistingRuntimes(ctx, opts.RuntimeName)
11421129
}
1130+
11431131
handleCliStep(reporter.InstallStepRunPreCheckExisitingRuntimes, "Checking for exisiting runtimes", err, true, false)
11441132
if err != nil {
1145-
return fmt.Errorf("existing runtime check failed: %w", err)
1133+
return nil, fmt.Errorf("existing runtime check failed: %w", err)
11461134
}
11471135

11481136
if !opts.SkipClusterChecks {
1149-
err = kubeutil.EnsureClusterRequirements(ctx, kubeutil.RuntimeInstallOptions{
1137+
err = kubeutil.EnsureClusterRequirements(ctx, kubeutil.ClusterRequirementsOptions{
11501138
KubeFactory: opts.KubeFactory,
11511139
Namespace: opts.RuntimeName,
11521140
ContextUrl: cfConfig.GetCurrentContext().URL,
11531141
AccessMode: opts.AccessMode,
11541142
TunnelRegisterHost: opts.TunnelRegisterHost,
1143+
IsCustomInstall: opts.IsCustomInstall(),
11551144
})
11561145
}
1146+
11571147
handleCliStep(reporter.InstallStepRunPreCheckValidateClusterRequirements, "Ensuring cluster requirements", err, true, false)
11581148
if err != nil {
1159-
return fmt.Errorf("validation of minimum cluster requirements failed: %w", err)
1149+
return nil, fmt.Errorf("validation of minimum cluster requirements failed: %w", err)
11601150
}
11611151

1162-
return nil
1152+
return rt, nil
11631153
}
11641154

11651155
func checkIscProvider(ctx context.Context, opts *apgit.CloneOptions) error {
@@ -2012,13 +2002,14 @@ func printPreviousVsNewConfigsToUser(previousConfigurations map[string]string, n
20122002
fmt.Printf("%vIngress host:%v %s %v--> %s%v\n", BOLD, BOLD_RESET, previousConfigurations["IngressHost"], GREEN, newConfigurations["IngressHost"], COLOR_RESET)
20132003
}
20142004

2015-
func getVersionIfExists(versionStr string) (*semver.Version, error) {
2005+
func validateVersionIfExists(versionStr string) error {
2006+
var err error
20162007
if versionStr != "" {
20172008
log.G().Infof("vesionStr: %s", versionStr)
2018-
return semver.NewVersion(versionStr)
2009+
_, err = semver.NewVersion(versionStr)
20192010
}
20202011

2021-
return nil, nil
2012+
return err
20222013
}
20232014

20242015
func initializeGitSourceCloneOpts(opts *RuntimeInstallOptions) {
@@ -2055,3 +2046,28 @@ func (opts *RuntimeInstallOptions) GetValues(name string) (string, error) {
20552046
func (opts *RuntimeInstallOptions) shouldInstallIngress() bool {
20562047
return !opts.SkipIngress && opts.AccessMode == platmodel.AccessModeIngress
20572048
}
2049+
2050+
func (opts *RuntimeInstallOptions) IsCustomInstall() bool {
2051+
return opts.runtimeDef != store.RuntimeDefURL
2052+
}
2053+
2054+
func getRuntimeDef(runtimeDef, versionStr string) string {
2055+
if !strings.HasPrefix(runtimeDef, "http") {
2056+
// runtimeDef is some local file
2057+
return runtimeDef
2058+
}
2059+
2060+
if versionStr == "" {
2061+
// no specific version string
2062+
return runtimeDef
2063+
}
2064+
2065+
version, err := semver.NewVersion(versionStr)
2066+
if err != nil {
2067+
// should not arrive here, since we check for validateVersionIfExists earlier
2068+
return runtimeDef
2069+
}
2070+
2071+
// specific version means the runtimeDef is the default value in cli-v2 repo
2072+
return strings.Replace(runtimeDef, "/releases/latest/download", "/releases/download/v"+version.String(), 1)
2073+
}

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.539/cf-linux-amd64.tar.gz | tar zx
26+
curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.0.540/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.539/cf-darwin-amd64.tar.gz | tar zx
39+
curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.0.540/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: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,6 @@ 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}'" \
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}'" \
2021
-v -o ${OUT_FILE} ${MAIN}

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: 2.0.0
8-
version: 0.0.539
8+
version: 0.0.540
99
bootstrapSpecifier: github.com/codefresh-io/cli-v2/manifests/argo-cd
1010
components:
1111
- name: events

pkg/reporter/reporter.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ func G() AnalyticsReporter {
151151
}
152152

153153
func Init(user *codefresh.User, flow FlowType) {
154-
writeKey := store.Get().SegmentWriteKey
154+
writeKey := store.SegmentWriteKey
155155
if writeKey == "" {
156156
log.G().Debug("No segment write key was provided. Using the noop reporter.")
157157
return

0 commit comments

Comments
 (0)