Skip to content

Commit

Permalink
Merge branch 'release/2.6.12'
Browse files Browse the repository at this point in the history
  • Loading branch information
GrahamDumpleton committed Sep 19, 2023
2 parents e2f0abf + eaf8fa9 commit f182653
Show file tree
Hide file tree
Showing 15 changed files with 635 additions and 54 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
#@ load("@ytt:data", "data")
#@ load("/00-package.star", "image_reference", "image_pull_secrets", "image_pull_policy")

#@ prepull = ["training-portal"]
#@ prepull = []
#@ if data.values.imagePuller.prePullImages:
#@ prepull.append("training-portal")
#@ prepull.extend(data.values.imagePuller.prePullImages)
#@ end

---
#@ if prepull:
Expand Down
29 changes: 29 additions & 0 deletions client-programs/pkg/cmd/admin_cluster_create_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
apiv1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/kubernetes"
"k8s.io/kubectl/pkg/scheme"

"github.com/vmware-tanzu-labs/educates-training-platform/client-programs/pkg/cluster"
Expand Down Expand Up @@ -242,6 +243,10 @@ func (o *AdminClusterCreateOptions) Run() error {
return errors.Wrap(err, "failed to create service for registry")
}

if err = createLoopbackService(client, fullConfig.ClusterIngress.Domain); err != nil {
return err
}

if !o.WithServices {
return nil
}
Expand Down Expand Up @@ -413,3 +418,27 @@ func checkPortAvailability(listenAddress string, ports []uint) (bool, error) {

return true, nil
}

func createLoopbackService(k8sclient *kubernetes.Clientset, domain string) error {
service := apiv1.Service{
ObjectMeta: metav1.ObjectMeta{
Name: "loopback",
},
Spec: apiv1.ServiceSpec{
Type: apiv1.ServiceTypeExternalName,
ExternalName: fmt.Sprintf("localhost.%s", domain),
},
}

servicesClient := k8sclient.CoreV1().Services("default")

servicesClient.Delete(context.TODO(), "loopback", *metav1.NewDeleteOptions(0))

_, err := servicesClient.Create(context.TODO(), &service, metav1.CreateOptions{})

if err != nil {
return errors.Wrap(err, "unable to create localhost loopback service")
}

return nil
}
15 changes: 15 additions & 0 deletions client-programs/pkg/cmd/cluster_portal_open_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,18 @@ func (o *ClusterPortalOpenOptions) Run() error {
}
}

fmt.Printf("Training portal %q.\n", trainingPortal.GetName())

fmt.Print("Checking training portal is ready.\n")

