Skip to content
This repository has been archived by the owner on Mar 16, 2024. It is now read-only.

Commit

Permalink
Add support for runtime classes
Browse files Browse the repository at this point in the history
Runtime classes are added as in internal value on Acorn compute
class objects. This allows for using things like Kata Containers.

Signed-off-by: Bill Maxwell <[email protected]>
  • Loading branch information
cloudnautique committed Dec 5, 2023
1 parent 8691e0d commit 1a1e7fa
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 10 deletions.
1 change: 1 addition & 0 deletions pkg/apis/internal.acorn.io/v1/appinstance.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ type Scheduling struct {
Affinity *corev1.Affinity `json:"affinity,omitempty"`
Tolerations []corev1.Toleration `json:"tolerations,omitempty"`
PriorityClassName string `json:"priorityClassName,omitempty"`
RuntimeClassName string `json:"runtimeClassName,omitempty"`
}

type Endpoint struct {
Expand Down
1 change: 1 addition & 0 deletions pkg/apis/internal.admin.acorn.io/v1/computeclasses.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ type ProjectComputeClassInstance struct {
Memory ComputeClassMemory `json:"memory,omitempty"`
SupportedRegions []string `json:"supportedRegions,omitempty"`
PriorityClassName string `json:"priorityClassName,omitempty"`
RuntimeClassName string `json:"runtimeClassName,omitempty"`
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
Expand Down
1 change: 1 addition & 0 deletions pkg/controller/appdefinition/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -778,6 +778,7 @@ func toDeployment(req router.Request, appInstance *v1.AppInstance, tag name.Refe
Affinity: appInstance.Status.Scheduling[name].Affinity,
Tolerations: appInstance.Status.Scheduling[name].Tolerations,
PriorityClassName: appInstance.Status.Scheduling[name].PriorityClassName,
RuntimeClassName: z.Pointer[string](appInstance.Status.Scheduling[name].RuntimeClassName),
TerminationGracePeriodSeconds: z.Pointer[int64](10),
ImagePullSecrets: pullSecrets.ForContainer(name, append(containers, initContainers...)),
EnableServiceLinks: new(bool),
Expand Down
26 changes: 24 additions & 2 deletions pkg/controller/scheduling/scheduling.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
tl "github.com/acorn-io/runtime/pkg/tolerations"
"github.com/acorn-io/z"
corev1 "k8s.io/api/core/v1"
nodev1 "k8s.io/api/node/v1"
schedulingv1 "k8s.io/api/scheduling/v1"
"k8s.io/apimachinery/pkg/api/resource"
)
Expand Down Expand Up @@ -78,7 +79,12 @@ func addScheduling(req router.Request, appInstance *v1.AppInstance, workloads ma

affinity, tolerations = Nodes(req, computeClass)

priorityClassName, err := PriorityClassName(req, computeClass)
priorityClassName, err := priorityClassName(req, computeClass)
if err != nil {
return err
}

runtimeClassName, err := runtimeClassName(req, computeClass)
if err != nil {
return err
}
Expand All @@ -97,6 +103,7 @@ func addScheduling(req router.Request, appInstance *v1.AppInstance, workloads ma
Affinity: affinity,
Tolerations: tolerations,
PriorityClassName: priorityClassName,
RuntimeClassName: runtimeClassName,
}
}
return nil
Expand All @@ -111,7 +118,7 @@ func Nodes(req router.Request, computeClass *adminv1.ProjectComputeClassInstance
}

// PriorityClassName checks that a defined PriorityClass exists and returns the name of it
func PriorityClassName(req router.Request, computeClass *adminv1.ProjectComputeClassInstance) (string, error) {
func priorityClassName(req router.Request, computeClass *adminv1.ProjectComputeClassInstance) (string, error) {
if computeClass == nil || computeClass.PriorityClassName == "" {
return "", nil
}
Expand All @@ -125,6 +132,21 @@ func PriorityClassName(req router.Request, computeClass *adminv1.ProjectComputeC
return computeClass.PriorityClassName, nil
}

// RuntimeClassName checks that a defined RuntimeClass exists and returns the name of it
func runtimeClassName(req router.Request, computeClass *adminv1.ProjectComputeClassInstance) (string, error) {
if computeClass == nil || computeClass.RuntimeClassName == "" {
return "", nil
}

// Verify that the RuntimeClass exists
runtimeClassName := &nodev1.RuntimeClass{}
if err := req.Client.Get(req.Ctx, router.Key("", computeClass.RuntimeClassName), runtimeClassName); err != nil {
return "", err
}

return computeClass.RuntimeClassName, nil
}

// ResourceRequirements determines the cpu and memory amount to be set for the limits/requests of the Pod
func ResourceRequirements(req router.Request, app *v1.AppInstance, containerName string, container v1.Container, computeClass *adminv1.ProjectComputeClassInstance) (*corev1.ResourceRequirements, error) {
cfg, err := config.Get(req.Ctx, req.Client)
Expand Down
20 changes: 12 additions & 8 deletions pkg/install/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ rules:
apiGroups: [""]
resources:
- nodes
- verbs: ["get", "list", "watch"]
apiGroups: ["node.k8s.io"]
resources:
- runtimeclasses
- verbs: ["*"]
apiGroups: ["apiextensions.k8s.io"]
resources:
Expand All @@ -46,7 +50,7 @@ rules:
- verbs: ["get", "list", "watch"]
apiGroups: ["networking.k8s.io"]
resources:
- ingressclasses
- ingressclasses
- verbs: ["*"]
apiGroups: ["batch"]
resources:
Expand Down Expand Up @@ -87,11 +91,11 @@ rules:
verbs: ["updatepsa"]
- verbs: ["use"]
apiGroups:
- security.openshift.io
- security.openshift.io
resourceNames:
- nonroot-v2
- nonroot-v2
resources:
- securitycontextconstraints
- securitycontextconstraints

---
kind: ClusterRoleBinding
Expand All @@ -114,11 +118,11 @@ metadata:
rules:
- verbs: ["use"]
apiGroups:
- security.openshift.io
- security.openshift.io
resourceNames:
- nonroot-v2
- nonroot-v2
resources:
- securitycontextconstraints
- securitycontextconstraints
---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
Expand All @@ -131,4 +135,4 @@ roleRef:
subjects:
- kind: ServiceAccount
namespace: acorn-image-system
name: acorn-image-system
name: acorn-image-system
30 changes: 30 additions & 0 deletions pkg/openapi/generated/openapi_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions pkg/scheme/scheme.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
corev1 "k8s.io/api/core/v1"
discoveryv1 "k8s.io/api/discovery/v1"
networkingv1 "k8s.io/api/networking/v1"
nodev1 "k8s.io/api/node/v1"
policyv1 "k8s.io/api/policy/v1"
rbacv1 "k8s.io/api/rbac/v1"
schedulingv1 "k8s.io/api/scheduling/v1"
Expand Down Expand Up @@ -45,6 +46,7 @@ func AddToScheme(scheme *runtime.Scheme) error {
errs = append(errs, policyv1.AddToScheme(scheme))
errs = append(errs, batchv1.AddToScheme(scheme))
errs = append(errs, networkingv1.AddToScheme(scheme))
errs = append(errs, nodev1.AddToScheme(scheme))
errs = append(errs, storagev1.AddToScheme(scheme))
errs = append(errs, apiregistrationv1.AddToScheme(scheme))
errs = append(errs, rbacv1.AddToScheme(scheme))
Expand Down

0 comments on commit 1a1e7fa

Please sign in to comment.