parent
dcafa71d67
commit
e609611c4d
|
|
@ -91,6 +91,11 @@ func (r *ReconcileJenkinsBaseConfiguration) Reconcile() (reconcile.Result, jenki
|
|||
}
|
||||
r.logger.V(log.VDebug).Info("Service is present")
|
||||
|
||||
if err := r.createBackupCredentialsSecret(metaObject); err != nil {
|
||||
return reconcile.Result{}, nil, err
|
||||
}
|
||||
r.logger.V(log.VDebug).Info("Backup credentials secret is present")
|
||||
|
||||
result, err := r.createJenkinsMasterPod(metaObject)
|
||||
if err != nil {
|
||||
return reconcile.Result{}, nil, err
|
||||
|
|
@ -225,7 +230,11 @@ func (r *ReconcileJenkinsBaseConfiguration) createUserConfigurationConfigMap(met
|
|||
} else if err != nil {
|
||||
return err
|
||||
}
|
||||
//TODO make sure labels are fine
|
||||
valid := r.verifyLabelsForWatchedResource(currentConfigMap)
|
||||
if !valid {
|
||||
currentConfigMap.ObjectMeta.Labels = resources.BuildLabelsForWatchedResources(r.jenkins)
|
||||
return r.k8sClient.Update(context.TODO(), currentConfigMap)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
@ -443,3 +452,31 @@ func (r *ReconcileJenkinsBaseConfiguration) baseConfiguration(jenkinsClient jenk
|
|||
|
||||
return reconcile.Result{}, nil
|
||||
}
|
||||
|
||||
func (r *ReconcileJenkinsBaseConfiguration) createBackupCredentialsSecret(meta metav1.ObjectMeta) error {
|
||||
currentSecret := &corev1.Secret{}
|
||||
err := r.k8sClient.Get(context.TODO(), types.NamespacedName{Name: resources.GetBackupCredentialsSecretName(r.jenkins), Namespace: r.jenkins.Namespace}, currentSecret)
|
||||
if err != nil && errors.IsNotFound(err) {
|
||||
return r.k8sClient.Create(context.TODO(), resources.NewBackupCredentialsSecret(r.jenkins))
|
||||
} else if err != nil {
|
||||
return err
|
||||
}
|
||||
valid := r.verifyLabelsForWatchedResource(currentSecret)
|
||||
if !valid {
|
||||
currentSecret.ObjectMeta.Labels = resources.BuildLabelsForWatchedResources(r.jenkins)
|
||||
return r.k8sClient.Update(context.TODO(), currentSecret)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *ReconcileJenkinsBaseConfiguration) verifyLabelsForWatchedResource(object metav1.Object) bool {
|
||||
requiredLabels := resources.BuildLabelsForWatchedResources(r.jenkins)
|
||||
for key, value := range requiredLabels {
|
||||
if object.GetLabels()[key] != value {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,8 +16,13 @@ func GetBackupCredentialsSecretName(jenkins *virtuslabv1alpha1.Jenkins) string {
|
|||
}
|
||||
|
||||
// NewBackupCredentialsSecret builds the Kubernetes secret used to store backup credentials
|
||||
func NewBackupCredentialsSecret(meta metav1.ObjectMeta, jenkins *virtuslabv1alpha1.Jenkins) *corev1.Secret {
|
||||
meta.Name = GetBackupCredentialsSecretName(jenkins)
|
||||
func NewBackupCredentialsSecret(jenkins *virtuslabv1alpha1.Jenkins) *corev1.Secret {
|
||||
meta := metav1.ObjectMeta{
|
||||
Name: GetBackupCredentialsSecretName(jenkins),
|
||||
Namespace: jenkins.ObjectMeta.Namespace,
|
||||
Labels: BuildLabelsForWatchedResources(jenkins),
|
||||
}
|
||||
|
||||
return &corev1.Secret{
|
||||
TypeMeta: buildSecretTypeMeta(),
|
||||
ObjectMeta: meta,
|
||||
|
|
@ -26,6 +26,17 @@ func BuildResourceLabels(jenkins *virtuslabv1alpha1.Jenkins) map[string]string {
|
|||
}
|
||||
}
|
||||
|
||||
// BuildLabelsForWatchedResources returns labels for Kubernetes resources which operator want to watch
|
||||
// resources with that labels should not be deleted after Jenkins CR deletion, to prevent this situation don't set
|
||||
// any owner
|
||||
func BuildLabelsForWatchedResources(jenkins *virtuslabv1alpha1.Jenkins) map[string]string {
|
||||
return map[string]string{
|
||||
constants.LabelAppKey: constants.LabelAppValue,
|
||||
constants.LabelJenkinsCRKey: jenkins.Name,
|
||||
constants.LabelWatchKey: constants.LabelWatchValue,
|
||||
}
|
||||
}
|
||||
|
||||
// GetResourceName returns name of Kubernetes resource base on Jenkins CR
|
||||
func GetResourceName(jenkins *virtuslabv1alpha1.Jenkins) string {
|
||||
return fmt.Sprintf("%s-%s", constants.LabelAppValue, jenkins.ObjectMeta.Name)
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import (
|
|||
"github.com/VirtusLab/jenkins-operator/pkg/controller/jenkins/constants"
|
||||
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
)
|
||||
|
||||
const configureTheme = `
|
||||
|
|
@ -38,9 +39,11 @@ func GetUserConfigurationConfigMapName(jenkins *virtuslabv1alpha1.Jenkins) strin
|
|||
|
||||
// NewUserConfigurationConfigMap builds Kubernetes config map used to user configuration
|
||||
func NewUserConfigurationConfigMap(jenkins *virtuslabv1alpha1.Jenkins) *corev1.ConfigMap {
|
||||
meta := NewResourceObjectMeta(jenkins)
|
||||
meta.Name = GetUserConfigurationConfigMapName(jenkins)
|
||||
meta.Labels[constants.LabelWatchKey] = constants.LabelWatchValue // add watch for resource
|
||||
meta := metav1.ObjectMeta{
|
||||
Name: GetUserConfigurationConfigMapName(jenkins),
|
||||
Namespace: jenkins.ObjectMeta.Namespace,
|
||||
Labels: BuildLabelsForWatchedResources(jenkins),
|
||||
}
|
||||
|
||||
return &corev1.ConfigMap{
|
||||
TypeMeta: buildConfigMapTypeMeta(),
|
||||
|
|
|
|||
Loading…
Reference in New Issue