From 2660f7f3308d0339e543c65ae3580a68d1244ca2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Moritz=20Wanzenb=C3=B6ck?= Date: Tue, 2 Jul 2024 09:12:29 +0200 Subject: [PATCH] auto-detect topology namespace on startup MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Instead of having Helm do the guessing, we once check the available nodes on startup and check for the properties configured there. If we find a label indicating that the Aux/topology namespace is populated, we use that, otherwise we fall back to the normal Aux namespace. Signed-off-by: Moritz Wanzenböck --- CHANGELOG.md | 6 ++++++ README.md | 2 +- cmd/linstor-affinity-controller/main.go | 3 +-- pkg/controller/controller.go | 26 +++++++++++++++++++++++++ 4 files changed, 34 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fe8cd6c..0b60b95 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Changed +- Try to determine LINSTOR CSI topology namespace on startup. + +### Fixed +- Bump golinstor to fix caching issue when filtering nodes for segment. + ## [1.0.1] - 2024-05-02 ### Changed diff --git a/README.md b/README.md index 64adc1a..67e6880 100644 --- a/README.md +++ b/README.md @@ -45,7 +45,7 @@ The following options can be set on the chart: | `options.v` | Set verbosity for controller | `2` | | `options.reconcileRate` | Set the reconcile rate, i.e. how often the cluster state will be checked and updated | `15s` | | `options.resyncRate` | How often the controller will resync it's internal cache of Kubernetes resources | `15m` | -| `options.propertyNamespace` | Namespace used by LINSTOR CSI to store Kubernetes Node Labels | `Aux` | +| `options.propertyNamespace` | Namespace used by LINSTOR CSI to store Kubernetes Node Labels | `""` (auto-detected based on existing node labels on startup | | `linstor.Endpoint` | URL of the LINSTOR Controller API. | `""` (auto-detected when using Piraeus-Operator) | | `linstor.clientSecret` | TLS secret to use to authenticate with the LINSTOR API | `""` (auto-detected when using Piraeus-Operator) | | `image.repository` | Repository to pull the linstor-affinity-controller image from. | `quay.io/piraeusdatastore/linstor-affinity-controller` | diff --git a/cmd/linstor-affinity-controller/main.go b/cmd/linstor-affinity-controller/main.go index 008fab5..d00cfdd 100644 --- a/cmd/linstor-affinity-controller/main.go +++ b/cmd/linstor-affinity-controller/main.go @@ -5,7 +5,6 @@ import ( "os/signal" "time" - linstor "github.com/LINBIT/golinstor" "github.com/spf13/cobra" "k8s.io/cli-runtime/pkg/genericclioptions" k8scli "k8s.io/component-base/cli" @@ -60,7 +59,7 @@ func NewControllerCommand() *cobra.Command { cmd.Flags().DurationVar(&resyncRate, "resync-rate", 5*time.Minute, "how often the internal object cache should be resynchronized") cmd.Flags().DurationVar(&timeout, "timeout", 1*time.Minute, "how long a single reconcile attempt can take") cmd.Flags().StringVar(&bindAddress, "bind-address", "[::]:8000", "the address to use for /healthz and /readyz probes") - cmd.Flags().StringVar(&propertyNamespace, "property-namespace", linstor.NamespcAuxiliary, "The property namespace used by LINSTOR CSI") + cmd.Flags().StringVar(&propertyNamespace, "property-namespace", "", "The property namespace used by LINSTOR CSI") electorCfg.AddFlags(cmd.Flags()) return cmd diff --git a/pkg/controller/controller.go b/pkg/controller/controller.go index ef824cb..a8fcc86 100644 --- a/pkg/controller/controller.go +++ b/pkg/controller/controller.go @@ -68,6 +68,16 @@ func NewReconciler(cfg *Config) (*AffinityReconciler, error) { return nil, fmt.Errorf("failed to initialize linstor client: %w", err) } + if cfg.PropertyNamespace == "" { + prop, err := guessPropertyNamespace(context.Background(), lclient) + if err != nil { + return nil, fmt.Errorf("failed to guess property namespace: %w", err) + } + + klog.V(1).Infof("Determined property namespace: '%s'", prop) + cfg.PropertyNamespace = prop + } + lclient.PropertyNamespace = cfg.PropertyNamespace kclient, err := kubernetes.NewForConfig(cfg.RestCfg) @@ -545,3 +555,19 @@ func ApplyAffinity(topos []*csi.Topology) *applyv1core.VolumeNodeAffinityApplyCo return applyv1core.VolumeNodeAffinity().WithRequired(selector) } + +func guessPropertyNamespace(ctx context.Context, lclient *hlclient.HighLevelClient) (string, error) { + nodes, err := lclient.Nodes.GetAll(ctx) + if err != nil { + return "", fmt.Errorf("failed to list nodes for determining property namespace: %w", err) + } + + for i := range nodes { + node := &nodes[i] + if node.Props[linstor.NamespcAuxiliary+"/topology/kubernetes.io/hostname"] != "" { + return linstor.NamespcAuxiliary + "/topology", nil + } + } + + return linstor.NamespcAuxiliary, nil +}