forked from VirtusLab/jenkins-operator
-
Notifications
You must be signed in to change notification settings - Fork 236
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Intermediate change for usage of Deployment
Allows for using the annotation jenkins.io/use-deployment and setting the value to true makes the operator use a Deployment instead of Pod for serving Jenkins. This is part of an experimental feature.
- Loading branch information
1 parent
90c4cfb
commit 095b3e9
Showing
7 changed files
with
363 additions
and
212 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package base | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/jenkinsci/kubernetes-operator/pkg/apis/jenkins/v1alpha2" | ||
"github.com/jenkinsci/kubernetes-operator/pkg/controller/jenkins/configuration/base/resources" | ||
"github.com/jenkinsci/kubernetes-operator/pkg/controller/jenkins/notifications/event" | ||
"github.com/jenkinsci/kubernetes-operator/pkg/controller/jenkins/notifications/reason" | ||
"github.com/jenkinsci/kubernetes-operator/version" | ||
stackerr "github.com/pkg/errors" | ||
apierrors "k8s.io/apimachinery/pkg/api/errors" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"sigs.k8s.io/controller-runtime/pkg/reconcile" | ||
) | ||
|
||
func (r *ReconcileJenkinsBaseConfiguration) ensureJenkinsDeployment(meta metav1.ObjectMeta) (reconcile.Result, error) { | ||
userAndPasswordHash, err := r.calculateUserAndPasswordHash() | ||
if err != nil { | ||
return reconcile.Result{}, err | ||
} | ||
|
||
jenkinsDeployment, err := r.GetJenkinsDeployment() | ||
if apierrors.IsNotFound(err) { | ||
jenkinsDeployment = resources.NewJenkinsDeployment(meta, r.Configuration.Jenkins) | ||
*r.Notifications <- event.Event{ | ||
Jenkins: *r.Configuration.Jenkins, | ||
Phase: event.PhaseBase, | ||
Level: v1alpha2.NotificationLevelInfo, | ||
Reason: reason.NewPodCreation(reason.OperatorSource, []string{"Creating a Jenkins Deployment"}), | ||
} | ||
|
||
r.logger.Info(fmt.Sprintf("Creating a new Jenkins Deployment %s/%s", jenkinsDeployment.Namespace, jenkinsDeployment.Name)) | ||
err := r.CreateResource(jenkinsDeployment) | ||
if err != nil { | ||
return reconcile.Result{}, stackerr.WithStack(err) | ||
} | ||
|
||
now := metav1.Now() | ||
r.Configuration.Jenkins.Status = v1alpha2.JenkinsStatus{ | ||
OperatorVersion: version.Version, | ||
ProvisionStartTime: &now, | ||
LastBackup: r.Configuration.Jenkins.Status.LastBackup, | ||
PendingBackup: r.Configuration.Jenkins.Status.LastBackup, | ||
UserAndPasswordHash: userAndPasswordHash, | ||
} | ||
return reconcile.Result{Requeue: true}, r.Client.Update(context.TODO(), r.Configuration.Jenkins) | ||
} else if err != nil && !apierrors.IsNotFound(err) { | ||
return reconcile.Result{}, stackerr.WithStack(err) | ||
} | ||
|
||
// TODO (waveywaves): replace with a cleaner solution | ||
_ = jenkinsDeployment // This is to escape the variable is never used golint err | ||
return reconcile.Result{}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.