Reconcile ConfigMap
Signed-off-by: Howard Lau <howardlau1999@hotmail.com>
This commit is contained in:
parent
09d121bcb5
commit
6ee14a018f
|
@ -138,8 +138,6 @@ type VolumeSpec struct {
|
|||
// +kubebuilder:validation:Minimum=1
|
||||
Replicas int32 `json:"replicas"`
|
||||
Service *ServiceSpec `json:"service,omitempty"`
|
||||
// Config in raw toml string
|
||||
Config *string `json:"config,omitempty"`
|
||||
}
|
||||
|
||||
// FilerSpec is the spec for filers
|
||||
|
|
|
@ -398,11 +398,6 @@ func (in *VolumeSpec) DeepCopyInto(out *VolumeSpec) {
|
|||
*out = new(ServiceSpec)
|
||||
(*in).DeepCopyInto(*out)
|
||||
}
|
||||
if in.Config != nil {
|
||||
in, out := &in.Config, &out.Config
|
||||
*out = new(string)
|
||||
**out = **in
|
||||
}
|
||||
}
|
||||
|
||||
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new VolumeSpec.
|
||||
|
|
|
@ -23,6 +23,10 @@ func (r *SeaweedReconciler) ensureFilerServers(seaweedCR *seaweedv1.Seaweed) (do
|
|||
return
|
||||
}
|
||||
|
||||
if done, result, err = r.ensureFilerConfigMap(seaweedCR); done {
|
||||
return
|
||||
}
|
||||
|
||||
if done, result, err = r.ensureFilerStatefulSet(seaweedCR); done {
|
||||
return
|
||||
}
|
||||
|
@ -69,6 +73,15 @@ func (r *SeaweedReconciler) ensureFilerService(seaweedCR *seaweedv1.Seaweed) (bo
|
|||
|
||||
return ReconcileResult(err)
|
||||
}
|
||||
func (r *SeaweedReconciler) ensureFilerConfigMap(seaweedCR *seaweedv1.Seaweed) (bool, ctrl.Result, error) {
|
||||
log := r.Log.WithValues("sw-filer-configmap", seaweedCR.Name)
|
||||
|
||||
filerConfigMap := r.createFilerConfigMap(seaweedCR)
|
||||
_, err := r.CreateOrUpdateConfigMap(filerConfigMap)
|
||||
|
||||
log.Info("Get filer ConfigMap " + filerConfigMap.Name)
|
||||
return ReconcileResult(err)
|
||||
}
|
||||
|
||||
func labelsForFiler(name string) map[string]string {
|
||||
return map[string]string{"app": "seaweedfs", "role": "filer", "name": name}
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
package controllers
|
||||
|
||||
import (
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
|
||||
seaweedv1 "github.com/seaweedfs/seaweedfs-operator/api/v1"
|
||||
)
|
||||
|
||||
func (r *SeaweedReconciler) createFilerConfigMap(m *seaweedv1.Seaweed) *corev1.ConfigMap {
|
||||
labels := labelsForFiler(m.Name)
|
||||
|
||||
toml := ""
|
||||
if m.Spec.Master.Config != nil {
|
||||
toml = *m.Spec.Filer.Config
|
||||
}
|
||||
|
||||
dep := &corev1.ConfigMap{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: m.Name + "-filer",
|
||||
Namespace: m.Namespace,
|
||||
Labels: labels,
|
||||
},
|
||||
Data: map[string]string{
|
||||
"filer.toml": toml,
|
||||
},
|
||||
}
|
||||
return dep
|
||||
}
|
|
@ -20,6 +20,10 @@ func (r *SeaweedReconciler) ensureMaster(seaweedCR *seaweedv1.Seaweed) (done boo
|
|||
return
|
||||
}
|
||||
|
||||
if done, result, err = r.ensureMasterConfigMap(seaweedCR); done {
|
||||
return
|
||||
}
|
||||
|
||||
if done, result, err = r.ensureMasterStatefulSet(seaweedCR); done {
|
||||
return
|
||||
}
|
||||
|
@ -66,6 +70,16 @@ func (r *SeaweedReconciler) ensureMasterStatefulSet(seaweedCR *seaweedv1.Seaweed
|
|||
return ReconcileResult(err)
|
||||
}
|
||||
|
||||
func (r *SeaweedReconciler) ensureMasterConfigMap(seaweedCR *seaweedv1.Seaweed) (bool, ctrl.Result, error) {
|
||||
log := r.Log.WithValues("sw-master-configmap", seaweedCR.Name)
|
||||
|
||||
masterConfigMap := r.createMasterConfigMap(seaweedCR)
|
||||
_, err := r.CreateOrUpdateConfigMap(masterConfigMap)
|
||||
|
||||
log.Info("Get master ConfigMap " + masterConfigMap.Name)
|
||||
return ReconcileResult(err)
|
||||
}
|
||||
|
||||
func (r *SeaweedReconciler) ensureMasterService(seaweedCR *seaweedv1.Seaweed) (bool, ctrl.Result, error) {
|
||||
log := r.Log.WithValues("sw-master-service", seaweedCR.Name)
|
||||
|
||||
|
@ -74,7 +88,6 @@ func (r *SeaweedReconciler) ensureMasterService(seaweedCR *seaweedv1.Seaweed) (b
|
|||
|
||||
log.Info("Get master service " + masterService.Name)
|
||||
return ReconcileResult(err)
|
||||
|
||||
}
|
||||
|
||||
func labelsForMaster(name string) map[string]string {
|
||||
|
|
|
@ -4,6 +4,7 @@ import (
|
|||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
seaweedv1 "github.com/seaweedfs/seaweedfs-operator/api/v1"
|
||||
appsv1 "k8s.io/api/apps/v1"
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
|
@ -257,6 +258,27 @@ func (r *SeaweedReconciler) CreateOrUpdateIngress(ingress *extensionsv1beta1.Ing
|
|||
return result.(*extensionsv1beta1.Ingress), nil
|
||||
}
|
||||
|
||||
func (r *SeaweedReconciler) CreateOrUpdateConfigMap(configMap *corev1.ConfigMap) (*corev1.ConfigMap, error) {
|
||||
result, err := r.CreateOrUpdate(configMap, func(existing, desired runtime.Object) error {
|
||||
existingConfigMap := existing.(*corev1.ConfigMap)
|
||||
desiredConfigMap := desired.(*corev1.ConfigMap)
|
||||
|
||||
if existingConfigMap.Annotations == nil {
|
||||
existingConfigMap.Annotations = map[string]string{}
|
||||
}
|
||||
for k, v := range desiredConfigMap.Annotations {
|
||||
existingConfigMap.Annotations[k] = v
|
||||
}
|
||||
existingConfigMap.Labels = desiredConfigMap.Labels
|
||||
existingConfigMap.Data = desiredConfigMap.Data
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return result.(*corev1.ConfigMap), nil
|
||||
}
|
||||
|
||||
// EmptyClone create an clone of the resource with the same name and namespace (if namespace-scoped), with other fields unset
|
||||
func EmptyClone(obj runtime.Object) (runtime.Object, error) {
|
||||
meta, ok := obj.(metav1.Object)
|
||||
|
|
Loading…
Reference in New Issue