Skip to content

Commit

Permalink
Fix generating Jenkins API token
Browse files Browse the repository at this point in the history
  • Loading branch information
tomaszsek committed Jan 14, 2019
1 parent c9370cd commit e187640
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
4 changes: 2 additions & 2 deletions pkg/controller/jenkins/configuration/base/reconcile.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 221,7 @@ func (r *ReconcileJenkinsBaseConfiguration) createUserConfigurationConfigMap(met
currentConfigMap := &corev1.ConfigMap{}
err := r.k8sClient.Get(context.TODO(), types.NamespacedName{Name: resources.GetUserConfigurationConfigMapName(r.jenkins), Namespace: r.jenkins.Namespace}, currentConfigMap)
if err != nil && errors.IsNotFound(err) {
return r.k8sClient.Create(context.TODO(), resources.NewUserConfigurationConfigMap(meta, r.jenkins))
return r.k8sClient.Create(context.TODO(), resources.NewUserConfigurationConfigMap(r.jenkins))
} else if err != nil {
return err
}
Expand Down Expand Up @@ -253,7 253,7 @@ func (r *ReconcileJenkinsBaseConfiguration) createRBAC(meta metav1.ObjectMeta) e
}

func (r *ReconcileJenkinsBaseConfiguration) createService(meta metav1.ObjectMeta) error {
err := r.createResource(resources.NewService(&meta, r.minikube))
err := r.createResource(resources.NewService(meta, r.minikube))
if err != nil && !apierrors.IsAlreadyExists(err) {
return err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 14,10 @@ func buildServiceTypeMeta() metav1.TypeMeta {
}

// NewService builds the Kubernetes service resource
func NewService(meta *metav1.ObjectMeta, minikube bool) *corev1.Service {
func NewService(meta metav1.ObjectMeta, minikube bool) *corev1.Service {
service := &corev1.Service{
TypeMeta: buildServiceTypeMeta(),
ObjectMeta: *meta,
ObjectMeta: meta,
Spec: corev1.ServiceSpec{
Selector: meta.Labels,
// The first port have to be Jenkins http port because when run with minikube
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 2,11 @@ package resources

import (
"fmt"

virtuslabv1alpha1 "github.com/VirtusLab/jenkins-operator/pkg/apis/virtuslab/v1alpha1"
"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 = `
Expand Down Expand Up @@ -36,7 37,8 @@ func GetUserConfigurationConfigMapName(jenkins *virtuslabv1alpha1.Jenkins) strin
}

// NewUserConfigurationConfigMap builds Kubernetes config map used to user configuration
func NewUserConfigurationConfigMap(meta metav1.ObjectMeta, jenkins *virtuslabv1alpha1.Jenkins) *corev1.ConfigMap {
func NewUserConfigurationConfigMap(jenkins *virtuslabv1alpha1.Jenkins) *corev1.ConfigMap {
meta := NewResourceObjectMeta(jenkins)
meta.Name = GetUserConfigurationConfigMapName(jenkins)
meta.Labels[constants.LabelWatchKey] = constants.LabelWatchValue // add watch for resource

Expand Down
8 changes: 8 additions & 0 deletions pkg/controller/jenkins/jenkins_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 2,7 @@ package jenkins

import (
"context"
"fmt"

virtuslabv1alpha1 "github.com/VirtusLab/jenkins-operator/pkg/apis/virtuslab/v1alpha1"
"github.com/VirtusLab/jenkins-operator/pkg/controller/jenkins/configuration/base"
Expand Down Expand Up @@ -93,6 94,9 @@ func (r *ReconcileJenkins) Reconcile(request reconcile.Request) (reconcile.Resul
if err != nil && errors.IsConflict(err) {
logger.V(log.VWarn).Info(err.Error())
return reconcile.Result{Requeue: true}, nil
} else if err != nil {
logger.V(log.VWarn).Info(fmt.Sprintf("Reconcile loop failed: % v", err))
return reconcile.Result{Requeue: true}, nil
}
return result, err
}
Expand Down Expand Up @@ -131,12 135,14 @@ func (r *ReconcileJenkins) reconcile(request reconcile.Request, logger logr.Logg
return *result, nil
}
if jenkins.Status.BaseConfigurationCompletedTime == nil {
logger.Info("Base configuration phase is complete")
now := metav1.Now()
jenkins.Status.BaseConfigurationCompletedTime = &now
err = r.client.Update(context.TODO(), jenkins)
if err != nil {
return reconcile.Result{}, err
}
logger.Info("Base configuration completed time has been updated")
}

// Reconcile user configuration
Expand All @@ -157,12 163,14 @@ func (r *ReconcileJenkins) reconcile(request reconcile.Request, logger logr.Logg
return *result, nil
}
if jenkins.Status.UserConfigurationCompletedTime == nil {
logger.Info("User configuration phase is complete")
now := metav1.Now()
jenkins.Status.UserConfigurationCompletedTime = &now
err = r.client.Update(context.TODO(), jenkins)
if err != nil {
return reconcile.Result{}, err
}
logger.Info("User configuration completed time has been updated")
}

return reconcile.Result{}, nil
Expand Down

0 comments on commit e187640

Please sign in to comment.