blob: 11c2fa01ee54da245f9760a62437f3f5fe8f7ba8 [file] [log] [blame]
Lorenz Brun5e4fc2d2020-09-22 18:35:15 +02001// Copyright 2020 The Monogon Project Authors.
2//
3// SPDX-License-Identifier: Apache-2.0
4//
5// Licensed under the Apache License, Version 2.0 (the "License");
6// you may not use this file except in compliance with the License.
7// You may obtain a copy of the License at
8//
9// http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing, software
12// distributed under the License is distributed on an "AS IS" BASIS,
13// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14// See the License for the specific language governing permissions and
15// limitations under the License.
16
17package reconciler
18
19import (
20 "context"
21
22 node "k8s.io/api/node/v1beta1"
23 meta "k8s.io/apimachinery/pkg/apis/meta/v1"
24 "k8s.io/client-go/kubernetes"
25)
26
27type resourceRuntimeClasses struct {
28 kubernetes.Interface
29}
30
Jan Schär7f727482024-03-25 13:03:51 +010031func (r resourceRuntimeClasses) List(ctx context.Context) ([]meta.Object, error) {
Lorenz Brun5e4fc2d2020-09-22 18:35:15 +020032 res, err := r.NodeV1beta1().RuntimeClasses().List(ctx, listBuiltins)
33 if err != nil {
34 return nil, err
35 }
Jan Schär7f727482024-03-25 13:03:51 +010036 objs := make([]meta.Object, len(res.Items))
37 for i := range res.Items {
38 objs[i] = &res.Items[i]
Lorenz Brun5e4fc2d2020-09-22 18:35:15 +020039 }
40 return objs, nil
41}
42
Jan Schär7f727482024-03-25 13:03:51 +010043func (r resourceRuntimeClasses) Create(ctx context.Context, el meta.Object) error {
Lorenz Brun5e4fc2d2020-09-22 18:35:15 +020044 _, err := r.NodeV1beta1().RuntimeClasses().Create(ctx, el.(*node.RuntimeClass), meta.CreateOptions{})
45 return err
46}
47
48func (r resourceRuntimeClasses) Delete(ctx context.Context, name string) error {
49 return r.NodeV1beta1().RuntimeClasses().Delete(ctx, name, meta.DeleteOptions{})
50}
51
Jan Schär7f727482024-03-25 13:03:51 +010052func (r resourceRuntimeClasses) Expected() []meta.Object {
53 return []meta.Object{
54 &node.RuntimeClass{
Lorenz Brun5e4fc2d2020-09-22 18:35:15 +020055 ObjectMeta: meta.ObjectMeta{
56 Name: "gvisor",
57 Labels: builtinLabels(nil),
58 },
59 Handler: "runsc",
60 },
Jan Schär7f727482024-03-25 13:03:51 +010061 &node.RuntimeClass{
Lorenz Brun5e4fc2d2020-09-22 18:35:15 +020062 ObjectMeta: meta.ObjectMeta{
63 Name: "runc",
64 Labels: builtinLabels(nil),
65 },
66 Handler: "runc",
67 },
68 }
69}