Skip to content

Commit

Permalink
chore: adding knative domain upd as init subcommand
Browse files Browse the repository at this point in the history
  • Loading branch information
spchortis committed Oct 3, 2023
1 parent 442ecc7 commit ac552e7
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 16 deletions.
1 change: 1 addition & 0 deletions assets/k8s/serviceAccount/cluster-role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ rules:
- ingresses
- services
- secrets
- configmaps
verbs:
- create
- delete
Expand Down
24 changes: 20 additions & 4 deletions src/cli/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,17 @@ func (c icli) InitKnativeCMD(cCtx *cli.Context) error {
return err
}

if cCtx.NArg() < 1 {
return fmt.Errorf("Knative domain argument is required!")
}

knativeDomain := cCtx.Args().Get(0)
fmt.Printf("Argument from subcommand: %s\n", knativeDomain)
os.Exit(1)
knative.DomainUpd(knativeDomain, config)

err = knative.DomainUpd(knativeDomain, config)

if err != nil {
return err
}

return nil
}
Expand Down Expand Up @@ -157,8 +164,17 @@ func (c icli) InitCMD() *cli.Command {
{
Name: "knative-domain",
Usage: "updates knative service default domain",
Flags: c.CommandFlags([]FlagsType{Kubernetes}),
Action: c.InitKnativeCMD,
Before: c.baseBeforeFunc,
Before: func(ctx *cli.Context) error {
if err := c.loadFlagsFromConfig(ctx); err != nil {
return err
}

ignoredFlags := []string{namespaceFlag}

return c.checkRequiredFlags(ctx, ignoredFlags)
},
},
},
}
Expand Down
22 changes: 10 additions & 12 deletions src/services/k8s/knative.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,10 @@ func Apply(namespace string, commitSha string, config *rest.Config, project *pro

func Clean(namespace string, config *rest.Config, project *project.Project) error {
log.Info("Deleting Knative service", "host", config.Host, "name", project.Name, "namespace", namespace)
ctx := context.Background()
//ctx := context.Background()

ctx, cancel := context.WithTimeout(context.Background(), time.Minute*2)
defer cancel()

// Create a new Knative Serving client
servingClient, err := servingv1client.NewForConfig(config)
Expand All @@ -241,27 +244,22 @@ func DomainUpd(kn_domain string, config *rest.Config) error {
log.Info("Updating Knative default domain name...", "new domain", kn_domain, "configMap", configMapName, "namespace", namespace)
ctx := context.Background()

// Create a new Knative Serving client
//servingClient, err := servingv1client.NewForConfig(config)
//if err != nil {
// return fmt.Errorf("Error creating the knative client %v", err)
//}

client, err := kubernetes.NewForConfig(config)
if err != nil {
return fmt.Errorf("Creating Kubernetes client %v", err)
}

configMaps := client.CoreV1().ConfigMaps(namespace)
configMap, err := client.CoreV1().ConfigMaps(namespace).Get(ctx, configMapName, metav1.GetOptions{})

configMap, err := configMaps.Get(ctx, configMapName, metav1.GetOptions{})
if err != nil {
return err
return fmt.Errorf("Getting ConfigMaps: %v", err)
}

configMap.Data["domain"] = kn_domain
configMap.Data = make(map[string]string)

configMap.Data[kn_domain] = ""

_, err = configMaps.Update(ctx, configMap, metav1.UpdateOptions{})
_, err = client.CoreV1().ConfigMaps(namespace).Update(ctx, configMap, metav1.UpdateOptions{})
if err != nil {
return err
}
Expand Down

0 comments on commit ac552e7

Please sign in to comment.