Skip to content

Commit

Permalink
add basename configurability using environment variables (#50)
Browse files Browse the repository at this point in the history
  • Loading branch information
Oats87 authored Apr 1, 2020
1 parent 98b6b0b commit 4febc37
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions pkg/controllers/scheduledevent/scheduledeventcontroller.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package scheduledevent
import (
"fmt"
"math/rand"
"os"
"strings"
"time"

Expand All @@ -26,6 +27,25 @@ type ScheduledEventController struct {
seSynced cache.InformerSynced
}

var baseNameScheduledPrefix string
var baseNameDynamicPrefix string

func init() {
bnsp := os.Getenv("HF_BASENAME_SCHEDULED_PREFIX")
if bnsp == "" {
baseNameScheduledPrefix = "scheduled"
} else {
baseNameScheduledPrefix = bnsp
}

bndp := os.Getenv("HF_BASENAME_DYNAMIC_PREFIX")
if bndp == "" {
baseNameDynamicPrefix = "dynamic"
} else {
baseNameDynamicPrefix = bndp
}
}

func NewScheduledEventController(hfClientSet *hfClientset.Clientset, hfInformerFactory hfInformers.SharedInformerFactory) (*ScheduledEventController, error) {
seController := ScheduledEventController{}
seController.hfClientSet = hfClientSet
Expand Down Expand Up @@ -265,7 +285,7 @@ func (s *ScheduledEventController) reconcileScheduledEvent(seName string) error

for templateName, count := range vmtMap {
if count > 0 {
vmsRand := fmt.Sprintf("scheduled-%08x", rand.Uint32())
vmsRand := fmt.Sprintf("%s-%08x", baseNameScheduledPrefix, rand.Uint32())
vmsName := strings.Join([]string{"se", se.Name, "vms", vmsRand}, "-")
vmSets = append(vmSets, vmsName)
vms := &hfv1.VirtualMachineSet{
Expand Down Expand Up @@ -305,7 +325,7 @@ func (s *ScheduledEventController) reconcileScheduledEvent(seName string) error
}

// create the dynamic bind configurations
dbcRand := fmt.Sprintf("%08x", rand.Uint32())
dbcRand := fmt.Sprintf("%s-%08x", baseNameDynamicPrefix, rand.Uint32())
dbcName := strings.Join([]string{"se", se.Name, "dbc", dbcRand}, "-")
emptyCap := hfv1.CMSStruct{
CPU: 0,
Expand Down

0 comments on commit 4febc37

Please sign in to comment.