Files
my-rook-config/pkg/operator/k8sutil/daemonset.go
T
Sébastien Han 93b2448619 ceph: refactor rgw bootstrap
This commit does multiple things:

* remove support for AllNodes where we would deploy one rgw per node on
all the nodes.
* a transition path is implemented in the code so that if someone has an
existing deployment, daemonsets will be removed and replaced by an
deployments.
* when using "instances", each rgw deployed has its own key which makes
Ceph reporting the exact number of rgw running, see:

```
[root@rook-ceph-operator-775cf575c5-bh4sr /]# ceph -s
  cluster:
    id:     611fcf39-0669-4864-9a12-debb35c0397a
    health: HEALTH_OK

  services:
    mon: 3 daemons, quorum a,b,c (age 12h)
    mgr: a(active, since 12h)
    osd: 3 osds: 3 up (since 12h), 3 in (since 12h)
    rgw: 3 daemons active (my.store.a, my.store.b, my.store.c)

  data:
    pools:   6 pools, 600 pgs
    objects: 235 objects, 3.8 KiB
    usage:   3.0 GiB used, 84 GiB / 87 GiB avail
    pgs:     600 active+clean
```

Closes: https://github.com/rook/rook/issues/2474, https://github.com/rook/rook/issues/2957 and https://github.com/rook/rook/issues/3245
Signed-off-by: Sébastien Han <seb@redhat.com>
2019-06-14 17:55:15 +02:00

78 lines
2.7 KiB
Go

/*
Copyright 2018 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"
v1 "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"
)
// CreateDaemonSet creates
func CreateDaemonSet(name, namespace string, clientset kubernetes.Interface, ds *apps.DaemonSet) error {
_, err := clientset.AppsV1().DaemonSets(namespace).Create(ds)
if err != nil {
if k8serrors.IsAlreadyExists(err) {
_, err = clientset.AppsV1().DaemonSets(namespace).Update(ds)
}
if err != nil {
return fmt.Errorf("failed to start %s daemonset: %v\n%v", name, err, ds)
}
}
return err
}
// DeleteDaemonset makes a best effort at deleting a daemonset and its pods, then waits for them to be deleted
func DeleteDaemonset(clientset kubernetes.Interface, namespace, name string) error {
deleteAction := func(options *metav1.DeleteOptions) error {
return clientset.AppsV1().DaemonSets(namespace).Delete(name, options)
}
getAction := func() error {
_, err := clientset.AppsV1().DaemonSets(namespace).Get(name, metav1.GetOptions{})
return err
}
return deleteResourceAndWait(namespace, name, "daemonset", deleteAction, getAction)
}
// AddRookVersionLabelToDaemonSet adds or updates a label reporting the Rook version which last
// modified a DaemonSet.
func AddRookVersionLabelToDaemonSet(d *v1.DaemonSet) {
if d == nil {
return
}
if d.Labels == nil {
d.Labels = map[string]string{}
}
addRookVersionLabel(d.Labels)
}
// GetDaemonsets returns a list of daemonsets names labels matching a given selector
// example of a label selector might be "app=rook-ceph-mon, mon!=b"
// more: https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/
func GetDaemonsets(clientset kubernetes.Interface, namespace, labelSelector string) (*apps.DaemonSetList, error) {
listOptions := metav1.ListOptions{LabelSelector: labelSelector}
daemonsets, err := clientset.AppsV1().DaemonSets(namespace).List(listOptions)
if err != nil {
return nil, fmt.Errorf("failed to list deployments with labelSelector %s: %v", labelSelector, err)
}
return daemonsets, nil
}