Skip to content

Commit

Permalink
Print external URL of the exposed app (#2284)
Browse files Browse the repository at this point in the history
  • Loading branch information
pPrecel authored Dec 16, 2024
1 parent 1bcafd2 commit 2c669bc
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 8 deletions.
5 changes: 4 additions & 1 deletion internal/cmd/alpha/app/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions internal/kube/resources/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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{
Expand Down
10 changes: 5 additions & 5 deletions internal/kube/resources/resources_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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",
Expand All @@ -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{}{
Expand Down
2 changes: 2 additions & 0 deletions internal/modules/modules.go → internal/modules/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
File renamed without changes.
2 changes: 2 additions & 0 deletions internal/modules/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit 2c669bc

Please sign in to comment.