Skip to content

Commit

Permalink
auto-detect topology namespace on startup
Browse files Browse the repository at this point in the history
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 <moritz.wanzenboeck@linbit.com>
  • Loading branch information
WanzenBug committed Jul 2, 2024
1 parent 9362378 commit 2660f7f
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 3 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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` |
Expand Down
3 changes: 1 addition & 2 deletions cmd/linstor-affinity-controller/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
26 changes: 26 additions & 0 deletions pkg/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
}

0 comments on commit 2660f7f

Please sign in to comment.