From 2c669bceeaa7697e717ad161e7d4340bc570ac47 Mon Sep 17 00:00:00 2001 From: Filip Strozik Date: Mon, 16 Dec 2024 10:51:56 +0100 Subject: [PATCH] Print external URL of the exposed app (#2284) --- internal/cmd/alpha/app/push.go | 5 ++++- internal/kube/resources/resources.go | 4 ++-- internal/kube/resources/resources_test.go | 10 +++++----- internal/modules/{modules.go => list.go} | 2 ++ internal/modules/{modules_test.go => list_test.go} | 0 internal/modules/render.go | 2 ++ 6 files changed, 15 insertions(+), 8 deletions(-) rename internal/modules/{modules.go => list.go} (96%) rename internal/modules/{modules_test.go => list_test.go} (100%) diff --git a/internal/cmd/alpha/app/push.go b/internal/cmd/alpha/app/push.go index fabc1e190..0bc1cd97d 100644 --- a/internal/cmd/alpha/app/push.go +++ b/internal/cmd/alpha/app/push.go @@ -170,10 +170,13 @@ func runAppPush(cfg *appPushConfig) clierror.Error { return clierror.WrapE(clierr, clierror.New("failed to get cluster address from gateway", "Make sure Istio module is installed")) } - err = resources.CreateAPIRule(cfg.Ctx, client.RootlessDynamic(), cfg.name, cfg.namespace, domain, uint32(*cfg.containerPort.Value)) + host := fmt.Sprintf("%s.%s", cfg.name, domain) + err = resources.CreateAPIRule(cfg.Ctx, client.RootlessDynamic(), cfg.name, cfg.namespace, host, uint32(*cfg.containerPort.Value)) if err != nil { return clierror.Wrap(err, clierror.New("failed to create API Rule", "Make sure API Gateway module is installed", "Make sure APIRule is available in v2alpha1 version")) } + + fmt.Printf("\nThe %s app is now available under the https://%s/ address\n", cfg.name, host) } return nil diff --git a/internal/kube/resources/resources.go b/internal/kube/resources/resources.go index ca276e046..b8c339820 100644 --- a/internal/kube/resources/resources.go +++ b/internal/kube/resources/resources.go @@ -174,7 +174,7 @@ func CreateService(ctx context.Context, client kube.Client, name, namespace stri return err } -func CreateAPIRule(ctx context.Context, client rootlessdynamic.Interface, name, namespace, domain string, port uint32) error { +func CreateAPIRule(ctx context.Context, client rootlessdynamic.Interface, name, namespace, host string, port uint32) error { apirule := v2alpha1.APIRule{ TypeMeta: metav1.TypeMeta{ APIVersion: "gateway.kyma-project.io/v2alpha1", @@ -190,7 +190,7 @@ func CreateAPIRule(ctx context.Context, client rootlessdynamic.Interface, name, }, Spec: v2alpha1.APIRuleSpec{ Hosts: []*v2alpha1.Host{ - ptr.To(v2alpha1.Host(fmt.Sprintf("%s.%s", name, domain))), + ptr.To(v2alpha1.Host(host)), }, Gateway: ptr.To(fmt.Sprintf("%s/%s", istio.GatewayNamespace, istio.GatewayName)), Rules: []v2alpha1.Rule{ diff --git a/internal/kube/resources/resources_test.go b/internal/kube/resources/resources_test.go index 8faa75762..a0358aedd 100644 --- a/internal/kube/resources/resources_test.go +++ b/internal/kube/resources/resources_test.go @@ -222,14 +222,14 @@ func Test_CreateAPIRule(t *testing.T) { rootlessdynamic := &rootlessdynamic.Fake{} apiRuleName := "apiRule" namespace := "default" - domain := "example.com" + host := "example.com" port := uint32(80) - err := CreateAPIRule(ctx, rootlessdynamic, apiRuleName, namespace, domain, port) + err := CreateAPIRule(ctx, rootlessdynamic, apiRuleName, namespace, host, port) require.NoError(t, err) require.Equal(t, 1, len(rootlessdynamic.ApplyObjs)) - require.Equal(t, fixAPIRule(apiRuleName, namespace, domain, port), rootlessdynamic.ApplyObjs[0]) + require.Equal(t, fixAPIRule(apiRuleName, namespace, host, port), rootlessdynamic.ApplyObjs[0]) }) t.Run("do not allow creating existing apiRule", func(t *testing.T) { ctx := context.Background() @@ -245,7 +245,7 @@ func Test_CreateAPIRule(t *testing.T) { }) } -func fixAPIRule(apiRuleName, namespace, domain string, port uint32) unstructured.Unstructured { +func fixAPIRule(apiRuleName, namespace, host string, port uint32) unstructured.Unstructured { return unstructured.Unstructured{ Object: map[string]interface{}{ "apiVersion": "gateway.kyma-project.io/v2alpha1", @@ -261,7 +261,7 @@ func fixAPIRule(apiRuleName, namespace, domain string, port uint32) unstructured }, "spec": map[string]interface{}{ "hosts": []interface{}{ - fmt.Sprintf("%s.%s", apiRuleName, domain), + host, }, "gateway": fmt.Sprintf("%s/%s", istio.GatewayNamespace, istio.GatewayName), "rules": []interface{}{ diff --git a/internal/modules/modules.go b/internal/modules/list.go similarity index 96% rename from internal/modules/modules.go rename to internal/modules/list.go index cb0bbc0cb..ea2a2d0ca 100644 --- a/internal/modules/modules.go +++ b/internal/modules/list.go @@ -35,6 +35,8 @@ type ModuleVersion struct { type ModulesList []Module +// List returns list of available module on a cluster +// collects info about modules based on ModuleTemplates, ModuleReleaseMetas and the KymaCR func List(ctx context.Context, client kyma.Interface) (ModulesList, error) { moduleTemplates, err := client.ListModuleTemplate(ctx) if err != nil { diff --git a/internal/modules/modules_test.go b/internal/modules/list_test.go similarity index 100% rename from internal/modules/modules_test.go rename to internal/modules/list_test.go diff --git a/internal/modules/render.go b/internal/modules/render.go index dd4f753b4..7f9ebc7d1 100644 --- a/internal/modules/render.go +++ b/internal/modules/render.go @@ -32,6 +32,8 @@ var ( } ) +// Renders uses standard output to print ModuleList in table view +// TODO: support other formats like YAML or JSON func Render(modulesList ModulesList, tableInfo TableInfo) { render(os.Stdout, modulesList, tableInfo) }