blob: b41c2c9741ee704463290ee6f3f09a01b1c5113a [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
Lorenz Brun6211e4d2023-11-14 19:09:40 +010022 node "k8s.io/api/node/v1"
Lorenz Brun5e4fc2d2020-09-22 18:35:15 +020023 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 Brun6211e4d2023-11-14 19:09:40 +010032 res, err := r.NodeV1().RuntimeClasses().List(ctx, listBuiltins)
Lorenz Brun5e4fc2d2020-09-22 18:35:15 +020033 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 Brun6211e4d2023-11-14 19:09:40 +010044 _, err := r.NodeV1().RuntimeClasses().Create(ctx, el.(*node.RuntimeClass), meta.CreateOptions{})
Lorenz Brun5e4fc2d2020-09-22 18:35:15 +020045 return err
46}
47
48func (r resourceRuntimeClasses) Delete(ctx context.Context, name string) error {
Lorenz Brun6211e4d2023-11-14 19:09:40 +010049 return r.NodeV1().RuntimeClasses().Delete(ctx, name, meta.DeleteOptions{})
Lorenz Brun5e4fc2d2020-09-22 18:35:15 +020050}
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}