blob: ecbcb4bcb714a2304dc1de1b0f273ddfbfcca862 [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 storage "k8s.io/api/storage/v1"
23 meta "k8s.io/apimachinery/pkg/apis/meta/v1"
24 "k8s.io/client-go/kubernetes"
25)
26
Serge Bazanski77cb6c52020-12-19 00:09:22 +010027// TODO(q3k): this is duplicated with //metropolis/node/kubernetes:provisioner.go; integrate this once provisioner.go
Serge Bazanskie6030f62020-06-03 17:52:59 +020028// gets moved into a subpackage.
Serge Bazanski77cb6c52020-12-19 00:09:22 +010029// ONCHANGE(//metropolis/node/kubernetes:provisioner.go): needs to match csiProvisionerName declared.
Serge Bazanskie6030f62020-06-03 17:52:59 +020030const csiProvisionerName = "com.nexantic.smalltown.vfs"
31
32type resourceCSIDrivers struct {
33 kubernetes.Interface
34}
35
36func (r resourceCSIDrivers) List(ctx context.Context) ([]string, error) {
37 res, err := r.StorageV1().CSIDrivers().List(ctx, listBuiltins)
38 if err != nil {
39 return nil, err
40 }
41 objs := make([]string, len(res.Items))
42 for i, el := range res.Items {
43 objs[i] = el.ObjectMeta.Name
44 }
45 return objs, nil
46}
47
48func (r resourceCSIDrivers) Create(ctx context.Context, el interface{}) error {
49 _, err := r.StorageV1().CSIDrivers().Create(ctx, el.(*storage.CSIDriver), meta.CreateOptions{})
50 return err
51}
52
53func (r resourceCSIDrivers) Delete(ctx context.Context, name string) error {
54 return r.StorageV1().CSIDrivers().Delete(ctx, name, meta.DeleteOptions{})
55}
56
57func (r resourceCSIDrivers) Expected() map[string]interface{} {
58 return map[string]interface{}{
59 csiProvisionerName: &storage.CSIDriver{
60 ObjectMeta: meta.ObjectMeta{
61 Name: csiProvisionerName,
62 Labels: builtinLabels(nil),
63 },
64 Spec: storage.CSIDriverSpec{
65 AttachRequired: False(),
66 PodInfoOnMount: False(),
67 VolumeLifecycleModes: []storage.VolumeLifecycleMode{storage.VolumeLifecyclePersistent},
68 },
69 },
70 }
71}