Skip to content

Commit

Permalink
Add default option to storageclass (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
majst01 authored Feb 7, 2022
1 parent a38da72 commit 37e0d18
Show file tree
Hide file tree
Showing 6 changed files with 205 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ export CGO_ENABLED := 0
# Image URL to use all building/pushing image targets
IMG ?= duros-controller:latest
# Produce CRDs that work back to Kubernetes 1.11 (no version conversion)
CRD_OPTIONS ?= "crd:trivialVersions=true"
CRD_OPTIONS ?= "crd"

SHA := $(shell git rev-parse --short=8 HEAD)
GITVERSION := $(shell git describe --long --all)
Expand Down
1 change: 1 addition & 0 deletions api/v1/duros_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ type StorageClass struct {
Name string `json:"name"`
ReplicaCount int `json:"replicas"`
Compression bool `json:"compression"`
Default bool `json:"default" description:"if set to true this storageclass is configured as default"`
}

func init() {
Expand Down
5 changes: 4 additions & 1 deletion config/crd/bases/storage.metal-stack.io_duros.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.6.2
controller-gen.kubebuilder.io/version: v0.7.0
creationTimestamp: null
name: duros.storage.metal-stack.io
spec:
Expand Down Expand Up @@ -54,12 +54,15 @@ spec:
properties:
compression:
type: boolean
default:
type: boolean
name:
type: string
replicas:
type: integer
required:
- compression
- default
- name
- replicas
type: object
Expand Down
8 changes: 8 additions & 0 deletions controllers/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/golang-jwt/jwt/v4"
"github.com/metal-stack/duros-go"
durosv2 "github.com/metal-stack/duros-go/api/duros/v2"
metaltag "github.com/metal-stack/metal-lib/pkg/tag"

storagev1 "github.com/metal-stack/duros-controller/api/v1"
apps "k8s.io/api/apps/v1"
Expand Down Expand Up @@ -976,8 +977,15 @@ func (r *DurosReconciler) deployCSI(ctx context.Context, projectID string, scs [

for i := range scs {
sc := scs[i]

annotations := map[string]string{
"storageclass.kubernetes.io/is-default-class": strconv.FormatBool(sc.Default),
metaltag.ClusterDescription: "DO NOT EDIT - This resource is managed by duros-controller. Any modifications are discarded and the resource is returned to the original state.",
}

obj := &storage.StorageClass{ObjectMeta: metav1.ObjectMeta{Name: sc.Name}}
op, err = controllerutil.CreateOrUpdate(ctx, r.Shoot, obj, func() error {
obj.ObjectMeta.Annotations = annotations
obj.Provisioner = provisioner
obj.AllowVolumeExpansion = pointer.Bool(true)
obj.Parameters = map[string]string{
Expand Down
5 changes: 4 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ go 1.16

require (
cloud.google.com/go v0.99.0 // indirect
github.com/go-logr/logr v0.4.0
github.com/go-logr/logr v1.0.0
github.com/go-logr/zapr v0.4.0
github.com/golang-jwt/jwt/v4 v4.2.0
github.com/google/gofuzz v1.2.0 // indirect
github.com/metal-stack/duros-go v0.3.0
github.com/metal-stack/metal-lib v0.9.0
github.com/metal-stack/v v1.0.3
github.com/onsi/ginkgo v1.16.5
github.com/onsi/gomega v1.17.0
Expand All @@ -22,3 +23,5 @@ require (
k8s.io/utils v0.0.0-20211203121628-587287796c64
sigs.k8s.io/controller-runtime v0.10.3
)

replace github.com/go-logr/logr => github.com/go-logr/logr v0.4.0
Loading

0 comments on commit 37e0d18

Please sign in to comment.