Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions openstack-seeder/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ func main() {
pflag.StringVar(&options.KubeConfig, "kubeconfig", "", "Path to kubeconfig file with authorization and master location information.")
pflag.BoolVar(&options.DryRun, "dry-run", false, "Only pretend to seed.")
pflag.StringVar(&options.InterfaceType, "interface", "internal", "Openstack service interface type to use.")
pflag.StringVar(&options.IgnoreNamespace, "ignorenamespace", "", "Ignore seeds from a certain k8s Namespace.")
pflag.StringVar(&options.OnlyNamespace, "onlynamespace", "", "Only apply seeds from a certain k8s Namespace.")
pflag.StringArrayVar(&options.IgnoreNamespaces, "ignorenamespace", nil, "Ignore seeds from a certain k8s Namespace (can be given multiple times to ignore multiple namespaces).")
pflag.StringArrayVar(&options.OnlyNamespaces, "onlynamespace", nil, "Only apply seeds from a certain k8s Namespace (can be given multiple times to watch multiple namespaces).")
pflag.CommandLine.AddGoFlagSet(flag.CommandLine)
pflag.Parse()

Expand Down
31 changes: 17 additions & 14 deletions openstack-seeder/pkg/seeder/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ package controller
import (
"context"
"flag"
"slices"

"gopkg.in/yaml.v2"

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

"fmt"
"github.com/getsentry/raven-go"
"github.com/golang/glog"
"k8s.io/client-go/tools/clientcmd"
"os"
"os/exec"
"strings"
"time"

"github.com/getsentry/raven-go"
"github.com/golang/glog"
"k8s.io/client-go/tools/clientcmd"
Copy link
Contributor Author

@majewsky majewsky May 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI, my auto-formatter reshuffled the imports here.

)

var (
Expand All @@ -48,11 +51,11 @@ var (
)

type Options struct {
KubeConfig string
DryRun bool
InterfaceType string
IgnoreNamespace string
OnlyNamespace string
KubeConfig string
DryRun bool
InterfaceType string
IgnoreNamespaces []string
OnlyNamespaces []string
}

type SeederController struct {
Expand Down Expand Up @@ -210,15 +213,15 @@ func (c *SeederController) seedApply(seed *seederv1.OpenstackSeed) {
}

// to allow to ignore seeds from a particular namespace
if seed.ObjectMeta.Namespace == c.Options.IgnoreNamespace {
glog.Infof("Ignoring seeds from %s Namespace.", c.Options.IgnoreNamespace)
if slices.Contains(c.Options.IgnoreNamespaces, seed.ObjectMeta.Namespace) {
glog.Infof("Ignoring seeds from %s Namespace.", seed.ObjectMeta.Namespace)
return
}

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

if err = cmd.Start(); err != nil {
glog.Errorf("ERROR: could not spawn %s: ", seeder_name, err)
glog.Errorf("ERROR: could not spawn %s: %v", seeder_name, err)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI, my linter complained about this clearly wrong statement, so I fixed this while having the file open.

}

stdin.Write(yaml_seed)
Expand Down