Skip to content

Commit 88519db

Browse files
authored
Merge pull request #105 from sapcc/seeder-ignore-multiple-namespaces
openstack-seeder: support selecting or ignoring multiple namespaces
2 parents cc8e7a3 + 043d2bb commit 88519db

File tree

2 files changed

+19
-16
lines changed

2 files changed

+19
-16
lines changed

openstack-seeder/cmd/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ func main() {
4949
pflag.StringVar(&options.KubeConfig, "kubeconfig", "", "Path to kubeconfig file with authorization and master location information.")
5050
pflag.BoolVar(&options.DryRun, "dry-run", false, "Only pretend to seed.")
5151
pflag.StringVar(&options.InterfaceType, "interface", "internal", "Openstack service interface type to use.")
52-
pflag.StringVar(&options.IgnoreNamespace, "ignorenamespace", "", "Ignore seeds from a certain k8s Namespace.")
53-
pflag.StringVar(&options.OnlyNamespace, "onlynamespace", "", "Only apply seeds from a certain k8s Namespace.")
52+
pflag.StringArrayVar(&options.IgnoreNamespaces, "ignorenamespace", nil, "Ignore seeds from a certain k8s Namespace (can be given multiple times to ignore multiple namespaces).")
53+
pflag.StringArrayVar(&options.OnlyNamespaces, "onlynamespace", nil, "Only apply seeds from a certain k8s Namespace (can be given multiple times to watch multiple namespaces).")
5454
pflag.CommandLine.AddGoFlagSet(flag.CommandLine)
5555
pflag.Parse()
5656

openstack-seeder/pkg/seeder/controller/controller.go

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ package controller
1919
import (
2020
"context"
2121
"flag"
22+
"slices"
23+
2224
"gopkg.in/yaml.v2"
2325

2426
"k8s.io/apimachinery/pkg/fields"
@@ -33,13 +35,14 @@ import (
3335
apierrors "k8s.io/apimachinery/pkg/api/errors"
3436

3537
"fmt"
36-
"github.com/getsentry/raven-go"
37-
"github.com/golang/glog"
38-
"k8s.io/client-go/tools/clientcmd"
3938
"os"
4039
"os/exec"
4140
"strings"
4241
"time"
42+
43+
"github.com/getsentry/raven-go"
44+
"github.com/golang/glog"
45+
"k8s.io/client-go/tools/clientcmd"
4346
)
4447

4548
var (
@@ -48,11 +51,11 @@ var (
4851
)
4952

5053
type Options struct {
51-
KubeConfig string
52-
DryRun bool
53-
InterfaceType string
54-
IgnoreNamespace string
55-
OnlyNamespace string
54+
KubeConfig string
55+
DryRun bool
56+
InterfaceType string
57+
IgnoreNamespaces []string
58+
OnlyNamespaces []string
5659
}
5760

5861
type SeederController struct {
@@ -210,15 +213,15 @@ func (c *SeederController) seedApply(seed *seederv1.OpenstackSeed) {
210213
}
211214

212215
// to allow to ignore seeds from a particular namespace
213-
if seed.ObjectMeta.Namespace == c.Options.IgnoreNamespace {
214-
glog.Infof("Ignoring seeds from %s Namespace.", c.Options.IgnoreNamespace)
216+
if slices.Contains(c.Options.IgnoreNamespaces, seed.ObjectMeta.Namespace) {
217+
glog.Infof("Ignoring seeds from %s Namespace.", seed.ObjectMeta.Namespace)
215218
return
216219
}
217220

218221
// to only apply seeds from a particular namespace and ignore the rest
219-
if c.Options.OnlyNamespace != "" {
220-
if seed.ObjectMeta.Namespace != c.Options.OnlyNamespace {
221-
glog.Infof("Ignoring seeds from %s Namespace. Only seeds from %s Namespace will be applied.", seed.ObjectMeta.Namespace, c.Options.OnlyNamespace)
222+
if len(c.Options.OnlyNamespaces) > 0 {
223+
if slices.Contains(c.Options.OnlyNamespaces, seed.ObjectMeta.Namespace) {
224+
glog.Infof("Ignoring seeds from %s Namespace. Only seeds from %v Namespaces will be applied.", seed.ObjectMeta.Namespace, c.Options.OnlyNamespaces)
222225
return
223226
}
224227
}
@@ -266,7 +269,7 @@ func (c *SeederController) seedApply(seed *seederv1.OpenstackSeed) {
266269
cmd.Stderr = os.Stderr
267270

268271
if err = cmd.Start(); err != nil {
269-
glog.Errorf("ERROR: could not spawn %s: ", seeder_name, err)
272+
glog.Errorf("ERROR: could not spawn %s: %v", seeder_name, err)
270273
}
271274

272275
stdin.Write(yaml_seed)

0 commit comments

Comments
 (0)