Skip to content

Commit

Permalink
Merge branch 'release/2.6.10'
Browse files Browse the repository at this point in the history
  • Loading branch information
GrahamDumpleton committed Sep 13, 2023
2 parents 818c586 + cb77d13 commit f0a13b1
Show file tree
Hide file tree
Showing 16 changed files with 140 additions and 260 deletions.
39 changes: 0 additions & 39 deletions .github/PULL_REQUEST_TEMPLATE.yml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ clusterIngress:
#! Ingress domain. DNS parent subdomain used for training portal and workshop
#! ingresses.

domain: "educates-local-dev.xyz"
domain: "educates-local-dev.test"

#! Ingress class. Required when multiple ingress controllers exist and it is
#! necessary to use one which is not marked as the default. Note that any
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ metadata:
annotations:
kapp.k14s.io/versioned: ""
kapp.k14s.io/num-versions: "5"
#@ if data.values.clusterIngress.domain == "educates-local-dev.xyz":
#@ if data.values.clusterIngress.domain == "educates-local-dev.test":
stringData:
values.yaml: #@ yaml.encode(data.values)
kyverno-policies.yaml: #@ yaml.encode(kyverno_policies)
Expand Down
2 changes: 1 addition & 1 deletion client-programs/pkg/cmd/cluster_portal_create_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func (p *ProjectInfo) NewClusterPortalCreateCmd() *cobra.Command {
c.Flags().UintVar(
&o.Capacity,
"capacity",
1,
5,
"maximum number of current sessions for the training portal",
)
c.Flags().StringVar(
Expand Down
47 changes: 41 additions & 6 deletions client-programs/pkg/cmd/cluster_portal_open_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@ package cmd
import (
"context"
"fmt"
"io"
"net/http"
"net/url"
"os/exec"
"runtime"
"time"

"github.com/pkg/errors"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -45,28 +49,59 @@ func (o *ClusterPortalOpenOptions) Run() error {
return errors.New("no workshops deployed")
}

url, found, _ := unstructured.NestedString(trainingPortal.Object, "status", "educates", "url")
targetUrl, found, _ := unstructured.NestedString(trainingPortal.Object, "status", "educates", "url")

if !found {
return errors.New("workshops not available")
}

rootUrl := targetUrl

if o.Admin {
url = url + "/admin"
targetUrl = targetUrl + "/admin"
} else {
password, _, _ := unstructured.NestedString(trainingPortal.Object, "spec", "portal", "password")

if password != "" {
values := url.Values{}
values.Add("redirect_url", "/")
values.Add("password", password)

targetUrl = fmt.Sprintf("%s/workshops/access/?%s", targetUrl, values.Encode())
}
}

for i := 1; i < 300; i++ {
time.Sleep(time.Second)

resp, err := http.Get(rootUrl)

if err != nil || resp.StatusCode == 503 {
continue
}

defer resp.Body.Close()
io.ReadAll(resp.Body)

break
}

switch runtime.GOOS {
case "linux":
err = exec.Command("xdg-open", url).Start()
err = exec.Command("xdg-open", targetUrl).Start()
case "windows":
err = exec.Command("rundll32", "url.dll,FileProtocolHandler", url).Start()
err = exec.Command("rundll32", "url.dll,FileProtocolHandler", targetUrl).Start()
case "darwin":
err = exec.Command("open", url).Start()
err = exec.Command("open", targetUrl).Start()
default:
err = fmt.Errorf("unsupported platform")
}

return err
if err != nil {
return errors.Wrap(err, "unable to open web browser")
}

return nil
}

func (p *ProjectInfo) NewClusterPortalOpenCmd() *cobra.Command {
Expand Down
123 changes: 86 additions & 37 deletions client-programs/pkg/cmd/cluster_workshop_deploy_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@ package cmd
import (
"context"
"encoding/json"
"fmt"
"io"
"math/rand"
"net/http"
"net/url"
"os/exec"
"runtime"
"strings"
"time"

Expand Down Expand Up @@ -36,6 +42,7 @@ type ClusterWorkshopDeployOptions struct {
Environ []string
WorkshopFile string
WorkshopVersion string
OpenBrowser bool
DataValuesFlags yttcmd.DataValuesFlags
}

Expand Down Expand Up @@ -86,7 +93,7 @@ func (o *ClusterWorkshopDeployOptions) Run() error {

// 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)
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)

if err != nil {
return err
Expand Down Expand Up @@ -135,8 +142,8 @@ func (p *ProjectInfo) NewClusterWorkshopDeployCmd() *cobra.Command {
c.Flags().UintVar(
&o.Capacity,
"capacity",
1,
"maximum number of current sessions for the workshop",
0,
"maximum number of concurrent sessions for this workshop",
)
c.Flags().UintVar(
&o.Reserved,
Expand Down Expand Up @@ -215,6 +222,13 @@ func (p *ProjectInfo) NewClusterWorkshopDeployCmd() *cobra.Command {
"the address of the image repository",
)

c.Flags().BoolVar(
&o.OpenBrowser,
"open-browser",
false,
"automatically launch browser on portal",
)

c.Flags().StringArrayVar(
&o.DataValuesFlags.EnvFromStrings,
"data-values-env",
Expand Down Expand Up @@ -258,7 +272,7 @@ func (p *ProjectInfo) NewClusterWorkshopDeployCmd() *cobra.Command {

var trainingPortalResource = schema.GroupVersionResource{Group: "training.educates.dev", Version: "v1beta1", Resource: "trainingportals"}

func deployWorkshopResource(client dynamic.Interface, workshop *unstructured.Unstructured, portal string, capacity uint, reserved uint, initial uint, expires string, overtime string, deadline string, orphaned string, overdue string, refresh string, registry string, environ []string) error {
func deployWorkshopResource(client dynamic.Interface, workshop *unstructured.Unstructured, portal string, capacity uint, reserved uint, initial uint, expires string, overtime string, deadline string, orphaned string, overdue string, refresh string, registry string, environ []string, openBrowser bool) error {
trainingPortalClient := client.Resource(trainingPortalResource)

trainingPortal, err := trainingPortalClient.Get(context.TODO(), portal, metav1.GetOptions{})
Expand Down Expand Up @@ -292,7 +306,7 @@ func deployWorkshopResource(client dynamic.Interface, workshop *unstructured.Uns
"sessions": struct {
Maximum int64 `json:"maximum"`
}{
Maximum: 1,
Maximum: 5,
},
"workshop": map[string]interface{}{
"defaults": struct {
Expand All @@ -307,38 +321,6 @@ func deployWorkshopResource(client dynamic.Interface, workshop *unstructured.Uns
})
}

var propertyExists bool

var sessionsMaximum int64 = 1

if trainingPortalExists {
sessionsMaximum, propertyExists, err = unstructured.NestedInt64(trainingPortal.Object, "spec", "portal", "sessions", "maximum")

if err == nil && propertyExists {
if sessionsMaximum >= 0 && uint(sessionsMaximum) < capacity {
capacity = uint(sessionsMaximum)
}
}
} else {
capacity = 1
}

if capacity != 0 {
if reserved > capacity {
reserved = capacity
}
if initial > capacity {
initial = capacity
}
} else if sessionsMaximum != 0 {
if reserved > uint(sessionsMaximum) {
reserved = uint(sessionsMaximum)
}
if initial > uint(sessionsMaximum) {
initial = uint(sessionsMaximum)
}
}

workshops, _, err := unstructured.NestedSlice(trainingPortal.Object, "spec", "workshops")

if err != nil {
Expand Down Expand Up @@ -516,6 +498,73 @@ func deployWorkshopResource(client dynamic.Interface, workshop *unstructured.Uns
return errors.Wrapf(err, "unable to update training portal %q in cluster", portal)
}

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

for i := 1; i < 60; i++ {
time.Sleep(time.Second)

trainingPortal, err = trainingPortalClient.Get(context.TODO(), portal, metav1.GetOptions{})

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

var found bool

targetUrl, found, _ = unstructured.NestedString(trainingPortal.Object, "status", "educates", "url")

if found {
break
}
}

rootUrl := targetUrl

password, _, _ := unstructured.NestedString(trainingPortal.Object, "spec", "portal", "password")

if password != "" {
values := url.Values{}
values.Add("redirect_url", "/")
values.Add("password", password)

targetUrl = fmt.Sprintf("%s/workshops/access/?%s", targetUrl, values.Encode())
}

for i := 1; i < 300; i++ {
time.Sleep(time.Second)

resp, err := http.Get(rootUrl)

if err != nil || resp.StatusCode == 503 {
continue
}

defer resp.Body.Close()
io.ReadAll(resp.Body)

break
}

switch runtime.GOOS {
case "linux":
err = exec.Command("xdg-open", targetUrl).Start()
case "windows":
err = exec.Command("rundll32", "url.dll,FileProtocolHandler", targetUrl).Start()
case "darwin":
err = exec.Command("open", targetUrl).Start()
default:
err = fmt.Errorf("unsupported platform")
}

if err != nil {
return errors.Wrap(err, "unable to open web browser")
}
}

return nil
}

Expand Down
2 changes: 1 addition & 1 deletion client-programs/pkg/cmd/cluster_workshop_request_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ func requestWorkshop(client dynamic.Interface, name string, portal string, param
}

if indexUrl == "" {
indexUrl = portalUrl
indexUrl = fmt.Sprintf("%s/accounts/logout/", portalUrl)
}

requestURL = fmt.Sprintf("%s/workshops/environment/%s/request/?index_url=%s", portalUrl, environmentName, url.QueryEscape(indexUrl))
Expand Down
1 change: 0 additions & 1 deletion client-programs/pkg/cmd/educates_cmd_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ func (p *ProjectInfo) NewEducatesCmdGroup() *cobra.Command {
overrideCommandName(p.NewClusterWorkshopDeployCmd(), "deploy-workshop"),
overrideCommandName(p.NewClusterWorkshopListCmd(), "list-workshops"),
overrideCommandName(p.NewClusterWorkshopServeCmd(), "serve-workshop"),
overrideCommandName(p.NewClusterWorkshopRequestCmd(), "request-workshop"),
overrideCommandName(p.NewClusterWorkshopUpdateCmd(), "update-workshop"),
overrideCommandName(p.NewClusterWorkshopDeleteCmd(), "delete-workshop"),

Expand Down
16 changes: 0 additions & 16 deletions docker-extension/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,6 @@ ARG TAG=latest

FROM ${REPOSITORY}/${CLI_IMAGE_NAME}:${TAG} AS client-programs

# FROM golang:1.19-alpine AS builder
# ENV CGO_ENABLED=0
# WORKDIR /backend
# COPY backend/go.* .
# RUN --mount=type=cache,target=/go/pkg/mod \
# --mount=type=cache,target=/root/.cache/go-build \
# go mod download
# COPY backend/. .
# RUN --mount=type=cache,target=/go/pkg/mod \
# --mount=type=cache,target=/root/.cache/go-build \
# go build -trimpath -ldflags="-s -w" -o bin/service

FROM --platform=$BUILDPLATFORM node:18.12-alpine3.16 AS client-builder
WORKDIR /ui
# cache packages in layer
Expand Down Expand Up @@ -60,13 +48,9 @@ EOF

COPY --from=client-programs educates-linux-${TARGETARCH} /educates

# COPY --from=builder /backend/bin/service /

COPY docker-compose.yaml .
COPY metadata.json .
COPY logo.svg .
COPY --from=client-builder /ui/build ui

# CMD /service -socket /run/guest-services/backend.sock

CMD ["/educates", "docker", "extension", "backend", "--socket", "/run/guest-services/backend.sock"]
Loading

0 comments on commit f0a13b1

Please sign in to comment.