spinner := func(iteration int) string {
spinners := `|/-\`
return string(spinners[iteration%len(spinners)])
}

for i := 1; i < 300; i++ {
fmt.Printf("\r[%s] Waiting...", spinner(i))

time.Sleep(time.Second)

resp, err := http.Get(rootUrl)
Expand All @@ -86,6 +97,10 @@ func (o *ClusterPortalOpenOptions) Run() error {
break
}

fmt.Print("\r \r")

fmt.Printf("Opening training portal %s.\n", targetUrl)

switch runtime.GOOS {
case "linux":
err = exec.Command("xdg-open", targetUrl).Start()
Expand Down
21 changes: 21 additions & 0 deletions client-programs/pkg/cmd/cluster_workshop_deploy_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ func (o *ClusterWorkshopDeployOptions) Run() error {
return err
}

fmt.Printf("Loaded workshop %q.\n", workshop.GetName())

// Update the training portal, creating it if necessary.

err = deployWorkshopResource(dynamicClient, workshop, o.Portal, o.Capacity, o.Reserved, o.Initial, o.Expires, o.Overtime, o.Deadline, o.Orphaned, o.Overdue, o.Refresh, o.Repository, o.Environ, o.OpenBrowser)
Expand Down Expand Up @@ -489,22 +491,35 @@ func deployWorkshopResource(client dynamic.Interface, workshop *unstructured.Uns
unstructured.SetNestedSlice(trainingPortal.Object, updatedWorkshops, "spec", "workshops")

if trainingPortalExists {
fmt.Printf("Updating existing training portal %q.\n", trainingPortal.GetName())
_, err = trainingPortalClient.Update(context.TODO(), trainingPortal, metav1.UpdateOptions{FieldManager: "educates-cli"})
} else {
fmt.Printf("Creating new training portal %q.\n", trainingPortal.GetName())
_, err = trainingPortalClient.Create(context.TODO(), trainingPortal, metav1.CreateOptions{FieldManager: "educates-cli"})
}

if err != nil {
return errors.Wrapf(err, "unable to update training portal %q in cluster", portal)
}

fmt.Print("Workshop added to training portal.\n")

if openBrowser {
// Need to refetch training portal because if was just created the URL
// for access may not have been set yet.

var targetUrl string

fmt.Print("Checking training portal is ready.\n")

spinner := func(iteration int) string {
spinners := `|/-\`
return string(spinners[iteration%len(spinners)])
}

for i := 1; i < 60; i++ {
fmt.Printf("\r[%s] Waiting...", spinner(i))

time.Sleep(time.Second)

trainingPortal, err = trainingPortalClient.Get(context.TODO(), portal, metav1.GetOptions{})
Expand Down Expand Up @@ -535,6 +550,8 @@ func deployWorkshopResource(client dynamic.Interface, workshop *unstructured.Uns
}

for i := 1; i < 300; i++ {
fmt.Printf("\r[%s] Waiting...", spinner(i))

time.Sleep(time.Second)

resp, err := http.Get(rootUrl)
Expand All @@ -549,6 +566,10 @@ func deployWorkshopResource(client dynamic.Interface, workshop *unstructured.Uns
break
}

fmt.Print("\r \r")

fmt.Printf("Opening training portal %s.\n", targetUrl)

switch runtime.GOOS {
case "linux":
err = exec.Command("xdg-open", targetUrl).Start()
Expand Down
13 changes: 12 additions & 1 deletion client-programs/pkg/cmd/cluster_workshop_serve_cmd.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cmd

import (
"fmt"
"io/ioutil"
"os"
"path"
Expand Down Expand Up @@ -80,6 +81,12 @@ func generateAccessToken(refresh bool) (string, error) {
configFileDir := path.Join(xdg.DataHome, "educates")
accessTokenFile := path.Join(configFileDir, "live-reload-token.dat")

err := os.MkdirAll(configFileDir, os.ModePerm)

if err != nil {
return "", errors.Wrapf(err, "unable to create config directory")
}

var accessToken string

if refresh {
Expand Down Expand Up @@ -197,6 +204,8 @@ func (o *ClusterWorkshopServeOptions) Run() error {
if err != nil {
return err
}

fmt.Printf("Patched workshop %q.\n", workshop.GetName())
}

var cleanupFunc = func() {
Expand All @@ -210,6 +219,8 @@ func (o *ClusterWorkshopServeOptions) Run() error {
// Update the workshop resource in the Kubernetes cluster.

updateWorkshopResource(dynamicClient, workshop)

fmt.Printf("Restored workshop %q.\n", workshop.GetName())
}
}

Expand Down Expand Up @@ -264,7 +275,7 @@ func (p *ProjectInfo) NewClusterWorkshopServeCmd() *cobra.Command {
c.Flags().StringVar(
&o.ProxyHost,
"proxy-host",
"localhost.$(ingress_domain)",
"loopback.default.svc.cluster.local",
"host by which any remote proxy will be accessed",
)
c.Flags().IntVar(
Expand Down
2 changes: 2 additions & 0 deletions client-programs/pkg/cmd/cluster_workshop_update_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ func (o *ClusterWorkshopUpdateOptions) Run() error {
return err
}

fmt.Printf("Loaded workshop %q.\n", workshop.GetName())

return nil
}

Expand Down
4 changes: 4 additions & 0 deletions client-programs/pkg/cmd/workshop_publish_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ func (o *FilesPublishOptions) Publish(directory string) error {
return errors.Wrap(err, "couldn't parse workshop definition")
}

fmt.Printf("Processing workshop with name %q.\n", workshop.GetName())

if workshop.GetAPIVersion() != "training.educates.dev/v1beta1" || workshop.GetKind() != "Workshop" {
return errors.New("invalid type for workshop definition")
}
Expand Down Expand Up @@ -222,6 +224,8 @@ func (o *FilesPublishOptions) Publish(directory string) error {

// Now publish workshop directory contents as OCI image artifact.

fmt.Printf("Publishing workshop files to %q.\n", image)

pushOptions := imgpkgcmd.NewPushOptions(confUI)

pushOptions.ImageFlags.Image = image
Expand Down
1 change: 1 addition & 0 deletions session-manager/handlers/workshopenvironment.py
Original file line number Diff line number Diff line change
Expand Up @@ -954,6 +954,7 @@ def workshop_environment_create(
environment_token = spec.get("request", {}).get("token", "")

environment_variables = dict(
workshop_environment_uid=uid,
platform_arch=PLATFORM_ARCH,
image_repository=image_repository,
oci_image_cache=oci_image_cache,
Expand Down
1 change: 1 addition & 0 deletions session-manager/handlers/workshopsession.py
Original file line number Diff line number Diff line change
Expand Up @@ -926,6 +926,7 @@ def resolve_security_policy(name):
ingress_port = "443"

session_variables = dict(
workshop_session_uid=uid,
platform_arch=PLATFORM_ARCH,
image_repository=image_repository,
oci_image_cache=oci_image_cache,
Expand Down
14 changes: 14 additions & 0 deletions workshop-images/base-environment/opt/eduk8s/bin/xdg-open
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash

MESSAGE=$(cat <<EOF
{
"action": "dashboard:open-url",
"data": {
"url": "$1"
}
}
EOF
)

curl --silent -H "Content-Type: application/json" -o /dev/null \
--data "$MESSAGE" "http://localhost:10080/message/broadcast?token=$SERVICES_PASSWORD"
Loading

0 comments on commit f182653

Please sign in to comment.