Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add namespace field for ConfigMap resource and update PVC/Kind validation regex #132

Open
wants to merge 2 commits into
base: notebooks-v2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions workspaces/backend/api/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ func TestAPI(t *testing.T) {
RunSpecs(t, "API Suite")
}

const namespaceName = "default"

var _ = BeforeSuite(func() {
logf.SetLogger(zap.New(zap.WriteTo(GinkgoWriter), zap.UseDevMode(true)))
ctx, cancel = context.WithCancel(context.Background())
Expand Down Expand Up @@ -177,8 +179,9 @@ func NewExampleWorkspaceKind(name string) *kubefloworgv1beta1.WorkspaceKind {
},
Logo: kubefloworgv1beta1.WorkspaceKindIcon{
ConfigMap: &kubefloworgv1beta1.WorkspaceKindConfigMap{
Name: "my-logos",
Key: "apple-touch-icon-152x152.png",
Name: "my-logos",
Namespace: namespaceName,
Key: "apple-touch-icon-152x152.png",
},
},
},
Expand Down
6 changes: 3 additions & 3 deletions workspaces/controller/api/v1beta1/workspace_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ type WorkspaceSpec struct {
// the WorkspaceKind to use
//+kubebuilder:validation:MinLength:=2
//+kubebuilder:validation:MaxLength:=63
//+kubebuilder:validation:Pattern:=^[a-z0-9][-a-z0-9]*[a-z0-9]$
//+kubebuilder:validation:Pattern:=^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$
//+kubebuilder:validation:XValidation:rule="self == oldSelf",message="Workspace 'kind' is immutable"
//+kubebuilder:example="jupyterlab"
Kind string `json:"kind"`
Expand Down Expand Up @@ -85,7 +85,7 @@ type WorkspacePodVolumes struct {
//+kubebuilder:validation:Optional
//+kubebuilder:validation:MinLength:=2
//+kubebuilder:validation:MaxLength:=63
//+kubebuilder:validation:Pattern:=^[a-z0-9][-a-z0-9]*[a-z0-9]$
//+kubebuilder:validation:Pattern:=^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$
//+kubebuilder:example="my-home-pvc"
Home *string `json:"home,omitempty"`

Expand All @@ -104,7 +104,7 @@ type PodVolumeMount struct {
// the name of the PVC to mount
//+kubebuilder:validation:MinLength:=2
//+kubebuilder:validation:MaxLength:=63
//+kubebuilder:validation:Pattern:=^[a-z0-9][-a-z0-9]*[a-z0-9]$
//+kubebuilder:validation:Pattern:=^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$
//+kubebuilder:example="my-data-pvc"
PVCName string `json:"pvcName"`

Expand Down
12 changes: 12 additions & 0 deletions workspaces/controller/api/v1beta1/workspacekind_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,21 @@ type WorkspaceKindIcon struct {
}

type WorkspaceKindConfigMap struct {

//+kubebuilder:validation:MinLength:=1
//+kubebuilder:validation:MaxLength:=253
//+kubebuilder:validation:Pattern:=^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$
//+kubebuilder:example="my-logos"
Name string `json:"name"`

//+kubebuilder:validation:MinLength:=1
//+kubebuilder:validation:MaxLength:=63
//+kubebuilder:validation:Pattern:=^[a-z0-9]([-a-z0-9]*[a-z0-9])?$
Namespace string `json:"namespace"`

//+kubebuilder:validation:MinLength:=1
//+kubebuilder:validation:MaxLength:=253
//+kubebuilder:validation:Pattern:=^[-._a-zA-Z0-9]+$
//+kubebuilder:example="apple-touch-icon-152x152.png"
Key string `json:"key"`
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4273,13 +4273,25 @@ spec:
properties:
key:
example: apple-touch-icon-152x152.png
maxLength: 253
minLength: 1
pattern: ^[-._a-zA-Z0-9]+$
type: string
name:
example: my-logos
maxLength: 253
minLength: 1
pattern: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$
type: string
namespace:
maxLength: 63
minLength: 1
pattern: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?$
type: string
required:
- key
- name
- namespace
type: object
url:
example: https://jupyter.org/assets/favicons/apple-touch-icon-152x152.png
Expand All @@ -4298,13 +4310,25 @@ spec:
properties:
key:
example: apple-touch-icon-152x152.png
maxLength: 253
minLength: 1
pattern: ^[-._a-zA-Z0-9]+$
type: string
name:
example: my-logos
maxLength: 253
minLength: 1
pattern: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$
type: string
namespace:
maxLength: 63
minLength: 1
pattern: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?$
type: string
required:
- key
- name
- namespace
type: object
url:
example: https://jupyter.org/assets/favicons/apple-touch-icon-152x152.png
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ spec:
example: jupyterlab
maxLength: 63
minLength: 2
pattern: ^[a-z0-9][-a-z0-9]*[a-z0-9]$
pattern: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$
type: string
x-kubernetes-validations:
- message: Workspace 'kind' is immutable
Expand Down Expand Up @@ -130,7 +130,7 @@ spec:
example: my-data-pvc
maxLength: 63
minLength: 2
pattern: ^[a-z0-9][-a-z0-9]*[a-z0-9]$
pattern: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$
type: string
readOnly:
default: false
Expand All @@ -154,7 +154,7 @@ spec:
example: my-home-pvc
maxLength: 63
minLength: 2
pattern: ^[a-z0-9][-a-z0-9]*[a-z0-9]$
pattern: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$
type: string
type: object
required:
Expand Down
7 changes: 5 additions & 2 deletions workspaces/controller/internal/controller/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ var (
cancel context.CancelFunc
)

const namespaceName = "default"

func TestControllers(t *testing.T) {
RegisterFailHandler(Fail)

Expand Down Expand Up @@ -192,8 +194,9 @@ func NewExampleWorkspaceKind1(name string) *kubefloworgv1beta1.WorkspaceKind {
},
Logo: kubefloworgv1beta1.WorkspaceKindIcon{
ConfigMap: &kubefloworgv1beta1.WorkspaceKindConfigMap{
Name: "my-logos",
Key: "apple-touch-icon-152x152.png",
Name: "my-logos",
Namespace: namespaceName,
Key: "apple-touch-icon-152x152.png",
},
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,9 @@ var _ = Describe("WorkspaceKind Controller", func() {
newWorkspaceKind.Spec.Spawner.Icon = kubefloworgv1beta1.WorkspaceKindIcon{
Url: ptr.To("https://example.com/icon.png"),
ConfigMap: &kubefloworgv1beta1.WorkspaceKindConfigMap{
Name: "my-logos",
Key: "icon.png",
Name: "my-logos",
Namespace: namespaceName,
Key: "icon.png",
},
}
Expect(k8sClient.Patch(ctx, newWorkspaceKind, patch)).NotTo(Succeed())
Expand Down
7 changes: 5 additions & 2 deletions workspaces/controller/internal/webhook/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ var (
cancel context.CancelFunc
)

const namespaceName = "default"

func TestAPIs(t *testing.T) {
RegisterFailHandler(Fail)

Expand Down Expand Up @@ -186,8 +188,9 @@ func NewExampleWorkspaceKind(name string) *kubefloworgv1beta1.WorkspaceKind {
},
Logo: kubefloworgv1beta1.WorkspaceKindIcon{
ConfigMap: &kubefloworgv1beta1.WorkspaceKindConfigMap{
Name: "my-logos",
Key: "apple-touch-icon-152x152.png",
Name: "my-logos",
Namespace: namespaceName,
Key: "apple-touch-icon-152x152.png",
},
},
},
Expand Down