Skip to content

Commit 72ac518

Browse files
committed
Adding SandboxTemplate and SandboxClaim CRDs
SanboxTemplate: * Config object no controller expected for this * Created by administrator to specify common parameters for a sandbox * example names: py3, java8, conda-teamA, ... * We use claims to create a Sandbox instance from the template * template is cluster scoped SandboxClaim: * Create an instance of sandbox from a given claim * ttl determines after how long the sandboxClaim is auto-deleted, thereby deleting the sandbox * Seperation of concerns. User can be given access to create only claims.
1 parent 7052216 commit 72ac518

File tree

7 files changed

+4245
-1
lines changed

7 files changed

+4245
-1
lines changed

codegen.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,6 @@
1616

1717
package agentsandbox
1818

19-
//go:generate go tool -modfile=tools.mod sigs.k8s.io/controller-tools/cmd/controller-gen object crd:maxDescLen=0 paths="./..." output:crd:dir=k8s/crds output:rbac:dir=k8s rbac:roleName=agent-sandbox-controller,fileName=rbac.generated.yaml
19+
// Generate CRDs and RBAC rules
20+
//go:generate go tool -modfile=tools.mod sigs.k8s.io/controller-tools/cmd/controller-gen object crd:maxDescLen=0 paths="./api/..." output:crd:dir=k8s/crds output:rbac:dir=k8s rbac:roleName=agent-sandbox-controller,fileName=rbac.generated.yaml
21+
//go:generate go tool -modfile=tools.mod sigs.k8s.io/controller-tools/cmd/controller-gen object crd:maxDescLen=0 paths="./extensions/..." output:crd:dir=k8s/crds output:rbac:dir=k8s rbac:roleName=agent-sandbox-controller,fileName=rbac.generated.yaml
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Copyright 2025 The Kubernetes Authors.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
// Package v1alpha1 contains API Schema definitions for the agents v1alpha1 API group.
16+
// +kubebuilder:object:generate=true
17+
// +groupName=extensions.agents.x-k8s.io
18+
package v1alpha1
19+
20+
import (
21+
"k8s.io/apimachinery/pkg/runtime/schema"
22+
"sigs.k8s.io/controller-runtime/pkg/scheme"
23+
)
24+
25+
var (
26+
// GroupVersion is group version used to register these objects.
27+
GroupVersion = schema.GroupVersion{Group: "extensions.agents.x-k8s.io", Version: "v1alpha1"}
28+
29+
// SchemeBuilder is used to add go types to the GroupVersionKind scheme.
30+
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion}
31+
32+
// AddToScheme adds the types in this group-version to the given scheme.
33+
AddToScheme = SchemeBuilder.AddToScheme
34+
)
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*
2+
Copyright 2025.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package v1alpha1
18+
19+
import (
20+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
21+
)
22+
23+
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.
24+
// Important: Run "make" to regenerate code after modifying this file
25+
26+
// SandboxClaimSpec defines the desired state of Sandbox
27+
type SandboxClaimSpec struct {
28+
ShutdownTime *metav1.Time `json:"shutdownTime,omitempty" protobuf:"bytes,1,opt,name=shutdownTime"`
29+
30+
// SandboxTemplateRefName - name of the SandboxTemplate to be used for creating a Sandbox
31+
// +kubebuilder:validation:Required
32+
SandboxTemplateRefName string `json:"sandboxTemplateRefName,omitempty" protobuf:"bytes,3,name=sandboxTemplateRefName"`
33+
}
34+
35+
// SandboxClaimStatus defines the observed state of Sandbox.
36+
type SandboxClaimStatus struct {
37+
}
38+
39+
// +kubebuilder:object:root=true
40+
// +kubebuilder:subresource:status
41+
// +kubebuilder:resource:scope=Namespaced,shortName=sandboxclaim
42+
// SandboxClaim is the Schema for the sandbox Claim API
43+
type SandboxClaim struct {
44+
metav1.TypeMeta `json:",inline"`
45+
46+
// metadata is a standard object metadata
47+
// +optional
48+
metav1.ObjectMeta `json:"metadata,omitempty,omitzero"`
49+
50+
// spec defines the desired state of Sandbox
51+
// +required
52+
Spec SandboxClaimSpec `json:"spec"`
53+
54+
// status defines the observed state of Sandbox
55+
// +optional
56+
Status SandboxClaimStatus `json:"status,omitempty,omitzero"`
57+
}
58+
59+
// +kubebuilder:object:root=true
60+
61+
// SandboxList contains a list of Sandbox
62+
type SandboxClaimList struct {
63+
metav1.TypeMeta `json:",inline"`
64+
metav1.ListMeta `json:"metadata,omitempty"`
65+
Items []SandboxClaim `json:"items"`
66+
}
67+
68+
func init() {
69+
SchemeBuilder.Register(&SandboxClaim{}, &SandboxClaimList{})
70+
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/*
2+
Copyright 2025.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package v1alpha1
18+
19+
import (
20+
corev1 "k8s.io/api/core/v1"
21+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
22+
)
23+
24+
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.
25+
// Important: Run "make" to regenerate code after modifying this file
26+
27+
// SandboxTemplateSpec defines the desired state of Sandbox
28+
type SandboxTemplateSpec struct {
29+
// The following markers will use OpenAPI v3 schema to validate the value
30+
// More info: https://book.kubebuilder.io/reference/markers/crd-validation.html
31+
32+
TTLSeconds *int32 `json:"ttlSeconds,omitempty" protobuf:"varint,1,opt,name=ttlSeconds"`
33+
// template is the object that describes the pod spec that will be used to create
34+
// an agent sandbox.
35+
// +kubebuilder:validation:Required
36+
PodTemplate corev1.PodTemplateSpec `json:"podTemplate" protobuf:"bytes,3,opt,name=podTemplate"`
37+
}
38+
39+
// SandboxTemplateStatus defines the observed state of Sandbox.
40+
type SandboxTemplateStatus struct {
41+
}
42+
43+
// +kubebuilder:object:root=true
44+
// +kubebuilder:subresource:status
45+
// +kubebuilder:resource:scope=Cluster,shortName=sandboxtemplate
46+
// SandboxTemplate is the Schema for the sandboxe template API
47+
type SandboxTemplate struct {
48+
metav1.TypeMeta `json:",inline"`
49+
50+
// metadata is a standard object metadata
51+
// +optional
52+
metav1.ObjectMeta `json:"metadata,omitempty,omitzero"`
53+
54+
// spec defines the desired state of Sandbox
55+
// +required
56+
Spec SandboxTemplateSpec `json:"spec"`
57+
58+
// status defines the observed state of Sandbox
59+
// +optional
60+
Status SandboxTemplateStatus `json:"status,omitempty,omitzero"`
61+
}
62+
63+
// +kubebuilder:object:root=true
64+
65+
// SandboxTemplateList contains a list of Sandbox
66+
type SandboxTemplateList struct {
67+
metav1.TypeMeta `json:",inline"`
68+
metav1.ListMeta `json:"metadata,omitempty"`
69+
Items []SandboxTemplate `json:"items"`
70+
}
71+
72+
func init() {
73+
SchemeBuilder.Register(&SandboxTemplate{}, &SandboxTemplateList{})
74+
}

extensions/api/v1alpha1/zz_generated.deepcopy.go

Lines changed: 197 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)