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

PR: Create CodeEditor Deployment #240

Merged
merged 20 commits into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
5514435
refactor(api): create api for codeeditor
tunahanertekin Mar 5, 2024
a33dafd
refactor(controller): create codeeditor controller
tunahanertekin Mar 5, 2024
081e2f9
refactor(controller): implement fundamental reconciler methods
tunahanertekin Mar 5, 2024
889f9c5
refactor(api): add owned pvc fields to codeeditor
tunahanertekin Mar 5, 2024
f99e91a
refactor(resources): rename resource getter functions
tunahanertekin Mar 6, 2024
4d80702
refactor(resources): define codeeditor pvcs
tunahanertekin Mar 6, 2024
7070183
build(manifests): :whale: update internal manifests
tunahanertekin Mar 6, 2024
5f04d3e
refactor(pvc): handle lifecycle of owned pvcs
tunahanertekin Mar 6, 2024
5ad0110
refactor(bridge): update bridge port
tunahanertekin Mar 6, 2024
996c3ac
refactor(api): add fields for external volumes
tunahanertekin Mar 6, 2024
57c4e96
refactor(check): check external volumes
tunahanertekin Mar 6, 2024
45ad290
chore(rbac): add rbac markers for deployment
tunahanertekin Mar 6, 2024
728ebd7
refactor(api): add deployment related fields to codeeditor api
tunahanertekin Mar 6, 2024
955cb8f
refactor(api): add port to codeeditor api
tunahanertekin Mar 6, 2024
ea60f22
refactor(deployment): define code editor deployment
tunahanertekin Mar 6, 2024
c1ca244
refactor(controller): handle creation of deployment
tunahanertekin Mar 6, 2024
5ab957a
refactor(api): add linux user field to api
tunahanertekin Mar 6, 2024
2bb2a83
refactor(controller): check deployment status
tunahanertekin Mar 6, 2024
f97bd01
build(manifests): :whale: update internal manifests
tunahanertekin Mar 6, 2024
7d19554
refactor(statefulset): extend statefulset check logic
tunahanertekin Mar 7, 2024
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
13 changes: 13 additions & 0 deletions PROJECT
Original file line number Diff line number Diff line change
Expand Up @@ -182,4 +182,17 @@ resources:
defaulting: true
validation: true
webhookVersion: v1
- api:
crdVersion: v1
namespaced: true
controller: true
domain: roboscale.io
group: robot
kind: CodeEditor
path: github.com/robolaunch/robot-operator/pkg/api/roboscale.io/v1alpha2
version: v1alpha2
webhooks:
defaulting: true
validation: true
webhookVersion: v1
version: "3"
2,523 changes: 2,523 additions & 0 deletions config/crd/bases/robot.roboscale.io_codeeditors.yaml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion config/crd/bases/robot.roboscale.io_ros2workloads.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2622,7 +2622,7 @@ spec:
- created
type: object
status:
description: Status of the ROS2Bridge instance.
description: Status of the StatefulSet.
properties:
availableReplicas:
description: Total number of available pods (ready for at
Expand Down
3 changes: 3 additions & 0 deletions config/crd/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ resources:
- bases/robot.roboscale.io_notebooks.yaml
- bases/robot.roboscale.io_ros2workloads.yaml
- bases/robot.roboscale.io_ros2bridges.yaml
- bases/robot.roboscale.io_codeeditors.yaml
#+kubebuilder:scaffold:crdkustomizeresource

patchesStrategicMerge:
Expand All @@ -41,6 +42,7 @@ patchesStrategicMerge:
#- patches/webhook_in_notebooks.yaml
#- patches/webhook_in_ros2workloads.yaml
#- patches/webhook_in_ros2bridges.yaml
#- patches/webhook_in_codeeditors.yaml
#+kubebuilder:scaffold:crdkustomizewebhookpatch

# [CERTMANAGER] To enable cert-manager, uncomment all the sections with [CERTMANAGER] prefix.
Expand All @@ -61,6 +63,7 @@ patchesStrategicMerge:
#- patches/cainjection_in_notebooks.yaml
#- patches/cainjection_in_ros2workloads.yaml
#- patches/cainjection_in_ros2bridges.yaml
#- patches/cainjection_in_codeeditors.yaml
#+kubebuilder:scaffold:crdkustomizecainjectionpatch

# the following config is for teaching kustomize how to do kustomization for CRDs.
Expand Down
7 changes: 7 additions & 0 deletions config/crd/patches/cainjection_in_codeeditors.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# The following patch adds a directive for certmanager to inject CA into the CRD
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
cert-manager.io/inject-ca-from: $(CERTIFICATE_NAMESPACE)/$(CERTIFICATE_NAME)
name: codeeditors.robot.roboscale.io
16 changes: 16 additions & 0 deletions config/crd/patches/webhook_in_codeeditors.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# The following patch enables a conversion webhook for the CRD
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
name: codeeditors.robot.roboscale.io
spec:
conversion:
strategy: Webhook
webhook:
clientConfig:
service:
namespace: system
name: webhook-service
path: /convert
conversionReviewVersions:
- v1
31 changes: 31 additions & 0 deletions config/rbac/codeeditor_editor_role.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# permissions for end users to edit codeeditors.
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
labels:
app.kubernetes.io/name: clusterrole
app.kubernetes.io/instance: codeeditor-editor-role
app.kubernetes.io/component: rbac
app.kubernetes.io/created-by: robot-operator
app.kubernetes.io/part-of: robot-operator
app.kubernetes.io/managed-by: kustomize
name: codeeditor-editor-role
rules:
- apiGroups:
- robot.roboscale.io
resources:
- codeeditors
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- robot.roboscale.io
resources:
- codeeditors/status
verbs:
- get
27 changes: 27 additions & 0 deletions config/rbac/codeeditor_viewer_role.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# permissions for end users to view codeeditors.
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
labels:
app.kubernetes.io/name: clusterrole
app.kubernetes.io/instance: codeeditor-viewer-role
app.kubernetes.io/component: rbac
app.kubernetes.io/created-by: robot-operator
app.kubernetes.io/part-of: robot-operator
app.kubernetes.io/managed-by: kustomize
name: codeeditor-viewer-role
rules:
- apiGroups:
- robot.roboscale.io
resources:
- codeeditors
verbs:
- get
- list
- watch
- apiGroups:
- robot.roboscale.io
resources:
- codeeditors/status
verbs:
- get
38 changes: 38 additions & 0 deletions config/rbac/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,18 @@ metadata:
creationTimestamp: null
name: manager-role
rules:
- apiGroups:
- apps
resources:
- deployments
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- apps
resources:
Expand Down Expand Up @@ -187,6 +199,32 @@ rules:
- get
- patch
- update
- apiGroups:
- robot.roboscale.io
resources:
- codeeditors
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- robot.roboscale.io
resources:
- codeeditors/finalizers
verbs:
- update
- apiGroups:
- robot.roboscale.io
resources:
- codeeditors/status
verbs:
- get
- patch
- update
- apiGroups:
- robot.roboscale.io
resources:
Expand Down
40 changes: 40 additions & 0 deletions config/webhook/manifests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,26 @@ webhooks:
resources:
- ros2bridges
sideEffects: None
- admissionReviewVersions:
- v1
clientConfig:
service:
name: webhook-service
namespace: system
path: /mutate-robot-roboscale-io-v1alpha2-codeeditor
failurePolicy: Fail
name: mcodeeditor.kb.io
rules:
- apiGroups:
- robot.roboscale.io
apiVersions:
- v1alpha2
operations:
- CREATE
- UPDATE
resources:
- codeeditors
sideEffects: None
---
apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingWebhookConfiguration
Expand Down Expand Up @@ -452,3 +472,23 @@ webhooks:
resources:
- ros2bridges
sideEffects: None
- admissionReviewVersions:
- v1
clientConfig:
service:
name: webhook-service
namespace: system
path: /validate-robot-roboscale-io-v1alpha2-codeeditor
failurePolicy: Fail
name: vcodeeditor.kb.io
rules:
- apiGroups:
- robot.roboscale.io
apiVersions:
- v1alpha2
operations:
- CREATE
- UPDATE
resources:
- codeeditors
sideEffects: None
20 changes: 20 additions & 0 deletions internal/configure/v1alpha2/linux_user.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package configure

import (
corev1 "k8s.io/api/core/v1"
)

func (cfg *PodSpecConfigInjector) InjectLinuxUserAndGroup(podSpec *corev1.PodSpec) {

var user int64 = 1000
var group int64 = 3000

for key, cont := range podSpec.Containers {
cont.SecurityContext = &corev1.SecurityContext{
RunAsUser: &user,
RunAsGroup: &group,
Privileged: cont.SecurityContext.Privileged,
}
podSpec.Containers[key] = cont
}
}
6 changes: 3 additions & 3 deletions internal/configure/v1alpha2/runtime_class.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ package configure
import (
"github.com/robolaunch/robot-operator/internal/label"
"github.com/robolaunch/robot-operator/internal/node"
"github.com/robolaunch/robot-operator/pkg/api/roboscale.io/v1alpha2"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

func (cfg *PodSpecConfigInjector) InjectRuntimeClass(podSpec *corev1.PodSpec, ros2Workload v1alpha2.ROS2Workload, currentNode corev1.Node) {
if label.GetInstanceType(&ros2Workload) == label.InstanceTypeCloudInstance && node.IsK3s(currentNode) {
func (cfg *PodSpecConfigInjector) InjectRuntimeClass(podSpec *corev1.PodSpec, obj metav1.Object, currentNode corev1.Node) {
if label.GetInstanceType(obj) == label.InstanceTypeCloudInstance && node.IsK3s(currentNode) {
nvidiaRuntimeClass := "nvidia"
podSpec.RuntimeClassName = &nvidiaRuntimeClass
}
Expand Down
25 changes: 21 additions & 4 deletions internal/configure/v1alpha2/volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,16 @@ import (
corev1 "k8s.io/api/core/v1"
)

func (cfg *PodSpecConfigInjector) InjectVolumeConfiguration(podSpec *corev1.PodSpec, ros2Workload robotv1alpha2.ROS2Workload) {
cfg.injectOwnedPVCVolumes(podSpec, ros2Workload)
func (cfg *PodSpecConfigInjector) InjectVolumeConfiguration(podSpec *corev1.PodSpec, pvcStatuses []robotv1alpha2.OwnedPVCStatus) {
cfg.injectOwnedPVCVolumes(podSpec, pvcStatuses)
}

func (cfg *PodSpecConfigInjector) injectOwnedPVCVolumes(podSpec *corev1.PodSpec, ros2Workload robotv1alpha2.ROS2Workload) {
for _, pvcStatus := range ros2Workload.Status.PVCStatuses {
func (cfg *PodSpecConfigInjector) InjectExternalVolumeConfiguration(podSpec *corev1.PodSpec, evStatuses []robotv1alpha2.ExternalVolumeStatus) {
cfg.injectExternalPVCVolumes(podSpec, evStatuses)
}

func (cfg *PodSpecConfigInjector) injectOwnedPVCVolumes(podSpec *corev1.PodSpec, pvcStatuses []robotv1alpha2.OwnedPVCStatus) {
for _, pvcStatus := range pvcStatuses {
podSpec.Volumes = append(podSpec.Volumes, corev1.Volume{
Name: pvcStatus.Resource.Reference.Name,
VolumeSource: corev1.VolumeSource{
Expand All @@ -21,3 +25,16 @@ func (cfg *PodSpecConfigInjector) injectOwnedPVCVolumes(podSpec *corev1.PodSpec,
})
}
}

func (cfg *PodSpecConfigInjector) injectExternalPVCVolumes(podSpec *corev1.PodSpec, evStatuses []robotv1alpha2.ExternalVolumeStatus) {
for _, evStatus := range evStatuses {
podSpec.Volumes = append(podSpec.Volumes, corev1.Volume{
Name: evStatus.Name,
VolumeSource: corev1.VolumeSource{
PersistentVolumeClaim: &corev1.PersistentVolumeClaimVolumeSource{
ClaimName: evStatus.Name,
},
},
})
}
}
Loading
Loading