mirror of
https://github.com/ceph/ceph-csi.git
synced 2024-11-21 22:00:19 +00:00
deploy: move rbd/CSIDriver to API
Signed-off-by: Niels de Vos <ndevos@redhat.com>
This commit is contained in:
parent
f9c369918c
commit
584d43a132
20
api/deploy/kubernetes/doc.go
Normal file
20
api/deploy/kubernetes/doc.go
Normal file
@ -0,0 +1,20 @@
|
||||
/*
|
||||
Copyright 2021 The Ceph-CSI Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
// Package kubernetes contains functions to obtain standard and recommended
|
||||
// deployment artifacts for Kubernetes. These artifacts can be used by
|
||||
// automation tools that want to deploy Ceph-CSI.
|
||||
package kubernetes
|
74
api/deploy/kubernetes/rbd/csidriver.go
Normal file
74
api/deploy/kubernetes/rbd/csidriver.go
Normal file
@ -0,0 +1,74 @@
|
||||
/*
|
||||
Copyright 2021 The Ceph-CSI Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package rbd
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
_ "embed"
|
||||
"fmt"
|
||||
"text/template"
|
||||
|
||||
"github.com/ghodss/yaml"
|
||||
storagev1 "k8s.io/api/storage/v1"
|
||||
)
|
||||
|
||||
//go:embed csidriver.yaml
|
||||
var csiDriver string
|
||||
|
||||
type CSIDriverValues struct {
|
||||
Name string
|
||||
}
|
||||
|
||||
var CSIDriverDefaults = CSIDriverValues{
|
||||
Name: "rbd.csi.ceph.com",
|
||||
}
|
||||
|
||||
// NewCSIDriver takes a driver name from the CSIDriverValues struct and relaces
|
||||
// the value in the template. A CSIDriver object is returned which can be
|
||||
// created in the Kubernetes cluster.
|
||||
func NewCSIDriver(values CSIDriverValues) (*storagev1.CSIDriver, error) {
|
||||
data, err := NewCSIDriverYAML(values)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
driver := &storagev1.CSIDriver{}
|
||||
err = yaml.Unmarshal([]byte(data), driver)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed convert YAML to %T: %w", driver, err)
|
||||
}
|
||||
|
||||
return driver, nil
|
||||
}
|
||||
|
||||
// NewCSIDriverYAML takes a driver name from the CSIDriverValues struct and relaces
|
||||
// the value in the template. A CSIDriver object in YAML is returned which can be
|
||||
// created in the Kubernetes cluster.
|
||||
func NewCSIDriverYAML(values CSIDriverValues) (string, error) {
|
||||
var buf bytes.Buffer
|
||||
|
||||
tmpl, err := template.New("CSIDriver").Parse(csiDriver)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("failed to parse template: %w", err)
|
||||
}
|
||||
err = tmpl.Execute(&buf, values)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("failed to replace values in template: %w", err)
|
||||
}
|
||||
|
||||
return buf.String(), nil
|
||||
}
|
10
api/deploy/kubernetes/rbd/csidriver.yaml
Normal file
10
api/deploy/kubernetes/rbd/csidriver.yaml
Normal file
@ -0,0 +1,10 @@
|
||||
---
|
||||
# if Kubernetes version is less than 1.18 change
|
||||
# apiVersion to storage.k8s.io/v1beta1
|
||||
apiVersion: storage.k8s.io/v1
|
||||
kind: CSIDriver
|
||||
metadata:
|
||||
name: "{{ .Name }}"
|
||||
spec:
|
||||
attachRequired: true
|
||||
podInfoOnMount: false
|
38
api/deploy/kubernetes/rbd/csidriver_test.go
Normal file
38
api/deploy/kubernetes/rbd/csidriver_test.go
Normal file
@ -0,0 +1,38 @@
|
||||
/*
|
||||
Copyright 2021 The Ceph-CSI Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package rbd
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestNewCSIDriver(t *testing.T) {
|
||||
driver, err := NewCSIDriver(CSIDriverDefaults)
|
||||
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, driver)
|
||||
require.Equal(t, driver.Name, CSIDriverDefaults.Name)
|
||||
}
|
||||
|
||||
func TestNewCSIDriverYAML(t *testing.T) {
|
||||
yaml, err := NewCSIDriverYAML(CSIDriverDefaults)
|
||||
|
||||
require.NoError(t, err)
|
||||
require.NotEqual(t, "", yaml)
|
||||
}
|
@ -6,4 +6,5 @@ require (
|
||||
github.com/ghodss/yaml v1.0.0
|
||||
github.com/openshift/api v0.0.0-20210927171657-636513e97fda
|
||||
github.com/stretchr/testify v1.7.0
|
||||
k8s.io/api v0.22.1
|
||||
)
|
||||
|
@ -13,7 +13,12 @@
|
||||
# limitations under the License.
|
||||
|
||||
.PHONY: all
|
||||
all: scc.yaml
|
||||
all: \
|
||||
scc.yaml \
|
||||
rbd/kubernetes/csidriver.yaml
|
||||
|
||||
scc.yaml: ../api/deploy/ocp/scc.yaml ../api/deploy/ocp/scc.go
|
||||
$(MAKE) -C ../tools generate-deploy
|
||||
|
||||
rbd/kubernetes/csidriver.yaml: ../api/deploy/kubernetes/rbd/csidriver.yaml ../api/deploy/kubernetes/rbd/csidriver.go
|
||||
$(MAKE) -C ../tools generate-deploy
|
||||
|
@ -1,10 +1,18 @@
|
||||
---
|
||||
#
|
||||
# /!\ DO NOT MODIFY THIS FILE
|
||||
#
|
||||
# This file has been automatically generated by Ceph-CSI yamlgen.
|
||||
# The source for the contents can be found in the api/deploy directory, make
|
||||
# your modifications there.
|
||||
#
|
||||
---
|
||||
# if Kubernetes version is less than 1.18 change
|
||||
# apiVersion to storage.k8s.io/v1beta1
|
||||
apiVersion: storage.k8s.io/v1
|
||||
kind: CSIDriver
|
||||
metadata:
|
||||
name: rbd.csi.ceph.com
|
||||
name: "rbd.csi.ceph.com"
|
||||
spec:
|
||||
attachRequired: true
|
||||
podInfoOnMount: false
|
||||
|
@ -19,7 +19,9 @@ package main
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"reflect"
|
||||
|
||||
"github.com/ceph/ceph-csi/api/deploy/kubernetes/rbd"
|
||||
"github.com/ceph/ceph-csi/api/deploy/ocp"
|
||||
)
|
||||
|
||||
@ -35,18 +37,20 @@ const header = `---
|
||||
|
||||
type deploymentArtifact struct {
|
||||
filename string
|
||||
// FIXME: This is not dynamic enough for additional YAML generating
|
||||
// functions. Need to look into typecasting the functions and passing
|
||||
// interface{} instead of ocp.SecurityContextConstraintsValues.
|
||||
yamlFunc func(ocp.SecurityContextConstraintsValues) (string, error)
|
||||
defaults ocp.SecurityContextConstraintsValues
|
||||
yamlFunc reflect.Value
|
||||
defaults reflect.Value
|
||||
}
|
||||
|
||||
var yamlArtifacts = []deploymentArtifact{
|
||||
{
|
||||
"../deploy/scc.yaml",
|
||||
ocp.NewSecurityContextConstraintsYAML,
|
||||
ocp.SecurityContextConstraintsDefaults,
|
||||
reflect.ValueOf(ocp.NewSecurityContextConstraintsYAML),
|
||||
reflect.ValueOf(ocp.SecurityContextConstraintsDefaults),
|
||||
},
|
||||
{
|
||||
"../deploy/rbd/kubernetes/csidriver.yaml",
|
||||
reflect.ValueOf(rbd.NewCSIDriverYAML),
|
||||
reflect.ValueOf(rbd.CSIDriverDefaults),
|
||||
},
|
||||
}
|
||||
|
||||
@ -69,9 +73,10 @@ func writeArtifact(artifact deploymentArtifact) {
|
||||
panic(fmt.Sprintf("failed to write header to %q: %v", artifact.filename, err))
|
||||
}
|
||||
|
||||
data, err := artifact.yamlFunc(artifact.defaults)
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("failed to generate YAML for %q: %v", artifact.filename, err))
|
||||
result := artifact.yamlFunc.Call([]reflect.Value{artifact.defaults})
|
||||
data := result[0].String()
|
||||
if data == "" {
|
||||
panic(fmt.Sprintf("failed to generate YAML for %q: %v", artifact.filename, result[1].String()))
|
||||
}
|
||||
|
||||
_, err = f.WriteString(data)
|
||||
|
74
vendor/github.com/ceph/ceph-csi/api/deploy/kubernetes/rbd/csidriver.go
generated
vendored
Normal file
74
vendor/github.com/ceph/ceph-csi/api/deploy/kubernetes/rbd/csidriver.go
generated
vendored
Normal file
@ -0,0 +1,74 @@
|
||||
/*
|
||||
Copyright 2021 The Ceph-CSI Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package rbd
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
_ "embed"
|
||||
"fmt"
|
||||
"text/template"
|
||||
|
||||
"github.com/ghodss/yaml"
|
||||
storagev1 "k8s.io/api/storage/v1"
|
||||
)
|
||||
|
||||
//go:embed csidriver.yaml
|
||||
var csiDriver string
|
||||
|
||||
type CSIDriverValues struct {
|
||||
Name string
|
||||
}
|
||||
|
||||
var CSIDriverDefaults = CSIDriverValues{
|
||||
Name: "rbd.csi.ceph.com",
|
||||
}
|
||||
|
||||
// NewCSIDriver takes a driver name from the CSIDriverValues struct and relaces
|
||||
// the value in the template. A CSIDriver object is returned which can be
|
||||
// created in the Kubernetes cluster.
|
||||
func NewCSIDriver(values CSIDriverValues) (*storagev1.CSIDriver, error) {
|
||||
data, err := NewCSIDriverYAML(values)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
driver := &storagev1.CSIDriver{}
|
||||
err = yaml.Unmarshal([]byte(data), driver)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed convert YAML to %T: %w", driver, err)
|
||||
}
|
||||
|
||||
return driver, nil
|
||||
}
|
||||
|
||||
// NewCSIDriverYAML takes a driver name from the CSIDriverValues struct and relaces
|
||||
// the value in the template. A CSIDriver object in YAML is returned which can be
|
||||
// created in the Kubernetes cluster.
|
||||
func NewCSIDriverYAML(values CSIDriverValues) (string, error) {
|
||||
var buf bytes.Buffer
|
||||
|
||||
tmpl, err := template.New("CSIDriver").Parse(csiDriver)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("failed to parse template: %w", err)
|
||||
}
|
||||
err = tmpl.Execute(&buf, values)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("failed to replace values in template: %w", err)
|
||||
}
|
||||
|
||||
return buf.String(), nil
|
||||
}
|
10
vendor/github.com/ceph/ceph-csi/api/deploy/kubernetes/rbd/csidriver.yaml
generated
vendored
Normal file
10
vendor/github.com/ceph/ceph-csi/api/deploy/kubernetes/rbd/csidriver.yaml
generated
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
---
|
||||
# if Kubernetes version is less than 1.18 change
|
||||
# apiVersion to storage.k8s.io/v1beta1
|
||||
apiVersion: storage.k8s.io/v1
|
||||
kind: CSIDriver
|
||||
metadata:
|
||||
name: "{{ .Name }}"
|
||||
spec:
|
||||
attachRequired: true
|
||||
podInfoOnMount: false
|
1
vendor/modules.txt
vendored
1
vendor/modules.txt
vendored
@ -51,6 +51,7 @@ github.com/blang/semver
|
||||
github.com/cenkalti/backoff/v3
|
||||
# github.com/ceph/ceph-csi/api v0.0.0-00010101000000-000000000000 => ./api
|
||||
## explicit
|
||||
github.com/ceph/ceph-csi/api/deploy/kubernetes/rbd
|
||||
github.com/ceph/ceph-csi/api/deploy/ocp
|
||||
# github.com/ceph/go-ceph v0.11.0
|
||||
## explicit
|
||||
|
Loading…
Reference in New Issue
Block a user