ceph: remove obsolete statefulset functions
This commit removes obsolete statefulset create, delete, addlabel, templateToStatefulset functions which were part of deprecated csi support for k8s 1.13 and should have been removed as part of https://github.com/rook/rook/pull/5982. It also adds Unit test for templateToDeployment func. Signed-off-by: Rakshith R <rar@redhat.com>
This commit is contained in:
1 parent
4bdc02e16e
commit
35a9612041
3 files changed
+13
-92
No files matched your search
@@ -64,20 +64,6 @@ func templateToService(name, templatePath string, p templateParam) (*corev1.Serv
|
||||
return &svc, nil
|
||||
}
|
||||
|
||||
func templateToStatefulSet(name, templatePath string, p templateParam) (*apps.StatefulSet, error) {
|
||||
var ss apps.StatefulSet
|
||||
t, err := loadTemplate(name, templatePath, p)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to load statefulset template")
|
||||
}
|
||||
|
||||
err = yaml.Unmarshal([]byte(t), &ss)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to unmarshal statefulset template")
|
||||
}
|
||||
return &ss, nil
|
||||
}
|
||||
|
||||
func templateToDaemonSet(name, templatePath string, p templateParam) (*apps.DaemonSet, error) {
|
||||
var ds apps.DaemonSet
|
||||
t, err := loadTemplate(name, templatePath, p)
|
||||
|
||||
@@ -50,13 +50,14 @@ spec:
|
||||
- name: cephfsplugin
|
||||
image: {{ .CSIPluginImage }}
|
||||
`)
|
||||
testSSTemplate = []byte(`
|
||||
kind: StatefulSet
|
||||
testDepTemplate = []byte(`
|
||||
kind: Deployment
|
||||
apiVersion: apps/v1
|
||||
metadata:
|
||||
name: test-label
|
||||
namespace: {{ .Namespace }}
|
||||
spec:
|
||||
replicas: {{ .ProvisionerReplicas }}
|
||||
selector:
|
||||
matchLabels:
|
||||
app: test-label
|
||||
@@ -67,13 +68,15 @@ spec:
|
||||
spec:
|
||||
serviceAccount: test-sa
|
||||
containers:
|
||||
- name: csi-rbdplugin-attacher
|
||||
- name: csi-attacher
|
||||
image: {{ .AttacherImage }}
|
||||
- name: provisioner
|
||||
- name: csi-snapshotter
|
||||
image: {{ .SnapshotterImage }}
|
||||
- name: csi-resizer
|
||||
image: {{ .ResizerImage }}
|
||||
- name: csi-provisioner
|
||||
image: {{ .ProvisionerImage }}
|
||||
- name: rbdplugin
|
||||
image: {{ .CSIPluginImage }}
|
||||
- name: cephfsplugin
|
||||
- name: csi-cephfsplugin
|
||||
image: {{ .CSIPluginImage }}
|
||||
`)
|
||||
)
|
||||
@@ -97,13 +100,13 @@ func TestDaemonSetTemplate(t *testing.T) {
|
||||
assert.Nil(t, err)
|
||||
}
|
||||
|
||||
func TestStatefulSetTemplate(t *testing.T) {
|
||||
func TestDeploymentTemplate(t *testing.T) {
|
||||
tmp, err := ioutil.TempFile("", "yaml")
|
||||
assert.Nil(t, err)
|
||||
|
||||
defer os.Remove(tmp.Name())
|
||||
|
||||
_, err = tmp.Write(testSSTemplate)
|
||||
_, err = tmp.Write(testDepTemplate)
|
||||
assert.Nil(t, err)
|
||||
err = tmp.Close()
|
||||
assert.Nil(t, err)
|
||||
@@ -112,7 +115,7 @@ func TestStatefulSetTemplate(t *testing.T) {
|
||||
Param: CSIParam,
|
||||
Namespace: "foo",
|
||||
}
|
||||
_, err = templateToStatefulSet("test-ss", tmp.Name(), tp)
|
||||
_, err = templateToDeployment("test-dep", tmp.Name(), tp)
|
||||
assert.Nil(t, err)
|
||||
}
|
||||
|
||||
|
||||
@@ -1,68 +0,0 @@
|
||||
/*
|
||||
Copyright 2019 The Rook Authors. All rights reserved.
|
||||
|
||||
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 k8sutil
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
apps "k8s.io/api/apps/v1"
|
||||
k8serrors "k8s.io/apimachinery/pkg/api/errors"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/client-go/kubernetes"
|
||||
)
|
||||
|
||||
// create a apps.statefulset
|
||||
func CreateStatefulSet(clientset kubernetes.Interface, name, namespace string, ss *apps.StatefulSet) error {
|
||||
ctx := context.TODO()
|
||||
_, err := clientset.AppsV1().StatefulSets(namespace).Create(ctx, ss, metav1.CreateOptions{})
|
||||
if err != nil {
|
||||
if k8serrors.IsAlreadyExists(err) {
|
||||
_, err = clientset.AppsV1().StatefulSets(namespace).Update(ctx, ss, metav1.UpdateOptions{})
|
||||
}
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to start %s statefulset: %+v\n%+v", name, err, ss)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// DeleteStatefulset makes a best effort at deleting a statefulset and its pods, then waits for them to be deleted
|
||||
func DeleteStatefulset(clientset kubernetes.Interface, namespace, name string) error {
|
||||
ctx := context.TODO()
|
||||
logger.Debugf("removing %s statefulset if it exists", name)
|
||||
deleteAction := func(options *metav1.DeleteOptions) error {
|
||||
return clientset.AppsV1().StatefulSets(namespace).Delete(ctx, name, *options)
|
||||
}
|
||||
getAction := func() error {
|
||||
_, err := clientset.AppsV1().StatefulSets(namespace).Get(ctx, name, metav1.GetOptions{})
|
||||
return err
|
||||
}
|
||||
return deleteResourceAndWait(namespace, name, "statefulset", deleteAction, getAction)
|
||||
}
|
||||
|
||||
// AddRookVersionLabelToStatefulSet adds or updates a label reporting the Rook version which last
|
||||
// modified a apps.statefulset.
|
||||
func AddRookVersionLabelToStatefulSet(ss *apps.StatefulSet) {
|
||||
if ss == nil {
|
||||
return
|
||||
}
|
||||
if ss.Labels == nil {
|
||||
ss.Labels = map[string]string{}
|
||||
}
|
||||
addRookVersionLabel(ss.Labels)
|
||||
}
|
||||
Reference in new issue
Block a user