diff --git a/Makefile b/Makefile index dabd96d2..9a75ec37 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -VERSION=v0.1.46 +VERSION=v0.1.47 OUT_DIR=dist YEAR?=$(shell date +"%Y") diff --git a/cmd/commands/cluster.go b/cmd/commands/cluster.go index c44340b1..6ce3edc4 100644 --- a/cmd/commands/cluster.go +++ b/cmd/commands/cluster.go @@ -28,11 +28,11 @@ import ( "github.com/codefresh-io/cli-v2/pkg/util" kubeutil "github.com/codefresh-io/cli-v2/pkg/util/kube" kustutil "github.com/codefresh-io/cli-v2/pkg/util/kust" - platmodel "github.com/codefresh-io/go-sdk/pkg/codefresh/model" - "github.com/ghodss/yaml" "github.com/Masterminds/semver/v3" - "github.com/argoproj-labs/argocd-autopilot/pkg/kube" + apkube "github.com/argoproj-labs/argocd-autopilot/pkg/kube" + platmodel "github.com/codefresh-io/go-sdk/pkg/codefresh/model" + "github.com/ghodss/yaml" "github.com/juju/ansiterm" "github.com/spf13/cobra" kusttypes "sigs.k8s.io/kustomize/api/types" @@ -51,7 +51,7 @@ type ( tag string dryRun bool skipTLSValidation bool - kubeFactory kube.Factory + kubeFactory apkube.Factory } ClusterRemoveOptions struct { @@ -147,7 +147,7 @@ func newClusterAddCommand() *cobra.Command { cmd.Flags().StringVar(&opts.tag, "tag", "", "[dev only] - use a specific tag of the csdp-add-cluster image") util.Die(cmd.Flags().MarkHidden("tag")) - opts.kubeFactory = kube.AddFlags(cmd.Flags()) + opts.kubeFactory = apkube.AddFlags(cmd.Flags()) return cmd } diff --git a/cmd/commands/common.go b/cmd/commands/common.go index f08ad43c..a2db2ef8 100644 --- a/cmd/commands/common.go +++ b/cmd/commands/common.go @@ -38,8 +38,7 @@ import ( "github.com/codefresh-io/cli-v2/pkg/util/kube" routingutil "github.com/codefresh-io/cli-v2/pkg/util/routing" - "github.com/argoproj-labs/argocd-autopilot/pkg/fs" - "github.com/argoproj-labs/argocd-autopilot/pkg/git" + apfs "github.com/argoproj-labs/argocd-autopilot/pkg/fs" apgit "github.com/argoproj-labs/argocd-autopilot/pkg/git" aputil "github.com/argoproj-labs/argocd-autopilot/pkg/util" platmodel "github.com/codefresh-io/go-sdk/pkg/codefresh/model" @@ -487,7 +486,6 @@ func getKubeContextName(context, kubeconfig *pflag.Flag) (string, error) { return contextName, context.Value.Set(contextName) } - type SelectItem struct { Value string Label string @@ -744,24 +742,6 @@ func suggestIscRepo(ctx context.Context, suggestedSharedConfigRepo string) (stri return setIscRepoResponse, nil } -func isRuntimeManaged(ctx context.Context, runtimeName string) (bool, error) { - rt, err := getRuntime(ctx, runtimeName) - if err != nil { - return false, err - } - - return rt.Managed, nil -} - -func getRuntimeInstallationType(ctx context.Context, runtimeName string) (*platmodel.InstallationType, error) { - rt, err := getRuntime(ctx, runtimeName) - if err != nil { - return nil, err - } - - return &rt.InstallationType, nil -} - func ensureRuntimeOnKubeContext(ctx context.Context, kubeconfig string, runtimeName string, kubeContextName string) error { rt, err := getRuntime(ctx, runtimeName) if err != nil { @@ -797,7 +777,7 @@ func getRuntime(ctx context.Context, runtimeName string) (*platmodel.Runtime, er return rt, nil } -func patchRuntimeRepo(ctx context.Context, cloneOpts *git.CloneOptions, msg string, f func(fs fs.FS) error) error { +func patchRuntimeRepo(ctx context.Context, cloneOpts *apgit.CloneOptions, msg string, f func(fs apfs.FS) error) error { r, fs, err := cloneOpts.GetRepo(ctx) if err != nil { return err diff --git a/cmd/commands/config_test.go b/cmd/commands/config_test.go index e19a9c35..898d4868 100644 --- a/cmd/commands/config_test.go +++ b/cmd/commands/config_test.go @@ -19,6 +19,7 @@ import ( cfgit "github.com/codefresh-io/cli-v2/pkg/git" "github.com/codefresh-io/cli-v2/pkg/store" + "github.com/stretchr/testify/assert" ) diff --git a/cmd/commands/git-source.go b/cmd/commands/git-source.go index 19ed2cc3..7af60406 100644 --- a/cmd/commands/git-source.go +++ b/cmd/commands/git-source.go @@ -30,9 +30,9 @@ import ( routingutil "github.com/codefresh-io/cli-v2/pkg/util/routing" wfutil "github.com/codefresh-io/cli-v2/pkg/util/workflow" - "github.com/argoproj-labs/argocd-autopilot/pkg/application" - "github.com/argoproj-labs/argocd-autopilot/pkg/fs" - "github.com/argoproj-labs/argocd-autopilot/pkg/git" + apapp "github.com/argoproj-labs/argocd-autopilot/pkg/application" + apfs "github.com/argoproj-labs/argocd-autopilot/pkg/fs" + apgit "github.com/argoproj-labs/argocd-autopilot/pkg/git" aputil "github.com/argoproj-labs/argocd-autopilot/pkg/util" apicommon "github.com/argoproj/argo-events/pkg/apis/common" eventsourcereg "github.com/argoproj/argo-events/pkg/apis/eventsource" @@ -53,8 +53,8 @@ import ( type ( GitSourceCreateOptions struct { - InsCloneOpts *git.CloneOptions - GsCloneOpts *git.CloneOptions + InsCloneOpts *apgit.CloneOptions + GsCloneOpts *apgit.CloneOptions GsName string RuntimeName string RuntimeNamespace string @@ -82,22 +82,22 @@ type ( GitSourceEditOptions struct { RuntimeName string GsName string - GsCloneOpts *git.CloneOptions + GsCloneOpts *apgit.CloneOptions Include *string Exclude *string } gitSourceCalendarDemoPipelineOptions struct { runtimeName string - gsCloneOpts *git.CloneOptions - gsFs fs.FS + gsCloneOpts *apgit.CloneOptions + gsFs apfs.FS } gitSourceGitDemoPipelineOptions struct { runtimeName string - gsCloneOpts *git.CloneOptions + gsCloneOpts *apgit.CloneOptions gitProvider cfgit.Provider - gsFs fs.FS + gsFs apfs.FS hostName string ingressHost string skipIngress bool @@ -132,7 +132,7 @@ func NewGitSourceCommand() *cobra.Command { func NewGitSourceCreateCommand() *cobra.Command { var ( - gsCloneOpts *git.CloneOptions + gsCloneOpts *apgit.CloneOptions gitProvider cfgit.Provider createRepo bool include string @@ -188,17 +188,22 @@ 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 + runtimeName := args[0] + runtime, err := getRuntime(ctx, runtimeName) + if err != nil { + return err + } + + runtimeNamespace := runtimeName + if runtime.Metadata.Namespace != nil { + runtimeNamespace = *runtime.Metadata.Namespace } return RunGitSourceCreate(ctx, &GitSourceCreateOptions{ GsCloneOpts: gsCloneOpts, GitProvider: gitProvider, GsName: args[1], - RuntimeName: args[0], + RuntimeName: runtimeName, RuntimeNamespace: runtimeNamespace, CreateDemoResources: false, Include: include, @@ -245,7 +250,7 @@ func RunGitSourceCreate(ctx context.Context, opts *GitSourceCreateOptions) error return nil } -func ensureGitSourceDirectory(ctx context.Context, opts *GitSourceCreateOptions, gsRepo git.Repository, gsFs fs.FS) error { +func ensureGitSourceDirectory(ctx context.Context, opts *GitSourceCreateOptions, gsRepo apgit.Repository, gsFs apfs.FS) error { fi, err := gsFs.ReadDir(".") if err != nil { return fmt.Errorf("failed to read files in git-source repo. Err: %w", err) @@ -411,7 +416,7 @@ func RunGitSourceDelete(ctx context.Context, opts *GitSourceDeleteOptions) error func NewGitSourceEditCommand() *cobra.Command { var ( - gsCloneOpts *git.CloneOptions + gsCloneOpts *apgit.CloneOptions include string exclude string ) @@ -492,7 +497,7 @@ func RunGitSourceEdit(ctx context.Context, opts *GitSourceEditOptions) error { return nil } -func createDemoResources(ctx context.Context, opts *GitSourceCreateOptions, gsRepo git.Repository, gsFs fs.FS) error { +func createDemoResources(ctx context.Context, opts *GitSourceCreateOptions, gsRepo apgit.Repository, gsFs apfs.FS) error { fi, err := gsFs.ReadDir(".") if err != nil { return fmt.Errorf("failed to read files in git-source repo. Err: %w", err) @@ -1391,7 +1396,7 @@ func deleteCommonRedundantFields(crd map[string]interface{}) { } func writeObjectToYaml[Object any]( - gsFs fs.FS, + gsFs apfs.FS, filePath string, object Object, cleanUpFunc func(Object) (map[string]interface{}, error), @@ -1425,7 +1430,7 @@ func legacyGitSourceCreate(ctx context.Context, opts *GitSourceCreateOptions) er appDef := &runtime.AppDef{ Name: opts.GsName, - Type: application.AppTypeDirectory, + Type: apapp.AppTypeDirectory, URL: opts.GsCloneOpts.Repo, Include: opts.Include, Exclude: opts.Exclude, diff --git a/cmd/commands/helm_test.go b/cmd/commands/helm_test.go index 52651129..bf76f257 100644 --- a/cmd/commands/helm_test.go +++ b/cmd/commands/helm_test.go @@ -20,9 +20,10 @@ import ( "net/http" "testing" - kubemocks "github.com/argoproj-labs/argocd-autopilot/pkg/kube/mocks" cfgit "github.com/codefresh-io/cli-v2/pkg/git" gitmocks "github.com/codefresh-io/cli-v2/pkg/git/mocks" + + kubemocks "github.com/argoproj-labs/argocd-autopilot/pkg/kube/mocks" platmodel "github.com/codefresh-io/go-sdk/pkg/codefresh/model" "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" diff --git a/cmd/commands/runtime.go b/cmd/commands/runtime.go index 5726a8f0..496b2ce9 100644 --- a/cmd/commands/runtime.go +++ b/cmd/commands/runtime.go @@ -27,21 +27,20 @@ import ( "sync" "time" - kubeutil "github.com/codefresh-io/cli-v2/pkg/util/kube" - routingutil "github.com/codefresh-io/cli-v2/pkg/util/routing" - "github.com/codefresh-io/cli-v2/pkg/log" "github.com/codefresh-io/cli-v2/pkg/reporter" "github.com/codefresh-io/cli-v2/pkg/runtime" "github.com/codefresh-io/cli-v2/pkg/store" "github.com/codefresh-io/cli-v2/pkg/util" apu "github.com/codefresh-io/cli-v2/pkg/util/aputil" + kubeutil "github.com/codefresh-io/cli-v2/pkg/util/kube" + routingutil "github.com/codefresh-io/cli-v2/pkg/util/routing" "github.com/Masterminds/semver/v3" apcmd "github.com/argoproj-labs/argocd-autopilot/cmd/commands" - "github.com/argoproj-labs/argocd-autopilot/pkg/fs" + apfs "github.com/argoproj-labs/argocd-autopilot/pkg/fs" apgit "github.com/argoproj-labs/argocd-autopilot/pkg/git" - "github.com/argoproj-labs/argocd-autopilot/pkg/kube" + apkube "github.com/argoproj-labs/argocd-autopilot/pkg/kube" apstore "github.com/argoproj-labs/argocd-autopilot/pkg/store" argocdv1alpha1 "github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1" argocdv1alpha1cs "github.com/argoproj/argo-cd/v2/pkg/client/clientset/versioned" @@ -56,10 +55,9 @@ import ( type ( RuntimeUninstallOptions struct { RuntimeName string - RuntimeNamespace string Timeout time.Duration CloneOpts *apgit.CloneOptions - KubeFactory kube.Factory + KubeFactory apkube.Factory SkipChecks bool Force bool FastExit bool @@ -68,6 +66,7 @@ type ( kubeContext string skipAutopilotUninstall bool + runtimeNamespace string } RuntimeUpgradeOptions struct { @@ -148,24 +147,27 @@ func runtimeUninstallCommandPreRunHandler(cmd *cobra.Command, args []string, opt return err } - installationType, err := getRuntimeInstallationType(ctx, opts.RuntimeName) + rt, err := getRuntime(ctx, opts.RuntimeName) if err != nil { return err } - if *installationType == platmodel.InstallationTypeHelm { + if rt.InstallationType == platmodel.InstallationTypeHelm { return errors.New("This runtime was installed using Helm, please use Helm to uninstall it as well.") } - if !opts.SkipChecks { - opts.Managed, err = isRuntimeManaged(ctx, opts.RuntimeName) - if err != nil { - return err + opts.Managed = rt.Managed + if !opts.Managed { + opts.kubeContext, err = getKubeContextName(cmd.Flag("context"), cmd.Flag("kubeconfig")) } + + opts.runtimeNamespace, _ = cmd.Flags().GetString("namespace") + if opts.runtimeNamespace == "" { + opts.runtimeNamespace = opts.RuntimeName } - if !opts.Managed { - opts.kubeContext, err = getKubeContextName(cmd.Flag("context"), cmd.Flag("kubeconfig")) + if rt.Metadata.Namespace != nil { + opts.runtimeNamespace = *rt.Metadata.Namespace } handleCliStep(reporter.UninstallStepPreCheckGetKubeContext, "Getting kube context name", err, true, false) @@ -173,7 +175,7 @@ func runtimeUninstallCommandPreRunHandler(cmd *cobra.Command, args []string, opt return err } - if !opts.Managed && !opts.SkipChecks { + if !opts.Managed { kubeconfig := cmd.Flag("kubeconfig").Value.String() err = ensureRuntimeOnKubeContext(ctx, kubeconfig, opts.RuntimeName, opts.kubeContext) @@ -189,7 +191,7 @@ func runtimeUninstallCommandPreRunHandler(cmd *cobra.Command, args []string, opt return err } - if !opts.Managed && !opts.SkipChecks { + if !opts.Managed { err = ensureRepo(cmd, opts.RuntimeName, opts.CloneOpts, true) } handleCliStep(reporter.UninstallStepPreCheckEnsureRuntimeRepo, "Getting runtime repo", err, true, false) @@ -471,7 +473,7 @@ func NewRuntimeUninstallCommand() *cobra.Command { finalParameters = map[string]string{ "Codefresh context": cfConfig.GetCurrentContext().Name, "Runtime name": opts.RuntimeName, - "Runtime namespace": opts.RuntimeNamespace, + "Runtime namespace": opts.runtimeNamespace, } if !opts.Managed { @@ -501,12 +503,13 @@ func NewRuntimeUninstallCommand() *cobra.Command { cmd.Flags().BoolVar(&opts.Force, "force", false, "If true, will guarantee the runtime is removed from the platform, even in case of errors while cleaning the repo and the cluster") cmd.Flags().BoolVar(&opts.FastExit, "fast-exit", false, "If true, will not wait for deletion of cluster resources. This means that full resource deletion will not be verified") cmd.Flags().BoolVar(&opts.DisableTelemetry, "disable-telemetry", false, "If true, will disable the analytics reporting for the uninstall process") + _ = cmd.Flags().MarkDeprecated("skip-checks", "this flag was removed, runtime must exist on platform for uninstall to run") opts.CloneOpts = apu.AddCloneFlags(cmd, &apu.CloneFlagsOptions{ CloneForWrite: true, Optional: true, }) - opts.KubeFactory = kube.AddFlags(cmd.Flags()) + opts.KubeFactory = apkube.AddFlags(cmd.Flags()) return cmd } @@ -518,15 +521,7 @@ func runRuntimeUninstall(ctx context.Context, opts *RuntimeUninstallOptions) err // check whether the runtime exists var err error - - if !opts.SkipChecks { - _, err = getRuntime(ctx, opts.RuntimeName) - } handleCliStep(reporter.UninstallStepCheckRuntimeExists, "Checking if runtime exists", err, false, true) - if err != nil { - summaryArr = append(summaryArr, summaryLog{"you can attempt to uninstall again with the \"--skip-checks\" flag", Info}) - return err - } log.G(ctx).Infof("Uninstalling runtime \"%s\" - this process may take a few minutes...", opts.RuntimeName) @@ -559,7 +554,7 @@ func runRuntimeUninstall(ctx context.Context, opts *RuntimeUninstallOptions) err if !opts.Managed { err = apcmd.RunRepoUninstall(ctx, &apcmd.RepoUninstallOptions{ - Namespace: opts.RuntimeNamespace, + Namespace: opts.runtimeNamespace, KubeContextName: opts.kubeContext, Timeout: opts.Timeout, CloneOptions: opts.CloneOpts, @@ -595,7 +590,7 @@ func runRuntimeUninstall(ctx context.Context, opts *RuntimeUninstallOptions) err } if !opts.Managed { - err = runPostUninstallCleanup(ctx, opts.KubeFactory, opts.RuntimeNamespace) + err = runPostUninstallCleanup(ctx, opts.KubeFactory, opts.runtimeNamespace) if err != nil { errorMsg := fmt.Sprintf("failed to do post uninstall cleanup: %v", err) if !opts.Force { @@ -611,7 +606,7 @@ func runRuntimeUninstall(ctx context.Context, opts *RuntimeUninstallOptions) err return nil } -func runPostUninstallCleanup(ctx context.Context, kubeFactory kube.Factory, namespace string) error { +func runPostUninstallCleanup(ctx context.Context, kubeFactory apkube.Factory, namespace string) error { sealedSecrets, err := kubeutil.GetSecretsWithLabel(ctx, kubeFactory, namespace, store.Get().LabelSelectorSealedSecret) if err != nil { return err @@ -634,7 +629,7 @@ func runPostUninstallCleanup(ctx context.Context, kubeFactory kube.Factory, name return nil } -func printApplicationsState(ctx context.Context, runtime string, f kube.Factory, managed bool) error { +func printApplicationsState(ctx context.Context, runtime string, f apkube.Factory, managed bool) error { if managed { return nil } @@ -1094,7 +1089,7 @@ func downloadFile(response *http.Response, fullFilename string) error { return err } -var getProjectInfoFromFile = func(repofs fs.FS, name string) (*argocdv1alpha1.AppProject, *argocdv1alpha1.ApplicationSet, error) { +var getProjectInfoFromFile = func(repofs apfs.FS, name string) (*argocdv1alpha1.AppProject, *argocdv1alpha1.ApplicationSet, error) { proj := &argocdv1alpha1.AppProject{} appSet := &argocdv1alpha1.ApplicationSet{} if err := repofs.ReadYamls(name, proj, appSet); err != nil { @@ -1174,22 +1169,3 @@ 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 f55549bb..ff78f9c3 100644 --- a/cmd/commands/runtime_install.go +++ b/cmd/commands/runtime_install.go @@ -46,8 +46,8 @@ import ( "github.com/Masterminds/semver/v3" apcmd "github.com/argoproj-labs/argocd-autopilot/cmd/commands" - "github.com/argoproj-labs/argocd-autopilot/pkg/application" - "github.com/argoproj-labs/argocd-autopilot/pkg/fs" + apapp "github.com/argoproj-labs/argocd-autopilot/pkg/application" + apfs "github.com/argoproj-labs/argocd-autopilot/pkg/fs" apgit "github.com/argoproj-labs/argocd-autopilot/pkg/git" apkube "github.com/argoproj-labs/argocd-autopilot/pkg/kube" apstore "github.com/argoproj-labs/argocd-autopilot/pkg/store" @@ -164,7 +164,7 @@ func NewRuntimeInstallCommand() *cobra.Command { GitIntegrationRegistrationOpts: &GitIntegrationRegistrationOpts{}, featuresToInstall: make([]runtime.InstallFeature, 0), } - accessMode string + accessMode string ) cmd := &cobra.Command{ @@ -294,7 +294,7 @@ func NewRuntimeInstallCommand() *cobra.Command { }) installationOpts.GsCloneOpts = &apgit.CloneOptions{ - FS: fs.Create(memfs.New()), + FS: apfs.Create(memfs.New()), CreateIfNotExist: true, } @@ -934,7 +934,7 @@ func createGitSources(ctx context.Context, opts *RuntimeInstallOptions) error { mpCloneOpts := &apgit.CloneOptions{ Repo: store.Get().MarketplaceRepo, - FS: fs.Create(memfs.New()), + FS: apfs.Create(memfs.New()), Progress: opts.InsCloneOpts.Progress, } mpCloneOpts.Parse() @@ -1594,7 +1594,7 @@ func configureAppProxy(ctx context.Context, opts *RuntimeInstallOptions, rt *run } func updateCodefreshCM(ctx context.Context, opts *RuntimeInstallOptions, rt *runtime.Runtime) error { - var repofs fs.FS + var repofs apfs.FS var marshalRuntime []byte var r apgit.Repository var err error @@ -1664,7 +1664,7 @@ func createEventsReporter(ctx context.Context, cloneOpts *apgit.CloneOptions, op u = u.JoinPath(resPath) appDef := &runtime.AppDef{ Name: store.Get().EventsReporterName, - Type: application.AppTypeDirectory, + Type: apapp.AppTypeDirectory, URL: u.String(), IsInternal: true, } @@ -1706,7 +1706,7 @@ func createReporter(ctx context.Context, cloneOpts *apgit.CloneOptions, opts *Ru u = u.JoinPath(resPath) appDef := &runtime.AppDef{ Name: reporterCreateOpts.reporterName, - Type: application.AppTypeDirectory, + Type: apapp.AppTypeDirectory, URL: u.String(), IsInternal: reporterCreateOpts.IsInternal, } @@ -1750,7 +1750,7 @@ func createReporter(ctx context.Context, cloneOpts *apgit.CloneOptions, opts *Ru }) } -func updateProject(repofs fs.FS, rt *runtime.Runtime) error { +func updateProject(repofs apfs.FS, rt *runtime.Runtime) error { projPath := repofs.Join(apstore.Default.ProjectsDir, rt.Name+".yaml") project, appSet, err := getProjectInfoFromFile(repofs, projPath) if err != nil { @@ -1837,7 +1837,7 @@ func getArgoCDTokenSecret(ctx context.Context, kubeContext, namespace string, in }) } -func createReporterRBAC(repofs fs.FS, path, runtimeNamespace, saName string, clusterScope bool) error { +func createReporterRBAC(repofs apfs.FS, path, runtimeNamespace, saName string, clusterScope bool) error { serviceAccount := &v1.ServiceAccount{ TypeMeta: metav1.TypeMeta{ Kind: "ServiceAccount", @@ -1912,7 +1912,7 @@ func createReporterRBAC(repofs fs.FS, path, runtimeNamespace, saName string, clu return repofs.WriteYamls(repofs.Join(path, "rbac.yaml"), serviceAccount, role, roleBinding) } -func createEventsReporterEventSource(repofs fs.FS, path, namespace string, insecure bool) error { +func createEventsReporterEventSource(repofs apfs.FS, path, namespace string, insecure bool) error { port := 443 if insecure { port = 80 @@ -1934,7 +1934,7 @@ func createEventsReporterEventSource(repofs fs.FS, path, namespace string, insec return repofs.WriteYamls(repofs.Join(path, "event-source.yaml"), eventSource) } -func createReporterEventSource(repofs fs.FS, path, namespace string, reporterCreateOpts reporterCreateOptions, clusterScope bool) error { +func createReporterEventSource(repofs apfs.FS, path, namespace string, reporterCreateOpts reporterCreateOptions, clusterScope bool) error { var eventSource *aev1alpha1.EventSource var options *eventsutil.CreateEventSourceOptions @@ -1971,7 +1971,7 @@ func createReporterEventSource(repofs fs.FS, path, namespace string, reporterCre return repofs.WriteYamls(repofs.Join(path, "event-source.yaml"), eventSource) } -func createSensor(repofs fs.FS, name, path, namespace, eventSourceName string, triggers []string, dataKey string) error { +func createSensor(repofs apfs.FS, name, path, namespace, eventSourceName string, triggers []string, dataKey string) error { triggerUrl, err := url.JoinPath(cfConfig.GetCurrentContext().URL, store.Get().EventReportingEndpoint) if err != nil { return err @@ -2062,7 +2062,7 @@ func getInstallationFromRepoApproval(ctx context.Context, opts *RuntimeInstallOp return nil } -func getRuntimeDataFromCodefreshCM(_ context.Context, repofs fs.FS, runtimeName string, codefreshCM *v1.ConfigMap) (*runtime.Runtime, error) { +func getRuntimeDataFromCodefreshCM(_ context.Context, repofs apfs.FS, runtimeName string, codefreshCM *v1.ConfigMap) (*runtime.Runtime, error) { err := repofs.ReadYamls(repofs.Join(apstore.Default.BootsrtrapDir, runtimeName+".yaml"), codefreshCM) if err != nil { return nil, fmt.Errorf("failed to read file '%s': %w", runtimeName+".yaml", err) @@ -2085,13 +2085,14 @@ func postInstallationHandler(ctx context.Context, opts *RuntimeInstallOptions, e util.CheckNetworkErr(err) err := runRuntimeUninstall(ctx, &RuntimeUninstallOptions{ RuntimeName: opts.RuntimeName, - RuntimeNamespace: opts.RuntimeNamespace, Timeout: store.Get().WaitTimeout, CloneOpts: opts.InsCloneOpts, KubeFactory: opts.KubeFactory, SkipChecks: true, Force: true, FastExit: false, + + runtimeNamespace: opts.RuntimeNamespace, }) handleCliStep(reporter.UninstallPhaseFinish, "Uninstall phase finished after rollback", err, false, true) if err != nil { @@ -2177,7 +2178,7 @@ func getRuntimeDef(runtimeDef, version string) string { return strings.Replace(runtimeDef, "stable", version, 1) } -func patchClusterResourcesAppSet(fs fs.FS) error { +func patchClusterResourcesAppSet(fs apfs.FS) error { appSet := &argocdv1alpha1.ApplicationSet{} name := store.Get().ClusterResourcesPath if err := fs.ReadYamls(name, appSet); err != nil { @@ -2191,3 +2192,22 @@ func patchClusterResourcesAppSet(fs fs.FS) error { appSet.ObjectMeta.Labels[store.Get().LabelKeyCFInternal] = "true" return fs.WriteYamls(name, appSet) } + +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/upgrade.go b/cmd/commands/upgrade.go index 2f55556d..ab3dc3db 100644 --- a/cmd/commands/upgrade.go +++ b/cmd/commands/upgrade.go @@ -15,9 +15,9 @@ package commands import ( - "github.com/spf13/cobra" - cliutil "github.com/codefresh-io/cli-v2/pkg/util/cli" + + "github.com/spf13/cobra" ) func NewUpgradeCommand() *cobra.Command { diff --git a/docs/commands/cli-v2_runtime_uninstall.md b/docs/commands/cli-v2_runtime_uninstall.md index ab52c983..499b3c93 100644 --- a/docs/commands/cli-v2_runtime_uninstall.md +++ b/docs/commands/cli-v2_runtime_uninstall.md @@ -40,7 +40,6 @@ cli-v2 runtime uninstall [RUNTIME_NAME] [flags] -n, --namespace string If present, the namespace scope for this CLI request --repo string Repository URL [GIT_REPO] --request-timeout string The length of time to wait before giving up on a single server request. Non-zero values should contain a corresponding time unit (e.g. 1s, 2m, 3h). A value of zero means don't timeout requests. (default "0") - --skip-checks If true, will not verify that runtime exists before uninstalling -b, --upsert-branch If true will try to checkout the specified branch and create it if it doesn't exist --wait-timeout duration How long to wait for the runtime components to be deleted (default 8m0s) ``` diff --git a/pkg/util/aputil/aputil.go b/pkg/util/aputil/aputil.go index 599cdd90..1506afc2 100644 --- a/pkg/util/aputil/aputil.go +++ b/pkg/util/aputil/aputil.go @@ -23,7 +23,7 @@ import ( "github.com/codefresh-io/cli-v2/pkg/log" "github.com/codefresh-io/cli-v2/pkg/util" - "github.com/argoproj-labs/argocd-autopilot/pkg/git" + apgit "github.com/argoproj-labs/argocd-autopilot/pkg/git" aplog "github.com/argoproj-labs/argocd-autopilot/pkg/log" "github.com/go-git/go-billy/v5/memfs" "github.com/go-git/go-git/v5/plumbing/transport" @@ -43,8 +43,8 @@ type CloneFlagsOptions struct { Progress io.Writer } -func AddCloneFlags(cmd *cobra.Command, o *CloneFlagsOptions) *git.CloneOptions { - opts := git.AddFlags(cmd, &git.AddFlagsOptions{ +func AddCloneFlags(cmd *cobra.Command, o *CloneFlagsOptions) *apgit.CloneOptions { + opts := apgit.AddFlags(cmd, &apgit.AddFlagsOptions{ FS: memfs.New(), Prefix: o.Prefix, CreateIfNotExist: o.CreateIfNotExist, @@ -60,14 +60,14 @@ func AddCloneFlags(cmd *cobra.Command, o *CloneFlagsOptions) *git.CloneOptions { return opts } -func PushWithMessage(ctx context.Context, r git.Repository, msg string) error { +func PushWithMessage(ctx context.Context, r apgit.Repository, msg string) error { var ( err error prog io.Writer ) for try := 0; try < pushRetries; try++ { - _, err = r.Persist(ctx, &git.PushOptions{ + _, err = r.Persist(ctx, &apgit.PushOptions{ AddGlobPattern: ".", CommitMsg: msg, Progress: prog, diff --git a/pkg/util/kust/util.go b/pkg/util/kust/util.go index 2b674acd..5dacd56f 100644 --- a/pkg/util/kust/util.go +++ b/pkg/util/kust/util.go @@ -19,7 +19,7 @@ import ( "os" "path/filepath" - "github.com/argoproj-labs/argocd-autopilot/pkg/fs" + apfs "github.com/argoproj-labs/argocd-autopilot/pkg/fs" "github.com/ghodss/yaml" "sigs.k8s.io/kustomize/api/krusty" kusttypes "sigs.k8s.io/kustomize/api/types" @@ -28,7 +28,7 @@ import ( var KUSTOMOZATION_FILE_NAME = "kustomization.yaml" -func ReadKustomization(fs fs.FS, directory string) (*kusttypes.Kustomization, error) { +func ReadKustomization(fs apfs.FS, directory string) (*kusttypes.Kustomization, error) { fileName := fs.Join(directory, KUSTOMOZATION_FILE_NAME) kust := &kusttypes.Kustomization{} if err := fs.ReadYamls(fileName, kust); err != nil { @@ -59,7 +59,7 @@ func ReplaceResource(kust *kusttypes.Kustomization, fromURL, toURL string) error return nil } -func WriteKustomization(fs fs.FS, kust *kusttypes.Kustomization, directory string) error { +func WriteKustomization(fs apfs.FS, kust *kusttypes.Kustomization, directory string) error { fileName := fs.Join(directory, KUSTOMOZATION_FILE_NAME) return fs.WriteYamls(fileName, kust) } diff --git a/pkg/util/openshift/util.go b/pkg/util/openshift/util.go index 478faf34..9296b4c7 100644 --- a/pkg/util/openshift/util.go +++ b/pkg/util/openshift/util.go @@ -23,18 +23,18 @@ import ( apu "github.com/codefresh-io/cli-v2/pkg/util/aputil" kubeutil "github.com/codefresh-io/cli-v2/pkg/util/kube" - "github.com/argoproj-labs/argocd-autopilot/pkg/git" - "github.com/argoproj-labs/argocd-autopilot/pkg/kube" + apgit "github.com/argoproj-labs/argocd-autopilot/pkg/git" + apkube "github.com/argoproj-labs/argocd-autopilot/pkg/kube" apstore "github.com/argoproj-labs/argocd-autopilot/pkg/store" ocsecurityv1 "github.com/openshift/api/security/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) type OpenshiftOptions struct { - KubeFactory kube.Factory + KubeFactory apkube.Factory RuntimeName string RuntimeNamespace string - InsCloneOpts *git.CloneOptions + InsCloneOpts *apgit.CloneOptions } const openshiftNs = "openshift" @@ -57,7 +57,7 @@ func PrepareOpenshiftCluster(ctx context.Context, opts *OpenshiftOptions) error return nil } -func isOpenshiftCluster(ctx context.Context, kubeFactory kube.Factory) (bool, error) { +func isOpenshiftCluster(ctx context.Context, kubeFactory apkube.Factory) (bool, error) { exists, err := kubeutil.CheckNamespaceExists(ctx, openshiftNs, kubeFactory) if err != nil { return false, err diff --git a/pkg/util/routing/common_test.go b/pkg/util/routing/common_test.go index b7ffb47b..abfb1a78 100644 --- a/pkg/util/routing/common_test.go +++ b/pkg/util/routing/common_test.go @@ -20,9 +20,9 @@ import ( "os" "testing" - "github.com/stretchr/testify/assert" - "github.com/codefresh-io/cli-v2/pkg/util/routing" + + "github.com/stretchr/testify/assert" v1 "k8s.io/api/networking/v1" yamlutil "k8s.io/apimachinery/pkg/util/yaml" ) diff --git a/pkg/util/routing/gatewayapi.go b/pkg/util/routing/gatewayapi.go index cf955c7d..e59717cd 100644 --- a/pkg/util/routing/gatewayapi.go +++ b/pkg/util/routing/gatewayapi.go @@ -18,9 +18,10 @@ import ( "context" "fmt" - "github.com/argoproj-labs/argocd-autopilot/pkg/kube" "github.com/codefresh-io/cli-v2/pkg/log" httproute "github.com/codefresh-io/cli-v2/pkg/util/routing/types" + + apkkube "github.com/argoproj-labs/argocd-autopilot/pkg/kube" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/client-go/dynamic" @@ -112,7 +113,7 @@ var SupportedGatewayControllers = []gatewayControllerType{GatewayControllerConto // return httpRouteRules //} -func ValidateGatewayController(ctx context.Context, kubeFactory kube.Factory, gatewayName, gatewayNamespace string) (RoutingController, error) { +func ValidateGatewayController(ctx context.Context, kubeFactory apkkube.Factory, gatewayName, gatewayNamespace string) (RoutingController, error) { // Get Gateway cs := getClientsetOrDie(kubeFactory) gatewayResourceId := schema.GroupVersionResource{ @@ -173,7 +174,7 @@ func ValidateGatewayController(ctx context.Context, kubeFactory kube.Factory, ga // return httpRouteRules //} -func getClientsetOrDie(kubeFactory kube.Factory) dynamic.Interface { +func getClientsetOrDie(kubeFactory apkkube.Factory) dynamic.Interface { restConfig, err := kubeFactory.ToRESTConfig() if err != nil { panic(err)