From 0cd0d7d3b81c9987eabf41adf59954b31a4c7697 Mon Sep 17 00:00:00 2001 From: cmoulliard Date: Thu, 2 Jan 2025 12:25:56 +0100 Subject: [PATCH] Add argocd repository column Signed-off-by: cmoulliard --- pkg/cmd/get/packages.go | 31 +++++++++++++++++++++++++++++++ pkg/printer/package.go | 2 ++ pkg/types/package.go | 11 ++++++----- 3 files changed, 39 insertions(+), 5 deletions(-) diff --git a/pkg/cmd/get/packages.go b/pkg/cmd/get/packages.go index 902cbd6c..d51f571a 100644 --- a/pkg/cmd/get/packages.go +++ b/pkg/cmd/get/packages.go @@ -17,6 +17,11 @@ import ( "strconv" ) +// TODO To be removed when we will merge PR: 442 as duplicate +const ( + ArgocdIngressURL = "%s://argocd.cnoe.localtest.me:%s" +) + var PackagesCmd = &cobra.Command{ Use: "packages", Short: "retrieve packages from the cluster", @@ -34,6 +39,7 @@ func getPackagesE(cmd *cobra.Command, args []string) error { KubeConfigPath: kubeConfigPath, Scheme: k8s.GetScheme(), CancelFunc: ctxCancel, + TemplateData: v1alpha1.BuildCustomizationSpec{}, } b := build.NewBuild(opts) @@ -62,6 +68,11 @@ func printPackages(ctx context.Context, outWriter io.Writer, kubeClient client.C return fmt.Errorf("getting namespace: %w", err) } + argocdBaseUrl, err := ArgocdBaseUrl(ctx, kubeClient) + if err != nil { + return fmt.Errorf("getting localbuild config: %w", err) + } + if len(packages) == 0 { // Get all custom packages customPackages, err = getPackages(ctx, kubeClient, idpbuilderNamespace) @@ -84,6 +95,7 @@ func printPackages(ctx context.Context, outWriter io.Writer, kubeClient client.C newPackage := types.Package{} newPackage.Name = cp.Name newPackage.Namespace = cp.Namespace + newPackage.ArgocdRepository = argocdBaseUrl + "/applications/" + cp.Spec.ArgoCD.Namespace + "/" + cp.Spec.ArgoCD.Name // There is a GitRepositoryRefs when the project has been cloned to the internal git repository if cp.Status.GitRepositoryRefs != nil { newPackage.GitRepository = cp.Spec.InternalGitServeURL + "/" + v1alpha1.GiteaAdminUserName + "/" + idpbuilderNamespace + "-" + cp.Status.GitRepositoryRefs[0].Name @@ -113,6 +125,16 @@ func getPackageByName(ctx context.Context, kubeClient client.Client, ns, name st return p, kubeClient.Get(ctx, client.ObjectKey{Name: name, Namespace: ns}, &p) } +func getIDPConfig(ctx context.Context, kubeClient client.Client) (v1alpha1.BuildCustomizationSpec, error) { + b := v1alpha1.BuildCustomizationSpec{} + list, err := getLocalBuild(ctx, kubeClient) + if err != nil { + return b, err + } + // TODO: We assume that only one LocalBuild has been created for one cluster ! + return list.Items[0].Spec.BuildCustomization, nil +} + func getIDPNamespace(ctx context.Context, kubeClient client.Client) (string, error) { build, err := getLocalBuild(ctx, kubeClient) if err != nil { @@ -132,3 +154,12 @@ func getPackages(ctx context.Context, kubeClient client.Client, ns string) (v1al packageList := v1alpha1.CustomPackageList{} return packageList, kubeClient.List(ctx, &packageList, client.InNamespace(ns)) } + +// TODO To be removed when we will merge PR: 442 as duplicate +func ArgocdBaseUrl(ctx context.Context, kubeClient client.Client) (string, error) { + config, err := getIDPConfig(ctx, kubeClient) + if err != nil { + return "", err + } + return fmt.Sprintf(ArgocdIngressURL, config.Protocol, config.Port), nil +} diff --git a/pkg/printer/package.go b/pkg/printer/package.go index 907bb8d4..7a73082d 100644 --- a/pkg/printer/package.go +++ b/pkg/printer/package.go @@ -31,6 +31,7 @@ func generatePackageTable(packagesTable []types.Package) metav1.Table { {Name: "Custom package name", Type: "string"}, {Name: "idp namespace", Type: "string"}, {Name: "Git Repository", Type: "string"}, + {Name: "Argocd Repository", Type: "string"}, {Name: "Status", Type: "string"}, } for _, p := range packagesTable { @@ -39,6 +40,7 @@ func generatePackageTable(packagesTable []types.Package) metav1.Table { p.Name, p.Namespace, p.GitRepository, + p.ArgocdRepository, p.Status, }, } diff --git a/pkg/types/package.go b/pkg/types/package.go index 98753679..df47a636 100644 --- a/pkg/types/package.go +++ b/pkg/types/package.go @@ -1,9 +1,10 @@ package types type Package struct { - Name string - Namespace string - Type string - GitRepository string - Status string + Name string + Namespace string + Type string + GitRepository string + ArgocdRepository string + Status string }