Skip to content

Commit

Permalink
Add argocd repository column
Browse files Browse the repository at this point in the history
Signed-off-by: cmoulliard <[email protected]>
  • Loading branch information
cmoulliard committed Jan 2, 2025
1 parent 6415f7b commit 0cd0d7d
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 5 deletions.
31 changes: 31 additions & 0 deletions pkg/cmd/get/packages.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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 {
Expand All @@ -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
}
2 changes: 2 additions & 0 deletions pkg/printer/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -39,6 +40,7 @@ func generatePackageTable(packagesTable []types.Package) metav1.Table {
p.Name,
p.Namespace,
p.GitRepository,
p.ArgocdRepository,
p.Status,
},
}
Expand Down
11 changes: 6 additions & 5 deletions pkg/types/package.go
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit 0cd0d7d

Please sign in to comment.