2017-01-27 20:14:10 -08:00
|
|
|
/*
|
|
|
|
|
Copyright 2016 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.
|
|
|
|
|
*/
|
2017-07-24 07:37:56 -07:00
|
|
|
|
|
|
|
|
// Package rgw for the Ceph object store.
|
2017-01-27 20:14:10 -08:00
|
|
|
package rgw
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"fmt"
|
2017-09-01 12:52:14 -07:00
|
|
|
"path"
|
2017-01-27 20:14:10 -08:00
|
|
|
|
2017-06-13 12:33:08 -07:00
|
|
|
"github.com/coreos/pkg/capnslog"
|
2017-12-04 08:33:19 -08:00
|
|
|
rookalpha "github.com/rook/rook/pkg/apis/rook.io/v1alpha1"
|
2017-01-27 20:14:10 -08:00
|
|
|
"github.com/rook/rook/pkg/clusterd"
|
2017-12-04 08:33:19 -08:00
|
|
|
"github.com/rook/rook/pkg/daemon/ceph/client"
|
|
|
|
|
cephrgw "github.com/rook/rook/pkg/daemon/ceph/rgw"
|
2017-09-01 10:23:39 -07:00
|
|
|
"github.com/rook/rook/pkg/model"
|
2017-12-28 13:34:05 -08:00
|
|
|
opmon "github.com/rook/rook/pkg/operator/cluster/ceph/mon"
|
2017-01-27 20:14:10 -08:00
|
|
|
"github.com/rook/rook/pkg/operator/k8sutil"
|
2017-09-11 14:56:10 -07:00
|
|
|
"github.com/rook/rook/pkg/operator/pool"
|
2017-07-06 19:52:48 -07:00
|
|
|
"k8s.io/api/core/v1"
|
|
|
|
|
extensions "k8s.io/api/extensions/v1beta1"
|
2017-04-07 17:28:17 -07:00
|
|
|
"k8s.io/apimachinery/pkg/api/errors"
|
|
|
|
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
|
|
|
"k8s.io/apimachinery/pkg/util/intstr"
|
2017-01-27 20:14:10 -08:00
|
|
|
)
|
|
|
|
|
|
2017-06-13 12:33:08 -07:00
|
|
|
var logger = capnslog.NewPackageLogger("github.com/rook/rook", "op-rgw")
|
|
|
|
|
|
2017-01-27 20:14:10 -08:00
|
|
|
const (
|
2017-09-01 12:52:14 -07:00
|
|
|
appName = "rook-ceph-rgw"
|
|
|
|
|
keyringName = "keyring"
|
|
|
|
|
certVolumeName = "rook-rgw-cert"
|
|
|
|
|
certMountPath = "/etc/rook/private"
|
|
|
|
|
certKeyName = "cert"
|
|
|
|
|
certFilename = "rgw-cert.pem"
|
2017-01-27 20:14:10 -08:00
|
|
|
)
|
|
|
|
|
|
2017-07-24 07:37:56 -07:00
|
|
|
// Start the rgw manager
|
2017-12-12 14:26:31 -08:00
|
|
|
func CreateStore(context *clusterd.Context, store rookalpha.ObjectStore, version string, hostNetwork bool, ownerRefs []metav1.OwnerReference) error {
|
|
|
|
|
return createOrUpdate(context, store, version, hostNetwork, false, ownerRefs)
|
2017-09-19 13:56:15 -07:00
|
|
|
}
|
2017-01-27 20:14:10 -08:00
|
|
|
|
2017-12-12 14:26:31 -08:00
|
|
|
func UpdateStore(context *clusterd.Context, store rookalpha.ObjectStore, version string, hostNetwork bool, ownerRefs []metav1.OwnerReference) error {
|
|
|
|
|
return createOrUpdate(context, store, version, hostNetwork, true, ownerRefs)
|
2017-09-19 13:56:15 -07:00
|
|
|
}
|
|
|
|
|
|
2017-12-12 14:26:31 -08:00
|
|
|
func createOrUpdate(context *clusterd.Context, store rookalpha.ObjectStore, version string, hostNetwork, update bool, ownerRefs []metav1.OwnerReference) error {
|
2017-09-11 14:56:10 -07:00
|
|
|
// validate the object store settings
|
2017-12-04 08:33:19 -08:00
|
|
|
if err := validateStore(context, store); err != nil {
|
|
|
|
|
return fmt.Errorf("invalid object store %s arguments. %+v", store.Name, err)
|
2017-09-01 10:23:39 -07:00
|
|
|
}
|
|
|
|
|
|
2017-09-11 14:56:10 -07:00
|
|
|
// check if the object store already exists
|
2017-12-04 08:33:19 -08:00
|
|
|
exists, err := storeExists(context, store)
|
2017-09-11 14:56:10 -07:00
|
|
|
if err == nil && exists {
|
2017-09-19 13:56:15 -07:00
|
|
|
if !update {
|
2017-12-04 08:33:19 -08:00
|
|
|
logger.Infof("object store %s exists in namespace %s", store.Name, store.Namespace)
|
2017-09-19 13:56:15 -07:00
|
|
|
return nil
|
|
|
|
|
}
|
2017-12-04 08:33:19 -08:00
|
|
|
logger.Infof("object store %s exists in namespace %store. checking for updates", store.Name, store.Namespace)
|
2017-09-11 14:56:10 -07:00
|
|
|
}
|
|
|
|
|
|
2017-12-04 08:33:19 -08:00
|
|
|
logger.Infof("creating object store %s in namespace %s", store.Name, store.Namespace)
|
2017-12-12 14:26:31 -08:00
|
|
|
err = createKeyring(context, store, ownerRefs)
|
2017-01-27 20:14:10 -08:00
|
|
|
if err != nil {
|
|
|
|
|
return fmt.Errorf("failed to create rgw keyring. %+v", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// start the service
|
2017-12-12 14:26:31 -08:00
|
|
|
serviceIP, err := startService(context, store, hostNetwork, ownerRefs)
|
2017-01-27 20:14:10 -08:00
|
|
|
if err != nil {
|
|
|
|
|
return fmt.Errorf("failed to start rgw service. %+v", err)
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-11 14:56:10 -07:00
|
|
|
// create the ceph artifacts for the object store
|
2017-12-04 08:33:19 -08:00
|
|
|
objContext := cephrgw.NewContext(context, store.Name, store.Namespace)
|
|
|
|
|
err = cephrgw.CreateObjectStore(objContext, *store.Spec.MetadataPool.ToModel(""), *store.Spec.DataPool.ToModel(""), serviceIP, store.Spec.Gateway.Port)
|
2017-09-01 10:23:39 -07:00
|
|
|
if err != nil {
|
2017-10-05 10:00:19 -07:00
|
|
|
return fmt.Errorf("failed to create pools. %+v", err)
|
2017-09-01 10:23:39 -07:00
|
|
|
}
|
2017-08-31 10:54:59 -07:00
|
|
|
|
2017-12-12 14:26:31 -08:00
|
|
|
if err := startRGWPods(context, store, version, hostNetwork, update, ownerRefs); err != nil {
|
2017-09-19 13:56:15 -07:00
|
|
|
return fmt.Errorf("failed to start pods. %+v", err)
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-04 08:33:19 -08:00
|
|
|
logger.Infof("created object store %s", store.Name)
|
2017-09-19 13:56:15 -07:00
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-12 14:26:31 -08:00
|
|
|
func startRGWPods(context *clusterd.Context, store rookalpha.ObjectStore, version string, hostNetwork, update bool, ownerRefs []metav1.OwnerReference) error {
|
2017-09-19 13:56:15 -07:00
|
|
|
|
|
|
|
|
// if intended to update, remove the old pods so they can be created with the new spec settings
|
|
|
|
|
if update {
|
2017-12-04 08:33:19 -08:00
|
|
|
err := k8sutil.DeleteDeployment(context.Clientset, store.Namespace, instanceName(store))
|
2017-10-05 10:00:19 -07:00
|
|
|
if err != nil {
|
|
|
|
|
logger.Warningf(err.Error())
|
|
|
|
|
}
|
2017-12-04 08:33:19 -08:00
|
|
|
err = k8sutil.DeleteDaemonset(context.Clientset, store.Namespace, instanceName(store))
|
2017-10-05 10:00:19 -07:00
|
|
|
if err != nil {
|
|
|
|
|
logger.Warningf(err.Error())
|
|
|
|
|
}
|
2017-09-19 13:56:15 -07:00
|
|
|
}
|
|
|
|
|
|
2017-09-14 12:26:42 -07:00
|
|
|
// start the deployment or daemonset
|
|
|
|
|
var rgwType string
|
2017-09-19 13:56:15 -07:00
|
|
|
var err error
|
2017-12-04 08:33:19 -08:00
|
|
|
if store.Spec.Gateway.AllNodes {
|
2017-09-14 12:26:42 -07:00
|
|
|
rgwType = "daemonset"
|
2017-12-12 14:26:31 -08:00
|
|
|
err = startDaemonset(context, store, version, hostNetwork, ownerRefs)
|
2017-09-14 12:26:42 -07:00
|
|
|
} else {
|
|
|
|
|
rgwType = "deployment"
|
2017-12-12 14:26:31 -08:00
|
|
|
err = startDeployment(context, store, version, store.Spec.Gateway.Instances, hostNetwork, ownerRefs)
|
2017-09-14 12:26:42 -07:00
|
|
|
}
|
|
|
|
|
|
2017-01-27 20:14:10 -08:00
|
|
|
if err != nil {
|
2017-03-07 11:28:16 -08:00
|
|
|
if !errors.IsAlreadyExists(err) {
|
2017-12-04 08:33:19 -08:00
|
|
|
return fmt.Errorf("failed to create rgw %store. %+v", rgwType, err)
|
2017-01-27 20:14:10 -08:00
|
|
|
}
|
2017-09-14 12:26:42 -07:00
|
|
|
logger.Infof("rgw %s already exists", rgwType)
|
2017-01-27 20:14:10 -08:00
|
|
|
} else {
|
2017-09-14 12:26:42 -07:00
|
|
|
logger.Infof("rgw %s started", rgwType)
|
2017-01-27 20:14:10 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-11 14:56:10 -07:00
|
|
|
// Delete the object store.
|
|
|
|
|
// WARNING: This is a very destructive action that deletes all metadata and data pools.
|
2017-12-04 08:33:19 -08:00
|
|
|
func DeleteStore(context *clusterd.Context, store rookalpha.ObjectStore) error {
|
2017-09-11 14:56:10 -07:00
|
|
|
// check if the object store exists
|
2017-12-04 08:33:19 -08:00
|
|
|
exists, err := storeExists(context, store)
|
2017-09-11 14:56:10 -07:00
|
|
|
if err != nil {
|
|
|
|
|
return fmt.Errorf("failed to detect if there is an object store to delete. %+v", err)
|
|
|
|
|
}
|
|
|
|
|
if !exists {
|
2017-12-04 08:33:19 -08:00
|
|
|
logger.Infof("Object store %s does not exist in namespace %s", store.Name, store.Namespace)
|
2017-09-11 14:56:10 -07:00
|
|
|
return nil
|
2017-09-01 10:23:39 -07:00
|
|
|
}
|
|
|
|
|
|
2017-12-04 08:33:19 -08:00
|
|
|
logger.Infof("Deleting object store %s from namespace %s", store.Name, store.Namespace)
|
2017-09-11 14:56:10 -07:00
|
|
|
|
|
|
|
|
var gracePeriod int64
|
|
|
|
|
propagation := metav1.DeletePropagationForeground
|
|
|
|
|
options := &metav1.DeleteOptions{GracePeriodSeconds: &gracePeriod, PropagationPolicy: &propagation}
|
|
|
|
|
|
|
|
|
|
// Delete the rgw service
|
2017-12-04 08:33:19 -08:00
|
|
|
err = context.Clientset.CoreV1().Services(store.Namespace).Delete(instanceName(store), options)
|
2017-09-11 14:56:10 -07:00
|
|
|
if err != nil && !errors.IsNotFound(err) {
|
2017-09-13 10:46:06 -07:00
|
|
|
logger.Warningf("failed to delete rgw service. %+v", err)
|
2017-09-11 14:56:10 -07:00
|
|
|
}
|
|
|
|
|
|
2017-10-05 10:00:19 -07:00
|
|
|
// Make a best effort to delete the rgw pods
|
2017-12-04 08:33:19 -08:00
|
|
|
err = k8sutil.DeleteDeployment(context.Clientset, store.Namespace, instanceName(store))
|
2017-10-05 10:00:19 -07:00
|
|
|
if err != nil {
|
|
|
|
|
logger.Warningf(err.Error())
|
|
|
|
|
}
|
2017-12-04 08:33:19 -08:00
|
|
|
err = k8sutil.DeleteDaemonset(context.Clientset, store.Namespace, instanceName(store))
|
2017-10-05 10:00:19 -07:00
|
|
|
if err != nil {
|
|
|
|
|
logger.Warningf(err.Error())
|
|
|
|
|
}
|
2017-09-14 12:26:42 -07:00
|
|
|
|
2017-09-11 14:56:10 -07:00
|
|
|
// Delete the rgw keyring
|
2017-12-04 08:33:19 -08:00
|
|
|
err = context.Clientset.CoreV1().Secrets(store.Namespace).Delete(instanceName(store), options)
|
2017-09-11 14:56:10 -07:00
|
|
|
if err != nil && !errors.IsNotFound(err) {
|
2017-09-13 10:46:06 -07:00
|
|
|
logger.Warningf("failed to delete rgw secret. %+v", err)
|
2017-09-11 14:56:10 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Delete the realm and pools
|
2017-12-04 08:33:19 -08:00
|
|
|
objContext := cephrgw.NewContext(context, store.Name, store.Namespace)
|
2017-09-11 14:56:10 -07:00
|
|
|
err = cephrgw.DeleteObjectStore(objContext)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return fmt.Errorf("failed to delete the realm and pools. %+v", err)
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-04 08:33:19 -08:00
|
|
|
logger.Infof("Completed deleting object store %s", store.Name)
|
2017-09-11 14:56:10 -07:00
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-14 12:26:42 -07:00
|
|
|
// Check if the object store exists depending on either the deployment or the daemonset
|
2017-12-04 08:33:19 -08:00
|
|
|
func storeExists(context *clusterd.Context, store rookalpha.ObjectStore) (bool, error) {
|
|
|
|
|
_, err := context.Clientset.ExtensionsV1beta1().Deployments(store.Namespace).Get(instanceName(store), metav1.GetOptions{})
|
2017-09-14 12:26:42 -07:00
|
|
|
if err == nil {
|
|
|
|
|
// the deployment was found
|
|
|
|
|
return true, nil
|
2017-09-11 14:56:10 -07:00
|
|
|
}
|
2017-09-14 12:26:42 -07:00
|
|
|
if err != nil && !errors.IsNotFound(err) {
|
|
|
|
|
return false, err
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-04 08:33:19 -08:00
|
|
|
_, err = context.Clientset.ExtensionsV1beta1().DaemonSets(store.Namespace).Get(instanceName(store), metav1.GetOptions{})
|
2017-09-14 12:26:42 -07:00
|
|
|
if err == nil {
|
|
|
|
|
// the daemonset was found
|
|
|
|
|
return true, nil
|
|
|
|
|
}
|
|
|
|
|
if err != nil && !errors.IsNotFound(err) {
|
|
|
|
|
return false, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// neither one was found
|
|
|
|
|
return false, nil
|
2017-09-11 14:56:10 -07:00
|
|
|
}
|
|
|
|
|
|
2017-12-12 14:26:31 -08:00
|
|
|
func createKeyring(context *clusterd.Context, store rookalpha.ObjectStore, ownerRefs []metav1.OwnerReference) error {
|
2017-12-04 08:33:19 -08:00
|
|
|
_, err := context.Clientset.CoreV1().Secrets(store.Namespace).Get(instanceName(store), metav1.GetOptions{})
|
2017-02-06 15:17:48 -08:00
|
|
|
if err == nil {
|
|
|
|
|
logger.Infof("the rgw keyring was already generated")
|
|
|
|
|
return nil
|
|
|
|
|
}
|
2017-03-07 11:28:16 -08:00
|
|
|
if !errors.IsNotFound(err) {
|
2017-02-06 15:17:48 -08:00
|
|
|
return fmt.Errorf("failed to get rgw secrets. %+v", err)
|
|
|
|
|
}
|
2017-01-27 20:14:10 -08:00
|
|
|
|
|
|
|
|
// create the keyring
|
2017-06-02 13:44:54 -07:00
|
|
|
logger.Infof("generating rgw keyring")
|
2017-12-04 08:33:19 -08:00
|
|
|
keyring, err := createRGWKeyring(context, store.Namespace)
|
2017-01-27 20:14:10 -08:00
|
|
|
if err != nil {
|
2017-02-06 15:17:48 -08:00
|
|
|
return fmt.Errorf("failed to create keyring. %+v", err)
|
2017-01-27 20:14:10 -08:00
|
|
|
}
|
|
|
|
|
|
2017-02-06 15:17:48 -08:00
|
|
|
// store the secrets
|
|
|
|
|
secrets := map[string]string{
|
2017-02-07 14:48:17 -08:00
|
|
|
keyringName: keyring,
|
2017-02-06 15:17:48 -08:00
|
|
|
}
|
2017-02-17 12:54:00 -08:00
|
|
|
secret := &v1.Secret{
|
2017-12-12 14:26:31 -08:00
|
|
|
ObjectMeta: metav1.ObjectMeta{
|
|
|
|
|
Name: instanceName(store),
|
|
|
|
|
Namespace: store.Namespace,
|
|
|
|
|
OwnerReferences: ownerRefs,
|
|
|
|
|
},
|
2017-02-17 12:54:00 -08:00
|
|
|
StringData: secrets,
|
|
|
|
|
Type: k8sutil.RookType,
|
|
|
|
|
}
|
2017-12-04 08:33:19 -08:00
|
|
|
_, err = context.Clientset.CoreV1().Secrets(store.Namespace).Create(secret)
|
2017-02-06 15:17:48 -08:00
|
|
|
if err != nil {
|
|
|
|
|
return fmt.Errorf("failed to save rgw secrets. %+v", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nil
|
2017-01-27 20:14:10 -08:00
|
|
|
}
|
|
|
|
|
|
2017-12-04 08:33:19 -08:00
|
|
|
func instanceName(store rookalpha.ObjectStore) string {
|
|
|
|
|
return InstanceName(store.Name)
|
2017-08-31 10:54:59 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func InstanceName(name string) string {
|
|
|
|
|
return fmt.Sprintf("%s-%s", appName, name)
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-04 08:33:19 -08:00
|
|
|
func ModelToSpec(store model.ObjectStore, namespace string) *rookalpha.ObjectStore {
|
|
|
|
|
return &rookalpha.ObjectStore{
|
2017-09-11 14:56:10 -07:00
|
|
|
ObjectMeta: metav1.ObjectMeta{Name: store.Name, Namespace: namespace},
|
2017-12-04 08:33:19 -08:00
|
|
|
Spec: rookalpha.ObjectStoreSpec{
|
2017-09-11 14:58:13 -07:00
|
|
|
MetadataPool: pool.ModelToSpec(store.MetadataConfig),
|
|
|
|
|
DataPool: pool.ModelToSpec(store.DataConfig),
|
2017-12-04 08:33:19 -08:00
|
|
|
Gateway: rookalpha.GatewaySpec{
|
2017-09-11 14:58:13 -07:00
|
|
|
Port: store.Gateway.Port,
|
2017-09-14 12:26:42 -07:00
|
|
|
SecurePort: store.Gateway.SecurePort,
|
|
|
|
|
Instances: store.Gateway.Instances,
|
2017-09-19 13:56:15 -07:00
|
|
|
AllNodes: store.Gateway.AllNodes,
|
2017-09-11 14:58:13 -07:00
|
|
|
SSLCertificateRef: store.Gateway.CertificateRef,
|
2017-09-11 14:56:10 -07:00
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-04 08:33:19 -08:00
|
|
|
func makeRGWPodSpec(store rookalpha.ObjectStore, version string, hostNetwork bool) v1.PodTemplateSpec {
|
2017-06-09 11:14:08 +00:00
|
|
|
podSpec := v1.PodSpec{
|
2017-12-04 08:33:19 -08:00
|
|
|
Containers: []v1.Container{rgwContainer(store, version)},
|
2017-06-09 11:14:08 +00:00
|
|
|
RestartPolicy: v1.RestartPolicyAlways,
|
|
|
|
|
Volumes: []v1.Volume{
|
|
|
|
|
{Name: k8sutil.DataDirVolume, VolumeSource: v1.VolumeSource{EmptyDir: &v1.EmptyDirVolumeSource{}}},
|
|
|
|
|
k8sutil.ConfigOverrideVolume(),
|
|
|
|
|
},
|
2017-09-14 12:26:42 -07:00
|
|
|
HostNetwork: hostNetwork,
|
2017-06-09 11:14:08 +00:00
|
|
|
}
|
2017-09-14 12:26:42 -07:00
|
|
|
if hostNetwork {
|
2017-09-09 17:33:28 +02:00
|
|
|
podSpec.DNSPolicy = v1.DNSClusterFirstWithHostNet
|
|
|
|
|
}
|
2017-09-01 12:52:14 -07:00
|
|
|
|
|
|
|
|
// Set the ssl cert if specified
|
2017-12-04 08:33:19 -08:00
|
|
|
if store.Spec.Gateway.SSLCertificateRef != "" {
|
2017-09-01 12:52:14 -07:00
|
|
|
certVol := v1.Volume{Name: certVolumeName, VolumeSource: v1.VolumeSource{Secret: &v1.SecretVolumeSource{
|
2017-12-04 08:33:19 -08:00
|
|
|
SecretName: store.Spec.Gateway.SSLCertificateRef,
|
2017-09-01 12:52:14 -07:00
|
|
|
Items: []v1.KeyToPath{{Key: certKeyName, Path: certFilename}},
|
|
|
|
|
}}}
|
|
|
|
|
podSpec.Volumes = append(podSpec.Volumes, certVol)
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-04 08:33:19 -08:00
|
|
|
store.Spec.Gateway.Placement.ApplyToPodSpec(&podSpec)
|
2017-06-09 11:14:08 +00:00
|
|
|
|
2017-09-14 12:26:42 -07:00
|
|
|
return v1.PodTemplateSpec{
|
2017-04-07 17:28:17 -07:00
|
|
|
ObjectMeta: metav1.ObjectMeta{
|
2017-12-04 08:33:19 -08:00
|
|
|
Name: instanceName(store),
|
|
|
|
|
Labels: getLabels(store),
|
2017-01-27 20:14:10 -08:00
|
|
|
Annotations: map[string]string{},
|
|
|
|
|
},
|
2017-06-09 11:14:08 +00:00
|
|
|
Spec: podSpec,
|
2017-01-27 20:14:10 -08:00
|
|
|
}
|
2017-09-14 12:26:42 -07:00
|
|
|
}
|
2017-01-27 20:14:10 -08:00
|
|
|
|
2017-12-12 14:26:31 -08:00
|
|
|
func startDeployment(context *clusterd.Context, store rookalpha.ObjectStore, version string, replicas int32, hostNetwork bool, ownerRefs []metav1.OwnerReference) error {
|
2017-01-27 20:14:10 -08:00
|
|
|
|
2017-09-14 12:26:42 -07:00
|
|
|
deployment := &extensions.Deployment{
|
|
|
|
|
ObjectMeta: metav1.ObjectMeta{
|
2017-12-12 14:26:31 -08:00
|
|
|
Name: instanceName(store),
|
|
|
|
|
Namespace: store.Namespace,
|
|
|
|
|
OwnerReferences: ownerRefs,
|
2017-09-14 12:26:42 -07:00
|
|
|
},
|
2017-12-04 08:33:19 -08:00
|
|
|
Spec: extensions.DeploymentSpec{Template: makeRGWPodSpec(store, version, hostNetwork), Replicas: &replicas},
|
2017-09-14 12:26:42 -07:00
|
|
|
}
|
2017-12-04 08:33:19 -08:00
|
|
|
_, err := context.Clientset.ExtensionsV1beta1().Deployments(store.Namespace).Create(deployment)
|
2017-09-14 12:26:42 -07:00
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-12 14:26:31 -08:00
|
|
|
func startDaemonset(context *clusterd.Context, store rookalpha.ObjectStore, version string, hostNetwork bool, ownerRefs []metav1.OwnerReference) error {
|
2017-09-14 12:26:42 -07:00
|
|
|
|
|
|
|
|
daemonset := &extensions.DaemonSet{
|
|
|
|
|
ObjectMeta: metav1.ObjectMeta{
|
2017-12-12 14:26:31 -08:00
|
|
|
Name: instanceName(store),
|
|
|
|
|
Namespace: store.Namespace,
|
|
|
|
|
OwnerReferences: ownerRefs,
|
2017-09-14 12:26:42 -07:00
|
|
|
},
|
2017-11-06 18:38:11 +01:00
|
|
|
Spec: extensions.DaemonSetSpec{
|
2017-12-04 08:33:19 -08:00
|
|
|
Template: makeRGWPodSpec(store, version, hostNetwork),
|
2017-11-06 18:38:11 +01:00
|
|
|
},
|
2017-09-14 12:26:42 -07:00
|
|
|
}
|
|
|
|
|
|
2017-12-04 08:33:19 -08:00
|
|
|
_, err := context.Clientset.ExtensionsV1beta1().DaemonSets(store.Namespace).Create(daemonset)
|
2017-09-14 12:26:42 -07:00
|
|
|
return err
|
2017-01-27 20:14:10 -08:00
|
|
|
}
|
|
|
|
|
|
2017-12-04 08:33:19 -08:00
|
|
|
func rgwContainer(store rookalpha.ObjectStore, version string) v1.Container {
|
2017-01-27 20:14:10 -08:00
|
|
|
|
2017-09-01 12:52:14 -07:00
|
|
|
container := v1.Container{
|
2017-07-21 14:35:56 -07:00
|
|
|
Args: []string{
|
|
|
|
|
"rgw",
|
|
|
|
|
fmt.Sprintf("--config-dir=%s", k8sutil.DataDir),
|
2017-12-04 08:33:19 -08:00
|
|
|
fmt.Sprintf("--rgw-name=%s", store.Name),
|
|
|
|
|
fmt.Sprintf("--rgw-host=%s", instanceName(store)),
|
|
|
|
|
fmt.Sprintf("--rgw-port=%d", store.Spec.Gateway.Port),
|
|
|
|
|
fmt.Sprintf("--rgw-secure-port=%d", store.Spec.Gateway.SecurePort),
|
2017-07-21 14:35:56 -07:00
|
|
|
},
|
2017-12-04 08:33:19 -08:00
|
|
|
Name: instanceName(store),
|
2017-09-11 14:56:10 -07:00
|
|
|
Image: k8sutil.MakeRookImage(version),
|
2017-02-06 15:17:48 -08:00
|
|
|
VolumeMounts: []v1.VolumeMount{
|
2017-01-27 20:14:10 -08:00
|
|
|
{Name: k8sutil.DataDirVolume, MountPath: k8sutil.DataDir},
|
2017-05-12 15:54:29 -07:00
|
|
|
k8sutil.ConfigOverrideMount(),
|
2017-01-27 20:14:10 -08:00
|
|
|
},
|
2017-02-06 15:17:48 -08:00
|
|
|
Env: []v1.EnvVar{
|
2017-12-04 08:33:19 -08:00
|
|
|
{Name: "ROOK_RGW_KEYRING", ValueFrom: &v1.EnvVarSource{SecretKeyRef: &v1.SecretKeySelector{LocalObjectReference: v1.LocalObjectReference{Name: instanceName(store)}, Key: keyringName}}},
|
2017-08-01 22:33:00 -07:00
|
|
|
k8sutil.PodIPEnvVar(k8sutil.PrivateIPEnvVar),
|
|
|
|
|
k8sutil.PodIPEnvVar(k8sutil.PublicIPEnvVar),
|
2017-12-04 08:33:19 -08:00
|
|
|
opmon.ClusterNameEnvVar(store.Namespace),
|
2017-07-24 07:37:56 -07:00
|
|
|
opmon.EndpointEnvVar(),
|
|
|
|
|
opmon.SecretEnvVar(),
|
2017-05-12 15:54:29 -07:00
|
|
|
k8sutil.ConfigOverrideEnvVar(),
|
2017-02-06 15:17:48 -08:00
|
|
|
},
|
2017-12-04 08:33:19 -08:00
|
|
|
Resources: store.Spec.Gateway.Resources,
|
2017-01-27 20:14:10 -08:00
|
|
|
}
|
2017-09-01 12:52:14 -07:00
|
|
|
|
2017-12-04 08:33:19 -08:00
|
|
|
if store.Spec.Gateway.SSLCertificateRef != "" {
|
2017-09-01 12:52:14 -07:00
|
|
|
// Add a volume mount for the ssl certificate
|
|
|
|
|
mount := v1.VolumeMount{Name: certVolumeName, MountPath: certMountPath, ReadOnly: true}
|
|
|
|
|
container.VolumeMounts = append(container.VolumeMounts, mount)
|
|
|
|
|
|
|
|
|
|
// Pass the flag for using the ssl cert
|
|
|
|
|
path := path.Join(certMountPath, certFilename)
|
|
|
|
|
container.Args = append(container.Args, fmt.Sprintf("--rgw-cert=%s", path))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return container
|
2017-01-27 20:14:10 -08:00
|
|
|
}
|
|
|
|
|
|
2017-12-12 14:26:31 -08:00
|
|
|
func startService(context *clusterd.Context, store rookalpha.ObjectStore, hostNetwork bool, ownerRefs []metav1.OwnerReference) (string, error) {
|
2017-12-04 08:33:19 -08:00
|
|
|
labels := getLabels(store)
|
2017-09-11 14:56:10 -07:00
|
|
|
svc := &v1.Service{
|
2017-04-07 17:28:17 -07:00
|
|
|
ObjectMeta: metav1.ObjectMeta{
|
2017-12-12 14:26:31 -08:00
|
|
|
Name: instanceName(store),
|
|
|
|
|
Namespace: store.Namespace,
|
|
|
|
|
Labels: labels,
|
|
|
|
|
OwnerReferences: ownerRefs,
|
2017-01-27 20:14:10 -08:00
|
|
|
},
|
|
|
|
|
Spec: v1.ServiceSpec{
|
|
|
|
|
Selector: labels,
|
|
|
|
|
},
|
|
|
|
|
}
|
2017-09-14 12:26:42 -07:00
|
|
|
if hostNetwork {
|
|
|
|
|
svc.Spec.ClusterIP = v1.ClusterIPNone
|
2017-09-09 17:33:28 +02:00
|
|
|
}
|
2017-01-27 20:14:10 -08:00
|
|
|
|
2017-12-04 08:33:19 -08:00
|
|
|
addPort(svc, "http", store.Spec.Gateway.Port)
|
|
|
|
|
addPort(svc, "https", store.Spec.Gateway.SecurePort)
|
2017-09-14 12:26:42 -07:00
|
|
|
|
2017-12-04 08:33:19 -08:00
|
|
|
svc, err := context.Clientset.CoreV1().Services(store.Namespace).Create(svc)
|
2017-01-27 20:14:10 -08:00
|
|
|
if err != nil {
|
2017-03-07 11:28:16 -08:00
|
|
|
if !errors.IsAlreadyExists(err) {
|
2017-09-11 14:58:13 -07:00
|
|
|
return "", fmt.Errorf("failed to create rgw service. %+v", err)
|
2017-01-27 20:14:10 -08:00
|
|
|
}
|
2017-09-11 14:58:13 -07:00
|
|
|
logger.Infof("Gateway service already running")
|
2017-08-31 10:54:59 -07:00
|
|
|
return "", nil
|
2017-01-27 20:14:10 -08:00
|
|
|
}
|
|
|
|
|
|
2017-12-04 08:33:19 -08:00
|
|
|
logger.Infof("Gateway service running at %s:%d", svc.Spec.ClusterIP, store.Spec.Gateway.Port)
|
2017-09-11 14:56:10 -07:00
|
|
|
return svc.Spec.ClusterIP, nil
|
2017-01-27 20:14:10 -08:00
|
|
|
}
|
|
|
|
|
|
2017-09-14 12:26:42 -07:00
|
|
|
func addPort(service *v1.Service, name string, port int32) {
|
|
|
|
|
if port == 0 {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
service.Spec.Ports = append(service.Spec.Ports, v1.ServicePort{
|
|
|
|
|
Name: name,
|
|
|
|
|
Port: port,
|
|
|
|
|
TargetPort: intstr.FromInt(int(port)),
|
|
|
|
|
Protocol: v1.ProtocolTCP,
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-04 08:33:19 -08:00
|
|
|
func getLabels(store rookalpha.ObjectStore) map[string]string {
|
2017-01-27 20:14:10 -08:00
|
|
|
return map[string]string{
|
2017-02-07 14:48:17 -08:00
|
|
|
k8sutil.AppAttr: appName,
|
2017-12-04 08:33:19 -08:00
|
|
|
k8sutil.ClusterAttr: store.Namespace,
|
|
|
|
|
"rook_object_store": store.Name,
|
2017-01-27 20:14:10 -08:00
|
|
|
}
|
|
|
|
|
}
|
2017-10-17 09:33:37 -07:00
|
|
|
|
|
|
|
|
// create a keyring for the rgw client with a limited set of privileges
|
2017-12-04 08:33:19 -08:00
|
|
|
func createRGWKeyring(context *clusterd.Context, clusterName string) (string, error) {
|
2017-10-17 09:33:37 -07:00
|
|
|
username := "client.radosgw.gateway"
|
|
|
|
|
access := []string{"osd", "allow rwx", "mon", "allow rw"}
|
|
|
|
|
|
|
|
|
|
// get-or-create-key for the user account
|
|
|
|
|
key, err := client.AuthGetOrCreateKey(context, clusterName, username, access)
|
|
|
|
|
if err != nil {
|
2017-12-04 08:33:19 -08:00
|
|
|
return "", fmt.Errorf("failed to get or create auth key for %store. %+v", username, err)
|
2017-10-17 09:33:37 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return key, err
|
|
|
|
|
}
|
2017-12-28 13:34:05 -08:00
|
|
|
|
|
|
|
|
// Validate the object store arguments
|
|
|
|
|
func validateStore(context *clusterd.Context, s rookalpha.ObjectStore) error {
|
|
|
|
|
if s.Name == "" {
|
|
|
|
|
return fmt.Errorf("missing name")
|
|
|
|
|
}
|
|
|
|
|
if s.Namespace == "" {
|
|
|
|
|
return fmt.Errorf("missing namespace")
|
|
|
|
|
}
|
|
|
|
|
if err := pool.ValidatePoolSpec(context, s.Namespace, &s.Spec.MetadataPool); err != nil {
|
|
|
|
|
return fmt.Errorf("invalid metadata pool spec. %+v", err)
|
|
|
|
|
}
|
|
|
|
|
if err := pool.ValidatePoolSpec(context, s.Namespace, &s.Spec.DataPool); err != nil {
|
|
|
|
|
return fmt.Errorf("invalid data pool spec. %+v", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
}
|