blob: 36dee1c832d6b54d4512627ada4db1916dbd390a [file] [log] [blame]
Serge Bazanskie6030f62020-06-03 17:52:59 +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 core "k8s.io/api/core/v1"
23 storage "k8s.io/api/storage/v1"
24 meta "k8s.io/apimachinery/pkg/apis/meta/v1"
25 "k8s.io/client-go/kubernetes"
26)
27
28var reclaimPolicyDelete = core.PersistentVolumeReclaimDelete
29var waitForConsumerBinding = storage.VolumeBindingWaitForFirstConsumer
30
31type resourceStorageClasses struct {
32 kubernetes.Interface
33}
34
Jan Schär7f727482024-03-25 13:03:51 +010035func (r resourceStorageClasses) List(ctx context.Context) ([]meta.Object, error) {
Serge Bazanskie6030f62020-06-03 17:52:59 +020036 res, err := r.StorageV1().StorageClasses().List(ctx, listBuiltins)
37 if err != nil {
38 return nil, err
39 }
Jan Schär7f727482024-03-25 13:03:51 +010040 objs := make([]meta.Object, len(res.Items))
41 for i := range res.Items {
42 objs[i] = &res.Items[i]
Serge Bazanskie6030f62020-06-03 17:52:59 +020043 }
44 return objs, nil
45}
46
Jan Schär7f727482024-03-25 13:03:51 +010047func (r resourceStorageClasses) Create(ctx context.Context, el meta.Object) error {
Serge Bazanskie6030f62020-06-03 17:52:59 +020048 _, err := r.StorageV1().StorageClasses().Create(ctx, el.(*storage.StorageClass), meta.CreateOptions{})
49 return err
50}
51
Jan Schär69f5f4e2024-05-15 10:32:07 +020052func (r resourceStorageClasses) Update(ctx context.Context, el meta.Object) error {
53 _, err := r.StorageV1().StorageClasses().Update(ctx, el.(*storage.StorageClass), meta.UpdateOptions{})
54 return err
55}
56
57func (r resourceStorageClasses) Delete(ctx context.Context, name string, opts meta.DeleteOptions) error {
58 return r.StorageV1().StorageClasses().Delete(ctx, name, opts)
Serge Bazanskie6030f62020-06-03 17:52:59 +020059}
60
Jan Schär7f727482024-03-25 13:03:51 +010061func (r resourceStorageClasses) Expected() []meta.Object {
62 return []meta.Object{
63 &storage.StorageClass{
Serge Bazanskie6030f62020-06-03 17:52:59 +020064 ObjectMeta: meta.ObjectMeta{
65 Name: "local",
66 Labels: builtinLabels(nil),
67 Annotations: map[string]string{
68 "storageclass.kubernetes.io/is-default-class": "true",
Tim Windelschmidta8938da2024-09-13 22:34:01 +020069 "kubernetes.io/description": "local is the default storage class on Metropolis. " +
70 "It stores data on the node root disk and supports space limits, resizing and oversubscription but no snapshots. " +
71 "It is backed by XFS and uses permissive mounting options (exec,dev,suid). " +
72 "If you want more strict mounting options, chose the `local-strict` storage class.",
Serge Bazanskie6030f62020-06-03 17:52:59 +020073 },
74 },
75 AllowVolumeExpansion: True(),
76 Provisioner: csiProvisionerName,
77 ReclaimPolicy: &reclaimPolicyDelete,
78 VolumeBindingMode: &waitForConsumerBinding,
Tim Windelschmidta8938da2024-09-13 22:34:01 +020079 MountOptions: []string{
80 "exec",
81 "dev",
82 "suid",
83 },
84 },
85 &storage.StorageClass{
86 ObjectMeta: meta.ObjectMeta{
87 Name: "local-strict",
88 Labels: builtinLabels(nil),
89 Annotations: map[string]string{
90 "storageclass.kubernetes.io/is-default-class": "false",
91 "kubernetes.io/description": "local-strict is the same as local (see its description) but uses strict mount options (noexec, nodev, nosuid). " +
92 "It is best used together with readOnlyRoot to restrict exploitation vectors.",
93 },
94 },
95 AllowVolumeExpansion: True(),
96 Provisioner: csiProvisionerName,
97 ReclaimPolicy: &reclaimPolicyDelete,
98 VolumeBindingMode: &waitForConsumerBinding,
99 MountOptions: []string{
100 "noexec",
101 "nodev",
102 "nosuid",
103 },
Serge Bazanskie6030f62020-06-03 17:52:59 +0200104 },
105 }
106}