diff --git a/cmd/yawol-controller/main.go b/cmd/yawol-controller/main.go index d01cdf1a..3e02fdab 100644 --- a/cmd/yawol-controller/main.go +++ b/cmd/yawol-controller/main.go @@ -4,6 +4,7 @@ import ( "context" "flag" "os" + "strings" "time" "github.com/stackitcloud/yawol/controllers/yawol-controller/loadbalancer" @@ -68,6 +69,9 @@ func main() { var yawolletRequeueTime int var lbmDeletionGracePeriod time.Duration + var ntpServers string + var ntpPool string + var openstackTimeout time.Duration // settings for leases @@ -108,6 +112,9 @@ func main() { "Grace period before deleting a load balancer machine AFTER the machine has first been identified as unready.", ) + flag.StringVar(&ntpPool, "ntp-pool", "", "A NTP Pool which is used in LBMs.") + flag.StringVar(&ntpServers, "ntp-servers", "", "A comma separated list of NTP Servers which are used in LBMs.") + flag.DurationVar(&openstackTimeout, "openstack-timeout", 20*time.Second, "Timeout for all requests against Openstack.") flag.IntVar(&leasesDurationInt, "leases-duration", 60, @@ -288,6 +295,8 @@ func main() { Metrics: &helpermetrics.LoadBalancerMachineMetrics, OpenstackTimeout: openstackTimeout, YawolletRequeueTime: yawolletRequeueTime, + NTPServers: strings.Split(ntpServers, ","), + NTPPool: ntpPool, DiscoveryClient: discoveryClient, RateLimiter: rateLimiter, }).SetupWithManager(loadBalancerMachineMgr); err != nil { diff --git a/controllers/yawol-controller/loadbalancermachine/loadbalancermachine_controller.go b/controllers/yawol-controller/loadbalancermachine/loadbalancermachine_controller.go index 6fd35989..279f398d 100644 --- a/controllers/yawol-controller/loadbalancermachine/loadbalancermachine_controller.go +++ b/controllers/yawol-controller/loadbalancermachine/loadbalancermachine_controller.go @@ -63,6 +63,8 @@ type LoadBalancerMachineReconciler struct { //nolint:revive // naming from kubeb WorkerCount int OpenstackTimeout time.Duration YawolletRequeueTime int + NTPServers []string + NTPPool string DiscoveryClient *discovery.DiscoveryClient RateLimiter ratelimiter.RateLimiter } @@ -685,6 +687,8 @@ func (r *LoadBalancerMachineReconciler) reconcileServer( loadBalancerMachine, vip, r.YawolletRequeueTime, + r.NTPPool, + r.NTPServers, ) if err != nil { return err diff --git a/internal/helper/loadbalancermachine.go b/internal/helper/loadbalancermachine.go index ea2dcc0d..34501f3a 100644 --- a/internal/helper/loadbalancermachine.go +++ b/internal/helper/loadbalancermachine.go @@ -251,6 +251,8 @@ func GenerateUserData( loadbalancerMachine *yawolv1beta1.LoadBalancerMachine, vip string, yawolletRequeueTime int, + ntpPool string, + ntpServers []string, ) (string, error) { var err error const ( @@ -281,6 +283,11 @@ func GenerateUserData( } promtailConfigBase64 := base64.StdEncoding.EncodeToString([]byte(promtailConfig)) + var chronyConfig string + if ntpPool != "" || len(ntpServers) > 0 { + chronyConfig = generateChronyConfig(ntpPool, ntpServers) + } + sshOpenRC := openRCDel sshOpenRCState := openRCStop if loadbalancer.Spec.DebugSettings.Enabled { @@ -300,9 +307,20 @@ func GenerateUserData( yawolletArgs = yawolletArgs + "-requeue-time=" + strconv.Itoa(yawolletRequeueTime) + " " } - return ` + cloudInit := ` #cloud-config -write_files: +write_files:` + + if chronyConfig != "" { + cloudInit += ` +- encoding: b64 +content: ` + base64.StdEncoding.EncodeToString([]byte(chronyConfig)) + ` +owner: root:root +path: /etc/chrony/chrony.conf +permissions: '0644'` + } + + cloudInit += ` - encoding: b64 content: ` + kubeconfigBase64 + ` owner: yawol:yawol @@ -334,7 +352,26 @@ runcmd: - [ /sbin/rc-service, keepalived, restart ] - [ /sbin/rc-service, envoy, restart ] - [ /sbin/rc-service, yawollet, restart ] -`, nil +` + + return cloudInit, nil +} + +func generateChronyConfig(ntpPool string, ntpServers []string) string { + var chronyConfig string + if len(ntpServers) > 0 { + for _, ntpServer := range ntpServers { + chronyConfig += fmt.Sprintf("server %s iburst\n", ntpServer) + } + } + if ntpPool != "" { + // most likely you use pool or server but as the chrony config is valid with both we just add both. + chronyConfig += fmt.Sprintf("pool %s iburst\n", ntpPool) + } + chronyConfig += `driftfile /var/lib/chrony/chrony.drift +rtcsync +cmdport 0` + return chronyConfig } func generateKeepalivedConfig(vip string) string {