Skip to content

Commit

Permalink
Merge branch 'main' into use-gar-for-airflow-helm-chart
Browse files Browse the repository at this point in the history
  • Loading branch information
erikvatt committed Jan 8, 2025
2 parents ccdf5af + 121d60d commit 321a691
Show file tree
Hide file tree
Showing 8 changed files with 3 additions and 61 deletions.
2 changes: 1 addition & 1 deletion k8s/overlays/dev/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
images:
- name: europe-north1-docker.pkg.dev/knada-gcp/knada-north/knorten
newTag: 4f52addd01c5c0d03282c4c82bc0e029ad2e3dc3
newTag: 71f6a23f6b690724d3847e6afe2cdfb3a1ba0096
2 changes: 1 addition & 1 deletion k8s/overlays/prod/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
images:
- name: europe-north1-docker.pkg.dev/knada-gcp/knada-north/knorten
newTag: 4f52addd01c5c0d03282c4c82bc0e029ad2e3dc3
newTag: 71f6a23f6b690724d3847e6afe2cdfb3a1ba0096
9 changes: 1 addition & 8 deletions pkg/api/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ package api

import (
"context"
"database/sql"
"encoding/gob"
"errors"
"fmt"
"net/http"
"net/url"
Expand Down Expand Up @@ -438,13 +436,8 @@ func (c *client) syncChartForAllTeams(ctx context.Context, chartType gensql.Char
func (c *client) syncChart(ctx context.Context, teamID string, chartType gensql.ChartType) error {
switch chartType {
case gensql.ChartTypeJupyterhub:
pypiAccessValue, err := c.repo.TeamValueGet(ctx, chart.TeamValueKeyPYPIAccess, teamID)
if err != nil && !errors.Is(err, sql.ErrNoRows) {
return err
}
values := chart.JupyterConfigurableValues{
TeamID: teamID,
PYPIAccess: pypiAccessValue.Value == "true",
TeamID: teamID,
}
return c.repo.RegisterUpdateJupyterEvent(ctx, teamID, values)
case gensql.ChartTypeAirflow:
Expand Down
2 changes: 0 additions & 2 deletions pkg/api/chart.go
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,6 @@ func (c *client) newChart(ctx *gin.Context, teamSlug string, chartType gensql.Ch
ImageTag: form.ImageTag,
CullTimeout: strconv.FormatUint(cullTimeout, 10),
AllowList: removeEmptySliceElements(form.Allowlist),
PYPIAccess: form.PYPIAccess == "on",
}

return c.repo.RegisterCreateJupyterEvent(ctx, team.ID, values)
Expand Down Expand Up @@ -549,7 +548,6 @@ func (c *client) editChart(ctx *gin.Context, teamSlug string, chartType gensql.C
ImageName: form.ImageName,
ImageTag: form.ImageTag,
CullTimeout: form.CullTimeout,
PYPIAccess: form.PYPIAccess == "on",
AllowList: removeEmptySliceElements(form.Allowlist),
}

Expand Down
8 changes: 0 additions & 8 deletions pkg/api/chart_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,6 @@ func TestJupyterAPI(t *testing.T) {
t.Errorf("create jupyterhub: culltimeout value - expected %v, got %v", culltimeout, eventPayload.CullTimeout)
}

if eventPayload.PYPIAccess {
t.Errorf("create jupyterhub: pypiAccess value - expected %v, got %v", false, eventPayload.PYPIAccess)
}

if len(eventPayload.UserIdents) != 3 {
t.Errorf("create jupyterhub: expected 3 users, got %v", len(eventPayload.UserIdents))
}
Expand Down Expand Up @@ -248,10 +244,6 @@ func TestJupyterAPI(t *testing.T) {
t.Errorf("edit jupyterhub: image tag value - expected %v, got %v", imageTag, eventPayload.ImageTag)
}

if !eventPayload.PYPIAccess {
t.Errorf("edit jupyterhub: pypi access value - expected %v, got %v", true, eventPayload.PYPIAccess)
}

if len(eventPayload.UserIdents) != 3 {
t.Errorf("edit jupyterhub: expected 3 users, got %v", len(eventPayload.UserIdents))
}
Expand Down
10 changes: 0 additions & 10 deletions pkg/chart/jupyterhub.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package chart
import (
"context"
"fmt"
"strconv"
"strings"

"github.com/navikt/knorten/pkg/database"
Expand All @@ -25,7 +24,6 @@ type JupyterConfigurableValues struct {
ImageName string `helm:"singleuser.image.name"`
ImageTag string `helm:"singleuser.image.tag"`
CullTimeout string `helm:"cull.timeout"`
PYPIAccess bool
AllowList []string
}

Expand Down Expand Up @@ -59,10 +57,6 @@ func (c Client) syncJupyter(ctx context.Context, configurableValues *JupyterConf
return fmt.Errorf("merging values: %w", err)
}

if err := c.repo.TeamValueInsert(ctx, gensql.ChartTypeJupyterhub, TeamValueKeyPYPIAccess, strconv.FormatBool(values.PYPIAccess), team.ID); err != nil {
return fmt.Errorf("inserting %v team value to database: %w", TeamValueKeyPYPIAccess, err)
}

namespace := k8s.TeamIDToNamespace(team.ID)

if err := c.createHttpRoute(ctx, team.Slug+".jupyter."+c.topLevelDomain, namespace, gensql.ChartTypeJupyterhub); err != nil {
Expand All @@ -73,10 +67,6 @@ func (c Client) syncJupyter(ctx context.Context, configurableValues *JupyterConf
return fmt.Errorf("creating health check policy: %w", err)
}

if err := c.alterJupyterDefaultFQDNNetpol(ctx, namespace, configurableValues.PYPIAccess); err != nil {
return fmt.Errorf("creating jupyter default FQDN netpol: %w", err)
}

chartValues, err := reflect.CreateChartValues(values)
if err != nil {
return fmt.Errorf("creating chart values: %w", err)
Expand Down
22 changes: 0 additions & 22 deletions pkg/chart/k8s.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,25 +91,3 @@ func (c Client) deleteHealthCheckPolicy(ctx context.Context, namespace string, c

return c.manager.DeleteHealthCheckPolicy(ctx, name, namespace)
}

func (c Client) alterJupyterDefaultFQDNNetpol(ctx context.Context, namespace string, enabled bool) error {
if c.dryRun {
return nil
}

if enabled {
err := c.manager.ApplyNetworkPolicy(ctx, networking.NewNetworkPolicyJupyterPyPi(k8sJupyterhubNetworPolicy, namespace))
if err != nil {
return fmt.Errorf("applying network policy: %w", err)
}

return nil
}

err := c.manager.DeleteNetworkPolicy(ctx, k8sJupyterhubNetworPolicy, namespace)
if err != nil {
return fmt.Errorf("deleting network policy: %w", err)
}

return nil
}
9 changes: 0 additions & 9 deletions templates/charts/jupyterhub.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,6 @@
placeholder="3600"
class="navds-text-field__input navds-body-short navds-body-medium"/>
</div>
<div class="navds-checkbox">
<div class="navds-checkbox navds-checkbox--medium">
<input id="pypiaccess" name="pypiaccess" type="checkbox" class="navds-checkbox__input"
{{ if or (not .values.PYPIAccess) (eq .values.PYPIAccess "on") }}checked{{ end }}/>
<label for="pypiaccess" class="navds-checkbox__label">
<span class="navds-checkbox__content">PYPI-tilgang fra notebook</span>
</label>
</div>
</div>
<div class="navds-form-field navds-form-field--medium">
<fieldset id="allowlist">
<legend class="navds-form-field__label navds-label">Allowlist</legend>
Expand Down

0 comments on commit 321a691

Please sign in to comment.