diff --git a/Makefile b/Makefile index 6d8ee45a..f4a6aea3 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -VERSION=v0.1.37 +VERSION=v0.1.38 OUT_DIR=dist YEAR?=$(shell date +"%Y") diff --git a/cmd/commands/git-source.go b/cmd/commands/git-source.go index ccec6363..aee58c51 100644 --- a/cmd/commands/git-source.go +++ b/cmd/commands/git-source.go @@ -57,6 +57,7 @@ type ( GsCloneOpts *git.CloneOptions GsName string RuntimeName string + RuntimeNamespace string CreateDemoResources bool Exclude string Include string @@ -186,11 +187,18 @@ func NewGitSourceCreateCommand() *cobra.Command { RunE: func(cmd *cobra.Command, args []string) error { ctx := cmd.Context() + runtimeNamespace := args[0] + namespace := cmd.Flag("namespace").Value.String() + if namespace != "" { + runtimeNamespace = namespace + } + return RunGitSourceCreate(ctx, &GitSourceCreateOptions{ GsCloneOpts: gsCloneOpts, GitProvider: gitProvider, GsName: args[1], RuntimeName: args[0], + RuntimeNamespace: runtimeNamespace, CreateDemoResources: false, Include: include, Exclude: exclude, @@ -223,7 +231,7 @@ func RunGitSourceCreate(ctx context.Context, opts *GitSourceCreateOptions) error AppName: opts.GsName, AppSpecifier: appSpecifier, DestServer: store.Get().InCluster, - DestNamespace: &opts.RuntimeName, + DestNamespace: &opts.RuntimeNamespace, IsInternal: &isInternal, Include: &opts.Include, Exclude: &opts.Exclude, @@ -1424,7 +1432,7 @@ func legacyGitSourceCreate(ctx context.Context, opts *GitSourceCreateOptions) er appDef.IsInternal = util.StringIndexOf(store.Get().CFInternalGitSources, appDef.Name) > -1 - if err := appDef.CreateApp(ctx, nil, opts.InsCloneOpts, opts.RuntimeName, store.Get().CFGitSourceType); err != nil { + if err := appDef.CreateApp(ctx, nil, opts.InsCloneOpts, opts.RuntimeName, opts.RuntimeNamespace, store.Get().CFGitSourceType); err != nil { return fmt.Errorf("failed to create git-source application. Err: %w", err) } diff --git a/cmd/commands/runtime.go b/cmd/commands/runtime.go index 6f36951a..22feeb18 100644 --- a/cmd/commands/runtime.go +++ b/cmd/commands/runtime.go @@ -56,6 +56,7 @@ import ( type ( RuntimeUninstallOptions struct { RuntimeName string + RuntimeNamespace string Timeout time.Duration CloneOpts *apgit.CloneOptions KubeFactory kube.Factory @@ -71,6 +72,7 @@ type ( RuntimeUpgradeOptions struct { RuntimeName string + RuntimeNamespace string CloneOpts *apgit.CloneOptions CommonConfig *runtime.CommonConfig SuggestedSharedConfigRepo string @@ -178,7 +180,7 @@ func runtimeUninstallCommandPreRunHandler(cmd *cobra.Command, args []string, opt return err } - if !opts.Managed { + if !opts.Managed && !opts.SkipChecks { err = ensureRepo(cmd, opts.RuntimeName, opts.CloneOpts, true) } handleCliStep(reporter.UninstallStepPreCheckEnsureRuntimeRepo, "Getting runtime repo", err, true, false) @@ -216,6 +218,8 @@ func runtimeUpgradeCommandPreRunHandler(cmd *cobra.Command, args []string, opts return err } + opts.RuntimeNamespace = *rt.Metadata.Namespace + if rt.Managed { return fmt.Errorf("manual upgrades are not allowed for hosted runtimes and are managed by Codefresh operational team") } @@ -454,6 +458,7 @@ func NewRuntimeUninstallCommand() *cobra.Command { finalParameters = map[string]string{ "Codefresh context": cfConfig.CurrentContext, "Runtime name": opts.RuntimeName, + "Runtime namespace": opts.RuntimeNamespace, } if !opts.Managed { @@ -541,7 +546,7 @@ func runRuntimeUninstall(ctx context.Context, opts *RuntimeUninstallOptions) err if !opts.Managed { err = apcmd.RunRepoUninstall(ctx, &apcmd.RepoUninstallOptions{ - Namespace: opts.RuntimeName, + Namespace: opts.RuntimeNamespace, KubeContextName: opts.kubeContext, Timeout: opts.Timeout, CloneOptions: opts.CloneOpts, @@ -577,7 +582,7 @@ func runRuntimeUninstall(ctx context.Context, opts *RuntimeUninstallOptions) err } if !opts.Managed { - err = runPostUninstallCleanup(ctx, opts.KubeFactory, opts.RuntimeName) + err = runPostUninstallCleanup(ctx, opts.KubeFactory, opts.RuntimeNamespace) if err != nil { errorMsg := fmt.Sprintf("failed to do post uninstall cleanup: %v", err) if !opts.Force { @@ -875,7 +880,7 @@ func runRuntimeUpgrade(ctx context.Context, opts *RuntimeUpgradeOptions) error { log.G(ctx).Info("Downloading runtime definition") runtimeDef := getRuntimeDef(opts.runtimeDef, opts.versionStr) - newRt, err := runtime.Download(runtimeDef, opts.RuntimeName, opts.featuresToInstall) + newRt, err := runtime.Download(runtimeDef, opts.RuntimeName, opts.RuntimeNamespace, opts.featuresToInstall) handleCliStep(reporter.UpgradeStepDownloadRuntimeDefinition, "Downloading runtime definition", err, true, false) if err != nil { return fmt.Errorf("failed to download runtime definition: %w", err) @@ -930,7 +935,7 @@ func runRuntimeUpgrade(ctx context.Context, opts *RuntimeUpgradeOptions) error { for _, component := range newComponents { log.G(ctx).Infof("Installing new component \"%s\"", component.Name) component.IsInternal = true - err = component.CreateApp(ctx, nil, opts.CloneOpts, opts.RuntimeName, store.Get().CFComponentType) + err = component.CreateApp(ctx, nil, opts.CloneOpts, opts.RuntimeName, opts.RuntimeNamespace, store.Get().CFComponentType) if err != nil { err = fmt.Errorf("failed to create \"%s\" application: %w", component.Name, err) break @@ -1156,3 +1161,22 @@ func createAnalyticsReporter(ctx context.Context, flow reporter.FlowType, disabl reporter.Init(user, flow) } + +func getRuntimeNamespace(cmd *cobra.Command, runtimeName string, runtimeVersion *semver.Version) string { + namespace := runtimeName + differentNamespaceSupportVer := semver.MustParse("0.1.26") + hasdifferentNamespaceSupport := runtimeVersion.GreaterThan(differentNamespaceSupportVer) + + if !hasdifferentNamespaceSupport { + log.G().Infof("To specify a different namespace please use runtime version >= %s", differentNamespaceSupportVer.String()) + _ = cmd.Flag("namespace").Value.Set("") + return namespace + } + + namespaceVal := cmd.Flag("namespace").Value.String() + if namespaceVal != "" { + namespace = namespaceVal + } + + return namespace +} diff --git a/cmd/commands/runtime_install.go b/cmd/commands/runtime_install.go index 6b125b92..afc79365 100644 --- a/cmd/commands/runtime_install.go +++ b/cmd/commands/runtime_install.go @@ -77,6 +77,7 @@ import ( type ( RuntimeInstallOptions struct { RuntimeName string + RuntimeNamespace string RuntimeToken string RuntimeStoreIV string HostName string @@ -195,6 +196,12 @@ func NewRuntimeInstallCommand() *cobra.Command { installationOpts.useGatewayAPI = true } + installationOpts.RuntimeNamespace = installationOpts.RuntimeName + namespace := cmd.Flag("namespace").Value.String() + if namespace != "" { + installationOpts.RuntimeNamespace = namespace + } + createAnalyticsReporter(ctx, reporter.InstallFlow, installationOpts.DisableTelemetry) if accessMode != "" { @@ -224,6 +231,7 @@ func NewRuntimeInstallCommand() *cobra.Command { "Codefresh context": cfConfig.CurrentContext, "Kube context": installationOpts.kubeContext, "Runtime name": installationOpts.RuntimeName, + "Runtime namespace": installationOpts.RuntimeNamespace, "Repository URL": installationOpts.InsCloneOpts.Repo, "Ingress class": installationOpts.IngressClass, "Installing demo resources": strconv.FormatBool(installationOpts.InstallDemoResources), @@ -246,7 +254,7 @@ func NewRuntimeInstallCommand() *cobra.Command { return nil }, RunE: func(cmd *cobra.Command, _ []string) error { - err := runRuntimeInstall(cmd.Context(), installationOpts) + err := runRuntimeInstall(cmd, installationOpts) handleCliStep(reporter.InstallPhaseFinish, "Runtime installation phase finished", err, false, false) return err }, @@ -323,7 +331,7 @@ func runtimeInstallCommandPreRunHandler(cmd *cobra.Command, opts *RuntimeInstall log.G(ctx).Info("Downloading runtime definition file") runtimeDef := getRuntimeDef(opts.runtimeDef, opts.versionStr) - rt, err := runtime.Download(runtimeDef, opts.RuntimeName, opts.featuresToInstall) + rt, err := runtime.Download(runtimeDef, opts.RuntimeName, opts.RuntimeNamespace, opts.featuresToInstall) handleCliStep(reporter.InstallStepRunPreCheckDownloadRuntimeDefinition, "Downloading runtime definition", err, true, true) if err != nil { return fmt.Errorf("failed to download runtime definition: %w", err) @@ -593,10 +601,13 @@ func createRuntimeOnPlatform(ctx context.Context, opts *RuntimeInstallOptions, r return "", "", err } + cliInstallationType := platmodel.InstallationTypeCli + provider := platmodel.GitProviders(gitProvider) repoURL := opts.InsCloneOpts.URL() runtimeArgs := &platmodel.RuntimeInstallationArgs{ RuntimeName: opts.RuntimeName, + RuntimeNamespace: opts.RuntimeNamespace, Cluster: rt.Spec.Cluster, Managed: new(bool), RuntimeVersion: rt.Spec.Version.String(), @@ -608,6 +619,7 @@ func createRuntimeOnPlatform(ctx context.Context, opts *RuntimeInstallOptions, r Recover: &opts.FromRepo, IngressHost: &opts.IngressHost, AccessMode: &opts.AccessMode, + InstallationType: &cliInstallationType, } if opts.shouldInstallIngress() { @@ -632,8 +644,9 @@ func createRuntimeOnPlatform(ctx context.Context, opts *RuntimeInstallOptions, r return runtimeCreationResponse.NewAccessToken, hex.EncodeToString(iv), nil } -func runRuntimeInstall(ctx context.Context, opts *RuntimeInstallOptions) error { - rt, err := preInstallationChecks(ctx, opts) +func runRuntimeInstall(cmd *cobra.Command, opts *RuntimeInstallOptions) error { + ctx := cmd.Context() + rt, err := preInstallationChecks(cmd, opts) handleCliStep(reporter.InstallPhaseRunPreCheckFinish, "Pre run installation checks", err, true, true) if err != nil { util.CheckNetworkErr(err) @@ -681,7 +694,7 @@ func runRuntimeInstall(ctx context.Context, opts *RuntimeInstallOptions) error { log.G(ctx).WithField("version", rt.Spec.Version).Infof("Installing runtime \"%s\"", opts.RuntimeName) err = apcmd.RunRepoBootstrap(ctx, &apcmd.RepoBootstrapOptions{ AppSpecifier: appSpecifier, - Namespace: opts.RuntimeName, + Namespace: opts.RuntimeNamespace, KubeFactory: opts.KubeFactory, CloneOptions: opts.InsCloneOpts, Insecure: opts.Insecure, @@ -708,9 +721,10 @@ func runRuntimeInstall(ctx context.Context, opts *RuntimeInstallOptions) error { } err = oc.PrepareOpenshiftCluster(ctx, &oc.OpenshiftOptions{ - KubeFactory: opts.KubeFactory, - RuntimeName: opts.RuntimeName, - InsCloneOpts: opts.InsCloneOpts, + KubeFactory: opts.KubeFactory, + RuntimeName: opts.RuntimeName, + RuntimeNamespace: opts.RuntimeNamespace, + InsCloneOpts: opts.InsCloneOpts, }) if err != nil { return fmt.Errorf("failed setting up environment for openshift %w", err) @@ -857,7 +871,7 @@ func createMasterIngressResource(ctx context.Context, opts *RuntimeInstallOption ingressOptions := routingutil.CreateRouteOpts{ Name: opts.RuntimeName + store.Get().MasterIngressName, - Namespace: opts.RuntimeName, + Namespace: opts.RuntimeNamespace, IngressClass: opts.IngressClass, Hostname: opts.HostName, Annotations: map[string]string{ @@ -893,6 +907,7 @@ func createGitSources(ctx context.Context, opts *RuntimeInstallOptions) error { GitProvider: opts.gitProvider, GsName: store.Get().GitSourceName, RuntimeName: opts.RuntimeName, + RuntimeNamespace: opts.RuntimeNamespace, CreateDemoResources: opts.InstallDemoResources, HostName: opts.HostName, SkipIngress: opts.SkipIngress, @@ -929,6 +944,7 @@ func createGitSources(ctx context.Context, opts *RuntimeInstallOptions) error { GitProvider: opts.gitProvider, GsName: store.Get().MarketplaceGitSourceName, RuntimeName: opts.RuntimeName, + RuntimeNamespace: opts.RuntimeNamespace, CreateDemoResources: false, Exclude: "**/images/**/*", Include: "workflows/**/*.yaml", @@ -1151,9 +1167,9 @@ func installComponents(ctx context.Context, opts *RuntimeInstallOptions, rt *run return nil } -func preInstallationChecks(ctx context.Context, opts *RuntimeInstallOptions) (*runtime.Runtime, error) { +func preInstallationChecks(cmd *cobra.Command, opts *RuntimeInstallOptions) (*runtime.Runtime, error) { var err error - + ctx := cmd.Context() log.G(ctx).Debug("running pre-installation checks...") handleCliStep(reporter.InstallPhaseRunPreCheckStart, "Running pre run installation checks", nil, true, false) @@ -1165,11 +1181,14 @@ func preInstallationChecks(ctx context.Context, opts *RuntimeInstallOptions) (*r } runtimeDef := getRuntimeDef(opts.runtimeDef, opts.versionStr) - rt, err := runtime.Download(runtimeDef, opts.RuntimeName, opts.featuresToInstall) + rt, err := runtime.Download(runtimeDef, opts.RuntimeName, opts.RuntimeNamespace, opts.featuresToInstall) if err != nil { return nil, fmt.Errorf("failed to download runtime definition: %w", err) } + opts.RuntimeNamespace = getRuntimeNamespace(cmd, opts.RuntimeName, rt.Spec.Version) + rt.SetNamespace(opts.RuntimeNamespace) + handleCliStep(reporter.InstallStepRunPreCheckEnsureCliVersion, "Checking CLI version", err, true, false) if err != nil { return nil, util.DecorateErrorWithDocsLink(err, store.Get().DownloadCliLink) @@ -1199,7 +1218,7 @@ func preInstallationChecks(ctx context.Context, opts *RuntimeInstallOptions) (*r if !opts.SkipClusterChecks { err = kubeutil.EnsureClusterRequirements(ctx, kubeutil.ClusterRequirementsOptions{ KubeFactory: opts.KubeFactory, - Namespace: opts.RuntimeName, + Namespace: opts.RuntimeNamespace, ContextUrl: cfConfig.GetCurrentContext().URL, AccessMode: opts.AccessMode, TunnelRegisterHost: opts.TunnelRegisterHost, @@ -1617,12 +1636,12 @@ func updateCodefreshCM(ctx context.Context, opts *RuntimeInstallOptions, rt *run } func applySecretsToCluster(ctx context.Context, opts *RuntimeInstallOptions) error { - runtimeTokenSecret, err := getRuntimeTokenSecret(opts.RuntimeName, opts.RuntimeToken, opts.RuntimeStoreIV) + runtimeTokenSecret, err := getRuntimeTokenSecret(opts.RuntimeNamespace, opts.RuntimeToken, opts.RuntimeStoreIV) if err != nil { return fmt.Errorf("failed to create codefresh token secret: %w", err) } - argoTokenSecret, err := getArgoCDTokenSecret(ctx, opts.kubeContext, opts.RuntimeName, opts.Insecure) + argoTokenSecret, err := getArgoCDTokenSecret(ctx, opts.kubeContext, opts.RuntimeNamespace, opts.Insecure) if err != nil { return fmt.Errorf("failed to create argocd token secret: %w", err) } @@ -1648,7 +1667,7 @@ func createEventsReporter(ctx context.Context, cloneOpts *apgit.CloneOptions, op URL: u.String(), IsInternal: true, } - if err := appDef.CreateApp(ctx, opts.KubeFactory, cloneOpts, opts.RuntimeName, store.Get().CFComponentType); err != nil { + if err := appDef.CreateApp(ctx, opts.KubeFactory, cloneOpts, opts.RuntimeName, opts.RuntimeNamespace, store.Get().CFComponentType); err != nil { return err } @@ -1661,12 +1680,12 @@ func createEventsReporter(ctx context.Context, cloneOpts *apgit.CloneOptions, op return err } - if err = createEventsReporterEventSource(repofs, resPath, opts.RuntimeName, opts.Insecure); err != nil { + if err = createEventsReporterEventSource(repofs, resPath, opts.RuntimeNamespace, opts.Insecure); err != nil { return err } eventsReporterTriggers := []string{"events"} - if err = createSensor(repofs, store.Get().EventsReporterName, resPath, opts.RuntimeName, store.Get().EventsReporterName, eventsReporterTriggers, "data"); err != nil { + if err = createSensor(repofs, store.Get().EventsReporterName, resPath, opts.RuntimeNamespace, store.Get().EventsReporterName, eventsReporterTriggers, "data"); err != nil { return err } @@ -1690,7 +1709,7 @@ func createReporter(ctx context.Context, cloneOpts *apgit.CloneOptions, opts *Ru URL: u.String(), IsInternal: reporterCreateOpts.IsInternal, } - if err := appDef.CreateApp(ctx, opts.KubeFactory, cloneOpts, opts.RuntimeName, store.Get().CFComponentType); err != nil { + if err := appDef.CreateApp(ctx, opts.KubeFactory, cloneOpts, opts.RuntimeName, opts.RuntimeNamespace, store.Get().CFComponentType); err != nil { return err } @@ -1704,11 +1723,11 @@ func createReporter(ctx context.Context, cloneOpts *apgit.CloneOptions, opts *Ru return err } - if err = createReporterRBAC(repofs, resPath, opts.RuntimeName, reporterCreateOpts.saName, reporterCreateOpts.clusterScope); err != nil { + if err = createReporterRBAC(repofs, resPath, opts.RuntimeNamespace, reporterCreateOpts.saName, reporterCreateOpts.clusterScope); err != nil { return err } - if err = createReporterEventSource(repofs, resPath, opts.RuntimeName, reporterCreateOpts, reporterCreateOpts.clusterScope); err != nil { + if err = createReporterEventSource(repofs, resPath, opts.RuntimeNamespace, reporterCreateOpts, reporterCreateOpts.clusterScope); err != nil { return err } var triggerNames []string @@ -1716,7 +1735,7 @@ func createReporter(ctx context.Context, cloneOpts *apgit.CloneOptions, opts *Ru triggerNames = append(triggerNames, gvr.resourceName) } - if err = createSensor(repofs, reporterCreateOpts.reporterName, resPath, opts.RuntimeName, reporterCreateOpts.reporterName, triggerNames, "data.object"); err != nil { + if err = createSensor(repofs, reporterCreateOpts.reporterName, resPath, opts.RuntimeNamespace, reporterCreateOpts.reporterName, triggerNames, "data.object"); err != nil { return err } @@ -1817,7 +1836,7 @@ func getArgoCDTokenSecret(ctx context.Context, kubeContext, namespace string, in }) } -func createReporterRBAC(repofs fs.FS, path, runtimeName, saName string, clusterScope bool) error { +func createReporterRBAC(repofs fs.FS, path, runtimeNamespace, saName string, clusterScope bool) error { serviceAccount := &v1.ServiceAccount{ TypeMeta: metav1.TypeMeta{ Kind: "ServiceAccount", @@ -1825,14 +1844,14 @@ func createReporterRBAC(repofs fs.FS, path, runtimeName, saName string, clusterS }, ObjectMeta: metav1.ObjectMeta{ Name: saName, - Namespace: runtimeName, + Namespace: runtimeNamespace, }, } roleKind := "Role" roleMeta := metav1.ObjectMeta{ Name: saName, - Namespace: runtimeName, + Namespace: runtimeNamespace, } if clusterScope { @@ -1860,7 +1879,7 @@ func createReporterRBAC(repofs fs.FS, path, runtimeName, saName string, clusterS roleBindingKind := "RoleBinding" roleBindingMeta := metav1.ObjectMeta{ Name: saName, - Namespace: runtimeName, + Namespace: runtimeNamespace, } if clusterScope { @@ -1879,7 +1898,7 @@ func createReporterRBAC(repofs fs.FS, path, runtimeName, saName string, clusterS Subjects: []rbacv1.Subject{ { Kind: "ServiceAccount", - Namespace: runtimeName, + Namespace: runtimeNamespace, Name: saName, }, }, @@ -2064,13 +2083,14 @@ func postInstallationHandler(ctx context.Context, opts *RuntimeInstallOptions, e log.G(ctx).Errorf("installation failed due to error: %s, performing installation rollback", err.Error()) util.CheckNetworkErr(err) err := runRuntimeUninstall(ctx, &RuntimeUninstallOptions{ - RuntimeName: opts.RuntimeName, - Timeout: store.Get().WaitTimeout, - CloneOpts: opts.InsCloneOpts, - KubeFactory: opts.KubeFactory, - SkipChecks: true, - Force: true, - FastExit: false, + RuntimeName: opts.RuntimeName, + RuntimeNamespace: opts.RuntimeNamespace, + Timeout: store.Get().WaitTimeout, + CloneOpts: opts.InsCloneOpts, + KubeFactory: opts.KubeFactory, + SkipChecks: true, + Force: true, + FastExit: false, }) handleCliStep(reporter.UninstallPhaseFinish, "Uninstall phase finished after rollback", err, false, true) if err != nil { diff --git a/docs/releases/release_notes.md b/docs/releases/release_notes.md index 02147aa0..bccf5c6a 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.1.37/cf-linux-amd64.tar.gz | tar zx +curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.1.38/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.1.37/cf-darwin-amd64.tar.gz | tar zx +curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.1.38/cf-darwin-amd64.tar.gz | tar zx # move the binary to your $PATH mv ./cf-darwin-amd64 /usr/local/bin/cf diff --git a/go.mod b/go.mod index 507966aa..97156f8e 100644 --- a/go.mod +++ b/go.mod @@ -9,7 +9,7 @@ require ( github.com/argoproj/argo-events v0.17.1-0.20220327045437-70eaafe9afec github.com/argoproj/argo-workflows/v3 v3.3.1 github.com/briandowns/spinner v1.18.1 - github.com/codefresh-io/go-sdk v0.51.0 + github.com/codefresh-io/go-sdk v0.52.0 github.com/fatih/color v1.13.0 github.com/ghodss/yaml v1.0.1-0.20190212211648-25d852aebe32 github.com/go-git/go-billy/v5 v5.3.1 diff --git a/go.sum b/go.sum index 318e7757..947caebf 100644 --- a/go.sum +++ b/go.sum @@ -303,8 +303,8 @@ github.com/cockroachdb/datadriven v0.0.0-20200714090401-bf6692d28da5/go.mod h1:h github.com/cockroachdb/errors v1.2.4/go.mod h1:rQD95gz6FARkaKkQXUksEje/d9a6wBJoCr5oaCLELYA= github.com/cockroachdb/logtags v0.0.0-20190617123548-eb05cc24525f/go.mod h1:i/u985jwjWRlyHXQbwatDASoW0RMlZ/3i9yJHE2xLkI= github.com/codahale/hdrhistogram v0.0.0-20161010025455-3a0bb77429bd/go.mod h1:sE/e/2PUdi/liOCUjSTXgM1o87ZssimdTWN964YiIeI= -github.com/codefresh-io/go-sdk v0.51.0 h1:yYmrLp+iDTx9/K3KEFsxVlOB/+Y1KQHSwChgDP1Fjwc= -github.com/codefresh-io/go-sdk v0.51.0/go.mod h1:CcoVmTFWHGkbrSW8LyOGB/vJe5Vzr3iC/pNE2QIBTyg= +github.com/codefresh-io/go-sdk v0.52.0 h1:s+O87OebisNiDOEsh3qSAB8gDJ+Sc6WmBOh8AaFlm/o= +github.com/codefresh-io/go-sdk v0.52.0/go.mod h1:CcoVmTFWHGkbrSW8LyOGB/vJe5Vzr3iC/pNE2QIBTyg= github.com/codegangsta/inject v0.0.0-20150114235600-33e0aa1cb7c0/go.mod h1:4Zcjuz89kmFXt9morQgcfYZAYZ5n8WHjt81YYWIwtTM= github.com/codeskyblue/go-sh v0.0.0-20190412065543-76bd3d59ff27/go.mod h1:VQx0hjo2oUeQkQUET7wRwradO6f+fN5jzXgB/zROxxE= github.com/container-storage-interface/spec v1.5.0/go.mod h1:8K96oQNkJ7pFcC2R9Z1ynGGBB1I93kcS6PGg3SsOk8s= diff --git a/pkg/runtime/runtime.go b/pkg/runtime/runtime.go index d5911e68..f1b27e19 100644 --- a/pkg/runtime/runtime.go +++ b/pkg/runtime/runtime.go @@ -105,7 +105,7 @@ const ( InstallFeatureIngressless InstallFeature = "ingressless" ) -func Download(runtimeDef, name string, featuresToInstall []InstallFeature) (*Runtime, error) { +func Download(runtimeDef, name string, namespace string, featuresToInstall []InstallFeature) (*Runtime, error) { var ( body []byte err error @@ -136,7 +136,7 @@ func Download(runtimeDef, name string, featuresToInstall []InstallFeature) (*Run } runtime.Name = name - runtime.Namespace = name + runtime.Namespace = namespace filteredComponets := make([]AppDef, 0) for i := range runtime.Spec.Components { @@ -205,7 +205,7 @@ func (r *Runtime) Save(fs apfs.FS, filename string, config *CommonConfig) error } func (r *Runtime) Install(ctx context.Context, f apkube.Factory, cloneOpts *apgit.CloneOptions, valuesProvider HelmValuesProvider) error { - return r.Spec.install(ctx, f, cloneOpts, r.Name, valuesProvider) + return r.Spec.install(ctx, f, cloneOpts, r.Name, r.Namespace, valuesProvider) } func (r *Runtime) Upgrade(fs apfs.FS, newRt *Runtime, config *CommonConfig) ([]AppDef, error) { @@ -221,7 +221,7 @@ func (r *Runtime) Upgrade(fs apfs.FS, newRt *Runtime, config *CommonConfig) ([]A return newComponents, nil } -func (r *RuntimeSpec) install(ctx context.Context, f apkube.Factory, cloneOpts *apgit.CloneOptions, runtimeName string, valuesProvider HelmValuesProvider) error { +func (r *RuntimeSpec) install(ctx context.Context, f apkube.Factory, cloneOpts *apgit.CloneOptions, runtimeName , runtimeNamespace string, valuesProvider HelmValuesProvider) error { for _, component := range r.Components { log.G(ctx).Infof("Creating component \"%s\"", component.Name) component.IsInternal = true @@ -230,7 +230,7 @@ func (r *RuntimeSpec) install(ctx context.Context, f apkube.Factory, cloneOpts * return util.DecorateErrorWithDocsLink(fmt.Errorf("failed to create \"%s\" application: %w", component.Name, err)) } - err = component.CreateApp(ctx, f, cloneOpts, runtimeName, store.Get().CFComponentType, values) + err = component.CreateApp(ctx, f, cloneOpts, runtimeName, runtimeNamespace, store.Get().CFComponentType, values) if err != nil { return util.DecorateErrorWithDocsLink(fmt.Errorf("failed to create \"%s\" application: %w", component.Name, err)) } @@ -335,7 +335,7 @@ func shouldInstallFeature(featuresToInstall []InstallFeature, featureName Instal return false } -func (a *AppDef) CreateApp(ctx context.Context, f apkube.Factory, cloneOpts *apgit.CloneOptions, runtimeName, cfType string, optionalValues ...string) error { +func (a *AppDef) CreateApp(ctx context.Context, f apkube.Factory, cloneOpts *apgit.CloneOptions, runtimeName, runtimeNamespace, cfType string, optionalValues ...string) error { return util.Retry(ctx, &util.RetryOptions{ Func: func() error { newCloneOpts := &apgit.CloneOptions{ @@ -350,7 +350,7 @@ func (a *AppDef) CreateApp(ctx context.Context, f apkube.Factory, cloneOpts *apg newCloneOpts.Parse() if a.Type == "kustomize" || a.Type == "dir" { - return a.createAppUsingAutopilot(ctx, f, newCloneOpts, runtimeName, cfType) + return a.createAppUsingAutopilot(ctx, f, newCloneOpts, runtimeName, runtimeNamespace, cfType) } if a.Type == "helm" { @@ -358,7 +358,7 @@ func (a *AppDef) CreateApp(ctx context.Context, f apkube.Factory, cloneOpts *apg if len(optionalValues) > 0 { values = optionalValues[0] } - return a.createHelmAppDirectly(ctx, newCloneOpts, runtimeName, cfType, values) + return a.createHelmAppDirectly(ctx, newCloneOpts, runtimeName, runtimeNamespace, cfType, values) } return fmt.Errorf("failed to create app \"%s\", unknown type \"%s\"", a.Name, a.Type) @@ -366,7 +366,7 @@ func (a *AppDef) CreateApp(ctx context.Context, f apkube.Factory, cloneOpts *apg }) } -func (a *AppDef) createAppUsingAutopilot(ctx context.Context, f apkube.Factory, cloneOpts *apgit.CloneOptions, runtimeName, cfType string) error { +func (a *AppDef) createAppUsingAutopilot(ctx context.Context, f apkube.Factory, cloneOpts *apgit.CloneOptions, runtimeName, runtimeNamespace, cfType string) error { timeout := time.Duration(0) if a.Wait { timeout = store.Get().WaitTimeout @@ -380,7 +380,7 @@ func (a *AppDef) createAppUsingAutopilot(ctx context.Context, f apkube.Factory, AppName: a.Name, AppSpecifier: a.URL, AppType: a.Type, - DestNamespace: runtimeName, + DestNamespace: runtimeNamespace, Labels: map[string]string{ util.EscapeAppsetFieldName(store.Get().LabelKeyCFType): cfType, util.EscapeAppsetFieldName(store.Get().LabelKeyCFInternal): strconv.FormatBool(a.IsInternal), @@ -398,14 +398,14 @@ func (a *AppDef) createAppUsingAutopilot(ctx context.Context, f apkube.Factory, return apcmd.RunAppCreate(ctx, appCreateOpts) } -func (a *AppDef) createHelmAppDirectly(ctx context.Context, cloneOpts *apgit.CloneOptions, runtimeName, cfType string, values string) error { +func (a *AppDef) createHelmAppDirectly(ctx context.Context, cloneOpts *apgit.CloneOptions, runtimeName, runtimeNamespace, cfType string, values string) error { host, orgRepo, path, gitRef, _, suffix, _ := apaputil.ParseGitUrl(a.URL) repoUrl := host + orgRepo + suffix config := &HelmConfig{ Config: apapp.Config{ AppName: a.Name, UserGivenName: a.Name, - DestNamespace: runtimeName, + DestNamespace: runtimeNamespace, DestServer: apstore.Default.DestServer, SrcRepoURL: repoUrl, SrcPath: path, diff --git a/pkg/util/openshift/util.go b/pkg/util/openshift/util.go index 1ed1f229..478faf34 100644 --- a/pkg/util/openshift/util.go +++ b/pkg/util/openshift/util.go @@ -31,9 +31,10 @@ import ( ) type OpenshiftOptions struct { - KubeFactory kube.Factory - RuntimeName string - InsCloneOpts *git.CloneOptions + KubeFactory kube.Factory + RuntimeName string + RuntimeNamespace string + InsCloneOpts *git.CloneOptions } const openshiftNs = "openshift" @@ -83,7 +84,7 @@ func createScc(ctx context.Context, opts *OpenshiftOptions) error { APIVersion: "security.openshift.io/v1", }, ObjectMeta: metav1.ObjectMeta{ - Namespace: opts.RuntimeName, + Namespace: opts.RuntimeNamespace, Name: store.Get().SccName, }, AllowPrivilegedContainer: false,