Skip to content

Commit

Permalink
Use variadic command line flags for setting sync annotations.
Browse files Browse the repository at this point in the history
Signed-off-by: Rodrigo Reis <[email protected]>
  • Loading branch information
gargravarr committed Jan 17, 2024
1 parent 8a3fd20 commit 0b3b353
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 165 deletions.
10 changes: 3 additions & 7 deletions cmd/e2e/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,15 @@ kubectl proxy
```
watch -n 10 "kubectl get -n foo stackset,stack,ing,ep,deployment"
```
3. generate config file from end-2-end setup
```
sed -ne '/stackset-controller-config/{:a' -e 'n;p;ba' -e '}' \
e2e/apply/config.yaml > /tmp/stackset-controller-config.yaml
```
4. recreate namespace `foo` and run local build stackset-controller
3. recreate namespace `foo` and run local build stackset-controller
```
kubectl delete namespace foo; kubectl create namespace foo
make
./build/stackset-controller --apiserver=http://127.0.0.1:8001 \
--enable-configmap-support --enable-routegroup-support \
--enable-traffic-segments --annotated-traffic-segments \
--config-file=/tmp/stackset-controller-config.yaml --controller-id=foo \
--sync-ingress-annotation=example.org/i-haz-synchronize \
--sync-ingress-annotation=teapot.org/the-best --controller-id=foo \
--cluster-domain=${CLUSTER_DOMAIN} --cluster-domain=${CLUSTER_DOMAIN_INTERNAL}
```
4. rebuild e2e test and run e2e tests in `foo` namespace
Expand Down
7 changes: 6 additions & 1 deletion cmd/stackset-controller/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ var (
RouteGroupSupportEnabled bool
TrafficSegmentsEnabled bool
AnnotatedTrafficSegments bool
SyncIngressAnnotations []string
IngressSourceSwitchTTL time.Duration
ReconcileWorkers int
ConfigMapSupportEnabled bool
Expand Down Expand Up @@ -72,6 +73,10 @@ func main() {
"annotated-traffic-segments",
"Only support traffic segments when annotated. Requires --enable-traffic-segments.",
).Default("false").BoolVar(&config.AnnotatedTrafficSegments)
kingpin.Flag(
"sync-ingress-annotation",
"Ingress/RouteGroup annotation to propagate to all traffic segments.",
).StringsVar(&config.SyncIngressAnnotations)
kingpin.Flag("ingress-source-switch-ttl", "The ttl before an ingress source is deleted when replaced with another one e.g. switching from RouteGroup to Ingress or vice versa.").
Default(defaultIngressSourceSwitchTTL).DurationVar(&config.IngressSourceSwitchTTL)
kingpin.Flag("enable-configmap-support", "Enable support for ConfigMaps on StackSets.").Default("false").BoolVar(&config.ConfigMapSupportEnabled)
Expand All @@ -94,7 +99,6 @@ func main() {

controller, err := controller.NewStackSetController(
client,
config.ConfigFile,
config.ControllerID,
config.ReconcileWorkers,
config.BackendWeightsAnnotationKey,
Expand All @@ -104,6 +108,7 @@ func main() {
config.RouteGroupSupportEnabled,
config.TrafficSegmentsEnabled,
config.AnnotatedTrafficSegments,
config.SyncIngressAnnotations,
config.ConfigMapSupportEnabled,
config.IngressSourceSwitchTTL,
)
Expand Down
58 changes: 22 additions & 36 deletions controller/stackset.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
rgv1 "github.com/szuecs/routegroup-client/apis/zalando.org/v1"
zv1 "github.com/zalando-incubator/stackset-controller/pkg/apis/zalando.org/v1"
"github.com/zalando-incubator/stackset-controller/pkg/clientset"
"github.com/zalando-incubator/stackset-controller/pkg/config"
"github.com/zalando-incubator/stackset-controller/pkg/core"
"github.com/zalando-incubator/stackset-controller/pkg/recorder"
"golang.org/x/sync/errgroup"
Expand Down Expand Up @@ -50,26 +49,25 @@ const (
// stackset resources and starts and maintains other controllers per
// stackset resource.
type StackSetController struct {
logger *log.Entry
client clientset.Interface
configFile string
synchronizeIngressAnnotations []string
controllerID string
backendWeightsAnnotationKey string
clusterDomains []string
interval time.Duration
stacksetEvents chan stacksetEvent
stacksetStore map[types.UID]zv1.StackSet
recorder kube_record.EventRecorder
metricsReporter *core.MetricsReporter
HealthReporter healthcheck.Handler
routeGroupSupportEnabled bool
trafficSegmentsEnabled bool
annotatedTrafficSegments bool
ingressSourceSwitchTTL time.Duration
now func() string
reconcileWorkers int
configMapSupportEnabled bool
logger *log.Entry
client clientset.Interface
syncIngressAnnotations []string
controllerID string
backendWeightsAnnotationKey string
clusterDomains []string
interval time.Duration
stacksetEvents chan stacksetEvent
stacksetStore map[types.UID]zv1.StackSet
recorder kube_record.EventRecorder
metricsReporter *core.MetricsReporter
HealthReporter healthcheck.Handler
routeGroupSupportEnabled bool
trafficSegmentsEnabled bool
annotatedTrafficSegments bool
ingressSourceSwitchTTL time.Duration
now func() string
reconcileWorkers int
configMapSupportEnabled bool
sync.Mutex
}

Expand All @@ -94,7 +92,6 @@ func now() string {
// NewStackSetController initializes a new StackSetController.
func NewStackSetController(
client clientset.Interface,
configFile string,
controllerID string,
parallelWork int,
backendWeightsAnnotationKey string,
Expand All @@ -104,6 +101,7 @@ func NewStackSetController(
routeGroupSupportEnabled bool,
trafficSegmentsEnabled bool,
annotatedTrafficSegments bool,
syncIngressAnnotations []string,
configMapSupportEnabled bool,
ingressSourceSwitchTTL time.Duration,
) (*StackSetController, error) {
Expand All @@ -115,7 +113,6 @@ func NewStackSetController(
return &StackSetController{
logger: log.WithFields(log.Fields{"controller": "stackset"}),
client: client,
configFile: configFile,
controllerID: controllerID,
backendWeightsAnnotationKey: backendWeightsAnnotationKey,
clusterDomains: clusterDomains,
Expand All @@ -128,6 +125,7 @@ func NewStackSetController(
routeGroupSupportEnabled: routeGroupSupportEnabled,
trafficSegmentsEnabled: trafficSegmentsEnabled,
annotatedTrafficSegments: annotatedTrafficSegments,
syncIngressAnnotations: syncIngressAnnotations,
ingressSourceSwitchTTL: ingressSourceSwitchTTL,
configMapSupportEnabled: configMapSupportEnabled,
now: now,
Expand Down Expand Up @@ -176,18 +174,6 @@ func (c *StackSetController) Run(ctx context.Context) {

nextCheck = time.Now().Add(c.interval)

if c.configFile != "" {
config, err := config.ReadConfig(c.configFile)
if err == nil {
c.synchronizeIngressAnnotations = config.SynchronizeIngressAnnotations
} else {
c.logger.Errorf(
"Failed reading configuration from file: %v",
err,
)
}
}

stackSetContainers, err := c.collectResources(ctx)
if err != nil {
c.logger.Errorf("Failed to collect resources: %v", err)
Expand Down Expand Up @@ -326,7 +312,7 @@ func (c *StackSetController) collectResources(ctx context.Context) (map[types.UI

stacksetContainer.EnableSegmentTraffic()
stacksetContainer.SynchronizeIngressAnnotations(
c.synchronizeIngressAnnotations,
c.syncIngressAnnotations,
)
}
stacksets[uid] = stacksetContainer
Expand Down
2 changes: 1 addition & 1 deletion controller/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ func NewTestEnvironment() *testEnvironment {
controller, err := NewStackSetController(
client,
"",
"",
10,
"",
nil,
Expand All @@ -70,6 +69,7 @@ func NewTestEnvironment() *testEnvironment {
true,
true,
true,
[]string{},
true,
time.Minute,
)
Expand Down
9 changes: 0 additions & 9 deletions e2e/apply/config.yaml

This file was deleted.

12 changes: 2 additions & 10 deletions e2e/apply/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,15 @@ spec:
image: "{{{IMAGE}}}"
args:
- "--controller-id={{{CONTROLLER_ID}}}"
- "--config-file=/meta/config/stackset-controller-config.yaml"
- "--cluster-domain={{{CLUSTER_DOMAIN}}}"
- "--cluster-domain={{{CLUSTER_DOMAIN_INTERNAL}}}"
- "--enable-configmap-support"
- "--enable-routegroup-support"
- "--enable-traffic-segments"
- "--annotated-traffic-segments"
- "--sync-ingress-annotation=example.org/i-haz-synchronize"
- "--sync-ingress-annotation=teapot.org/the-best"
- "--ingress-source-switch-ttl=1m"
volumeMounts:
- name: config
mountPath: /meta/config
readOnly: true
resources:
limits:
cpu: 10m
Expand All @@ -49,8 +46,3 @@ spec:
readOnlyRootFilesystem: true
capabilities:
drop: ["ALL"]
volumes:
- name: config
configMap:
defaultMode: 420
name: "{{{APPLICATION}}}-config"
3 changes: 2 additions & 1 deletion e2e/run_e2e.sh
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,10 @@ echo ">>> Writing controller logs in $controllerLog"
sscPath=$(find build/ -name "stackset-controller" | head -n 1)
command $sscPath --apiserver=http://127.0.0.1:8001 \
--ingress-source-switch-ttl="1m" \
--config-file=/tmp/stackset-controller-config.yaml \
--enable-traffic-segments \
--annotated-traffic-segments \
--sync-ingress-annotation=example.org/i-haz-synchronize \
--sync-ingress-annotation=teapot.org/the-best \
--enable-configmap-support \
--enable-routegroup-support \
--cluster-domain=${CLUSTER_DOMAIN} \
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ require (
github.com/stretchr/testify v1.8.4
github.com/szuecs/routegroup-client v0.21.1
golang.org/x/sync v0.5.0
gopkg.in/yaml.v3 v3.0.1
k8s.io/api v0.24.17
k8s.io/apimachinery v0.24.17
k8s.io/client-go v0.24.17
Expand Down Expand Up @@ -72,6 +71,7 @@ require (
gopkg.in/DATA-DOG/go-sqlmock.v1 v1.3.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/apiextensions-apiserver v0.24.0 // indirect
k8s.io/gengo v0.0.0-20211129171323-c02415ce4185 // indirect
k8s.io/klog/v2 v2.90.0 // indirect
Expand Down
26 changes: 0 additions & 26 deletions pkg/config/config.go

This file was deleted.

73 changes: 0 additions & 73 deletions pkg/config/config_test.go

This file was deleted.

0 comments on commit 0b3b353

Please sign in to comment.