Skip to content

Commit

Permalink
feat(controller): allow specific front image
Browse files Browse the repository at this point in the history
Signed-off-by: Joshua Su <[email protected]>
  • Loading branch information
sujoshua committed Apr 8, 2024
1 parent 2f4b8e9 commit 33381f3
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 10 deletions.
1 change: 1 addition & 0 deletions api/v1beta1/job_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ type JobDeploy struct {
DeployConfig `json:",inline"`

DisableFront string `json:"disableFront,omitempty"`
FrontMode string `json:"frontMode,omitempty"`
FrontImage string `json:"frontImage,omitempty"`
FrontCmd string `json:"frontCmd,omitempty"`
DisableRsync string `json:"disableRsync,omitempty"`
Expand Down
1 change: 1 addition & 0 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ func main() {
PullSecret: os.Getenv("PULL_SECRET"),
StorageClass: os.Getenv("STORAGE_CLASS"),
AccessMode: os.Getenv("ACCESS_MODE"),
FrontMode: os.Getenv("FRONT_MODE"),
FrontImage: os.Getenv("FRONT_IMAGE"),
RsyncImage: os.Getenv("RSYNC_IMAGE"),
FrontCmd: os.Getenv("FRONT_CMD"),
Expand Down
6 changes: 4 additions & 2 deletions config/controller/controller.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,10 @@ spec:
# value: # Default storageClass of worker pvc
# - name: ACCESS_MODE
# value: ReadWriteOnce # Default accessMode of worker pvc
# - name: FRONT_IMAGE # Default image used to deploy the directory service
# value: nginx / caddy
# - name: FRONT_MODE # Default server to be used as Front Server, if this is not set, disable front server
# value: nginx / caddy / ''
# - name: FRONT_IMAGE # Default images used to deploy front server. Be careful, this value is related with FRONT_MODE, if you use nginx, you must specify a nginx image. If this is not set, both nginx and caddy mode pull from dockerhub.
# value: ''
# - name: RSYNC_IMAGE # Default image used to deploy the rsync service
# value: rsync
# - name: FRONT_CMD # Default command used to deploy the directory service
Expand Down
2 changes: 2 additions & 0 deletions config/crd/bases/mirror.redrock.team_jobs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1221,6 +1221,8 @@ spec:
type: string
frontImage:
type: string
frontMode:
type: string
image:
type: string
imagePullPolicy:
Expand Down
2 changes: 1 addition & 1 deletion internal/controller/job_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func (r *JobReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.R
}

var ig *v1.Ingress
disableFront, _, _, _, _, _ := r.checkRsyncFront(&job)
disableFront, _, _, _, _, _, _ := r.checkRsyncFront(&job)
if !disableFront {
ig, err = r.desiredIngress(&job)
if err != nil {
Expand Down
16 changes: 9 additions & 7 deletions internal/controller/job_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,19 @@ const (
RsyncPort = 873
)

func (r *JobReconciler) checkRsyncFront(job *v1beta1.Job) (disableFront, disableRsync bool, frontCmd, rsyncCmd []string, frontImage, rsyncImage string) {
frontImage, rsyncImage = r.Config.FrontImage, r.Config.RsyncImage
func (r *JobReconciler) checkRsyncFront(job *v1beta1.Job) (disableFront, disableRsync bool, frontCmd, rsyncCmd []string, frontMode, frontImage, rsyncImage string) {
frontMode, frontImage, rsyncImage = r.Config.FrontMode, r.Config.FrontImage, r.Config.RsyncImage
frontCmd, rsyncCmd = strings.Split(r.Config.FrontCmd, " "), strings.Split(r.Config.RsyncCmd, " ")
if s, err := strconv.ParseBool(job.Spec.Deploy.DisableFront); err == nil {
disableFront = s
}
if job.Spec.Deploy.FrontImage != "" {
frontImage = job.Spec.Deploy.FrontImage
if job.Spec.Deploy.FrontMode != "" {
frontMode = job.Spec.Deploy.FrontMode
}
if frontImage == "" {
if frontMode == "" {
disableFront = true
} else if frontImage == "" {
frontImage = frontMode + ":latest"
}
if job.Spec.Deploy.FrontCmd != "" {
frontCmd = strings.Split(job.Spec.Deploy.FrontCmd, " ")
Expand Down Expand Up @@ -245,7 +247,7 @@ func (r *JobReconciler) desiredDeployment(job *v1beta1.Job, manager string) (*ap
}
}

disableFront, disableRsync, frontCmd, rsyncCmd, frontImage, rsyncImage := r.checkRsyncFront(job)
disableFront, disableRsync, frontCmd, rsyncCmd, _, frontImage, rsyncImage := r.checkRsyncFront(job)
if !disableFront {
frontProbe := &corev1.Probe{
ProbeHandler: corev1.ProbeHandler{
Expand Down Expand Up @@ -337,7 +339,7 @@ func (r *JobReconciler) desiredService(job *v1beta1.Job) (*corev1.Service, error
Type: corev1.ServiceTypeClusterIP,
},
}
disableFront, disableRsync, _, _, _, _ := r.checkRsyncFront(job)
disableFront, disableRsync, _, _, _, _, _ := r.checkRsyncFront(job)
if !disableFront {
svc.Spec.Ports = append(svc.Spec.Ports, corev1.ServicePort{Name: "front", Port: FrontPort, Protocol: "TCP", TargetPort: intstr.FromString("front")})
}
Expand Down
1 change: 1 addition & 0 deletions internal/controller/manager_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ type Config struct {
PullSecret string
StorageClass string
AccessMode string
FrontMode string
FrontImage string
RsyncImage string
FrontCmd string
Expand Down

0 comments on commit 33381f3

Please sign in to comment.