Files
my-rook-config/pkg/operator/k8sutil/statefulset.go
T
Madhu Rajanna bdfdac8ee4 Update service if already present
previously we are not updating the service
if it's already present. with this change,
we will update the service. this does not
trigger any error message if service
already present.

Signed-off-by: Madhu Rajanna <madhupr007@gmail.com>
2019-09-24 09:43:02 +05:30

40 lines
1.1 KiB
Go

/*
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 (
"fmt"
apps "k8s.io/api/apps/v1"
k8serrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/client-go/kubernetes"
)
// create a apps.statefulset
func CreateStatefulSet(name, namespace string, clientset kubernetes.Interface, ss *apps.StatefulSet) error {
_, err := clientset.AppsV1().StatefulSets(namespace).Create(ss)
if err != nil {
if k8serrors.IsAlreadyExists(err) {
_, err = clientset.AppsV1().StatefulSets(namespace).Update(ss)
}
if err != nil {
return fmt.Errorf("failed to start %s statefulset: %+v\n%+v", name, err, ss)
}
}
return nil
}