mirror of
https://github.com/ceph/ceph-csi.git
synced 2024-11-10 08:20:23 +00:00
2064e674a4
Based on the review comments addressed the following, - Moved away from having to update the pod with volumes when a new Ceph cluster is added for provisioning via the CSI driver - The above now used k8s APIs to fetch secrets - TBD: Need to add a watch mechanisim such that these secrets can be cached and updated when changed - Folded the Cephc configuration and ID/key config map and secrets into a single secret - Provided the ability to read the same config via mapped or created files within the pod Tests: - Ran PV creation/deletion/attach/use using new scheme StorageClass - Ran PV creation/deletion/attach/use using older scheme to ensure nothing is broken - Did not execute snapshot related tests Signed-off-by: ShyamsundarR <srangana@redhat.com>
60 lines
1.8 KiB
Go
60 lines
1.8 KiB
Go
/*
|
|
Copyright 2019 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 util
|
|
|
|
import (
|
|
"fmt"
|
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
k8s "k8s.io/client-go/kubernetes"
|
|
"k8s.io/klog"
|
|
)
|
|
|
|
/*
|
|
K8sConfig is a ConfigStore interface implementation that reads configuration
|
|
information from k8s secrets.
|
|
|
|
Each Ceph cluster configuration secret is expected to be named,
|
|
ceph-cluster-<fsid>, where <fsid> is the Ceph cluster fsid.
|
|
|
|
The secret is expected to contain keys, as defined by the ConfigKeys constants
|
|
in the ConfigStore interface.
|
|
*/
|
|
type K8sConfig struct {
|
|
Client *k8s.Clientset
|
|
Namespace string
|
|
}
|
|
|
|
// DataForKey reads the appropriate k8s secret, named using fsid, and returns
|
|
// the contents of key within the secret
|
|
func (kc *K8sConfig) DataForKey(fsid string, key string) (data string, err error) {
|
|
secret, err := kc.Client.CoreV1().Secrets(kc.Namespace).Get("ceph-cluster-"+fsid, metav1.GetOptions{})
|
|
if err != nil {
|
|
err = fmt.Errorf("error fetching configuration for cluster ID (%s). (%s)", fsid, err)
|
|
return
|
|
}
|
|
|
|
content, ok := secret.Data[key]
|
|
if !ok {
|
|
err = fmt.Errorf("missing data for key (%s) in cluster configuration of (%s)", key, fsid)
|
|
return
|
|
}
|
|
|
|
data = string(content)
|
|
klog.V(3).Infof("returning data (%s) for key (%s) against cluster (%s)", data, key, fsid)
|
|
return
|
|
}
|