From 254858e07a2bc98bbd605bfdf4f9902d82960977 Mon Sep 17 00:00:00 2001 From: nicklesimba Date: Wed, 22 Nov 2023 12:30:19 -0600 Subject: [PATCH] Extended support for customizing whereabouts ip-reconciler cron schedule Signed-off-by: nicklesimba --- cmd/controlloop/controlloop.go | 22 ++++++++++++++++------ doc/crds/daemonset-install.yaml | 19 +++++++++++++++++++ doc/extended-configuration.md | 21 +++++++++++++++++++-- pkg/types/types.go | 4 ++-- script/install-cni.sh | 2 +- 5 files changed, 57 insertions(+), 11 deletions(-) diff --git a/cmd/controlloop/controlloop.go b/cmd/controlloop/controlloop.go index 15c1186b9..6989756eb 100644 --- a/cmd/controlloop/controlloop.go +++ b/cmd/controlloop/controlloop.go @@ -5,6 +5,7 @@ import ( "fmt" "os" "os/signal" + "strings" "time" gocron "github.com/go-co-op/gocron" @@ -28,8 +29,9 @@ import ( ) const ( - allNamespaces = "" - controllerName = "pod-ip-controlloop" + allNamespaces = "" + controllerName = "pod-ip-controlloop" + reconciler_cron_file = "cron-schedule/reconciler_cron_file" ) const ( @@ -66,7 +68,7 @@ func main() { defer networkController.Shutdown() s := gocron.NewScheduler(time.UTC) - schedule := cronExpressionFromFlatFile() + schedule := determineCronExpression() _, err = s.Cron(schedule).Do(func() { // user configurable cron expression in install-cni.sh reconciler.ReconcileIPs(errorChan) @@ -164,11 +166,19 @@ func newEventRecorder(broadcaster record.EventBroadcaster) record.EventRecorder return broadcaster.NewRecorder(scheme.Scheme, corev1.EventSource{Component: controllerName}) } -func cronExpressionFromFlatFile() string { +func determineCronExpression() string { flatipam, _, err := config.GetFlatIPAM(true, &types.IPAMConfig{}, "") if err != nil { - _ = logging.Errorf("could not get flatipam: %v", err) + _ = logging.Errorf("could not get flatipam config: %v", err) os.Exit(couldNotGetFlatIPAM) } - return flatipam.IPAM.ReconcilerCronExpression + + // We read the expression from a file if present, otherwise we use ReconcilerCronExpression + fileContents, err := os.ReadFile("cron-schedule/reconciler_cron_file") // Yuki~ this might be what needs changing if anything. Perhaps it's going to use the wrong filepath. + if err != nil { + _ = logging.Errorf("could not read file: %v, using expression from flatfile: %v", err, flatipam.IPAM.ReconcilerCronExpression) + return flatipam.IPAM.ReconcilerCronExpression + } + logging.Verbosef("using expression: %v", strings.TrimSpace(string(fileContents))) // do i need to trim spaces? idk i think the file would JUST be the expression? + return strings.TrimSpace(string(fileContents)) } diff --git a/doc/crds/daemonset-install.yaml b/doc/crds/daemonset-install.yaml index 0e57128b3..590b49bb1 100644 --- a/doc/crds/daemonset-install.yaml +++ b/doc/crds/daemonset-install.yaml @@ -70,6 +70,19 @@ rules: - patch - update - get + +--- +apiVersion: v1 +kind: ConfigMap +metadata: + name: cron-scheduler-configmap + namespace: kube-system + annotations: + kubernetes.io/description: | + Configmap containing user customizable cronjob schedule +data: + reconciler_cron_file: "30 4 * * *" # Default schedule is once per day at 4:30am. Users may configure this value to their liking. + --- apiVersion: apps/v1 kind: DaemonSet @@ -130,6 +143,8 @@ spec: mountPath: /host/opt/cni/bin - name: cni-net-dir mountPath: /host/etc/cni/net.d + - name: cron-scheduler-configmap + mountPath: /cron-schedule volumes: - name: cnibin hostPath: @@ -137,3 +152,7 @@ spec: - name: cni-net-dir hostPath: path: /etc/cni/net.d + - name: cron-scheduler-configmap + configMap: + name: "cron-scheduler-configmap" + defaultMode: 0744 diff --git a/doc/extended-configuration.md b/doc/extended-configuration.md index c42b86e2b..be0cd4f5c 100644 --- a/doc/extended-configuration.md +++ b/doc/extended-configuration.md @@ -134,9 +134,13 @@ spec: You'll note that in the `ipam` section there's a lot less parameters than are used in the previous examples. -### Reconciler Cron Expression Configuration (optional) +## Reconciler Cron Expression configuration for clusters via flatfile (optional) -You may want to provide a cron expression to configure how frequently the ip-reconciler runs. This is done via the flatfile. +*NOTE: configuring cron expression prior to cluster launch will only work for **non-Openshift** Kubernetes clusters, such as a vanilla Kubernetes cluster. Skip to the next section if you have an Openshift cluster or a cluster that has already launched.* + +Yuki~ do we even need to support configuring via flatfile? Leaving it for now, but hey, food for thought. + +You may want to provide a cron expression to configure how frequently the ip-reconciler runs. For clusters that have not yet been launched, this can be configured via the flatfile. You can speficy the `WHEREABOUTS_RECONCILER_CRON` environment variable in your daemonset definition file to override the default cron expression: ```yaml @@ -144,6 +148,19 @@ You can speficy the `WHEREABOUTS_RECONCILER_CRON` environment variable in your d - name: WHEREABOUTS_RECONCILER_CRON value: 30 * * * * ``` + +## Reconciler Cron Expression Configuration for live clusters via configmap (optional) + +Yuki~ README: this section may belong in the CNO since the steps outlined are not technically part of whereabouts. I'm not sure, and suggestions are welcome. + +You may want to provide a cron expression to configure how frequently the ip-reconciler runs. For **Openshift** Kubernetes clusters, this is done via updating the cron-scheduler-configmap. + +You can check that the cron-scheduler-configmap is present by running `oc get configmaps` in the openshift-multus namespace. + +To update the cron-scheduler-configmap, run `oc edit configmap cron-scheduler-configmap` and adjust the value to a valid cron expression of your liking. Shortly after, the reconciler schedule will update. + +If you are using a non-Openshift cluster, you can do the same steps, but you will need to look for the configmap in the kube-system namespace. + ## Installing etcd. (optional) etcd installation is optional. By default, we recommend the custom resource backend (given in the first example configuration). diff --git a/pkg/types/types.go b/pkg/types/types.go index a12ec43ed..519a094a5 100644 --- a/pkg/types/types.go +++ b/pkg/types/types.go @@ -70,7 +70,7 @@ type IPAMConfig struct { ConfigurationPath string `json:"configuration_path"` PodName string PodNamespace string - NetworkName string `json:"network_name,omitempty"` + NetworkName string `json:"network_name,omitempty"` } func (ic *IPAMConfig) UnmarshalJSON(data []byte) error { @@ -106,7 +106,7 @@ func (ic *IPAMConfig) UnmarshalJSON(data []byte) error { ConfigurationPath string `json:"configuration_path"` PodName string PodNamespace string - NetworkName string `json:"network_name,omitempty"` + NetworkName string `json:"network_name,omitempty"` } ipamConfigAlias := IPAMConfigAlias{ diff --git a/script/install-cni.sh b/script/install-cni.sh index 7c6a163c1..18f7abe4f 100755 --- a/script/install-cni.sh +++ b/script/install-cni.sh @@ -19,7 +19,7 @@ WHEREABOUTS_RECONCILER_CRON=${WHEREABOUTS_RECONCILER_CRON:-30 4 * * *} mkdir -p $CNI_CONF_DIR/whereabouts.d WHEREABOUTS_KUBECONFIG=$CNI_CONF_DIR/whereabouts.d/whereabouts.kubeconfig -WHEREABOUTS_FLATFILE=$CNI_CONF_DIR/whereabouts.d/whereabouts.conf +WHEREABOUTS_FLATFILE=$CNI_CONF_DIR/whereabouts.d/whereabouts.conf # Yuki~ Nikhil's note: imo we should remove "flatfile" from whereabouts vocabulary and call this "WHEREABOUTS_CONF_FILE" instead. Flatfile may be the format but it's confusing naming. WHEREABOUTS_KUBECONFIG_LITERAL=$(echo "$WHEREABOUTS_KUBECONFIG" | sed -e s'|/host||') # ------------------------------- Generate a "kube-config"