-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds the `cmd` package and implements the controller/reconciler entrypoints. --------- Co-authored-by: Jordan Olshevski <[email protected]>
- Loading branch information
Showing
17 changed files
with
280 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
FROM docker.io/golang:1.21 AS builder | ||
WORKDIR /app | ||
|
||
ADD go.mod . | ||
ADD go.sum . | ||
RUN go mod download | ||
|
||
COPY . . | ||
RUN CGO_ENABLED=0 go build ./cmd/eno-controller | ||
|
||
FROM scratch | ||
COPY --from=builder /app/eno-controller /eno-controller | ||
ENTRYPOINT ["/eno-controller"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package main | ||
|
||
import ( | ||
"flag" | ||
"fmt" | ||
"os" | ||
"time" | ||
|
||
"github.com/go-logr/zapr" | ||
"go.uber.org/zap" | ||
ctrl "sigs.k8s.io/controller-runtime" | ||
|
||
"github.com/Azure/eno/internal/controllers/synthesis" | ||
"github.com/Azure/eno/internal/manager" | ||
) | ||
|
||
// TODO: Expose leader election options | ||
|
||
func main() { | ||
if err := run(); err != nil { | ||
fmt.Fprintf(os.Stderr, "error: %s\n", err) | ||
os.Exit(1) | ||
} | ||
} | ||
|
||
func run() error { | ||
ctx := ctrl.SetupSignalHandler() | ||
var ( | ||
rolloutCooldown time.Duration | ||
synconf = &synthesis.Config{} | ||
) | ||
flag.DurationVar(&synconf.Timeout, "synthesis-timeout", time.Minute, "Maximum lifespan of synthesizer pods") | ||
flag.DurationVar(&rolloutCooldown, "rollout-cooldown", time.Second*30, "Minimum period of time between each ensuing composition update after a synthesizer is updated") | ||
flag.Parse() | ||
|
||
zl, err := zap.NewProduction() | ||
if err != nil { | ||
return err | ||
} | ||
logger := zapr.NewLogger(zl) | ||
|
||
mgr, err := manager.New(logger, &manager.Options{ | ||
Rest: ctrl.GetConfigOrDie(), | ||
}) | ||
if err != nil { | ||
return fmt.Errorf("constructing manager: %w", err) | ||
} | ||
|
||
synconn, err := synthesis.NewSynthesizerConnection(mgr) | ||
if err != nil { | ||
return fmt.Errorf("constructing synthesizer connection: %w", err) | ||
} | ||
|
||
err = synthesis.NewExecController(mgr, synconn) | ||
if err != nil { | ||
return fmt.Errorf("constructing execution controller: %w", err) | ||
} | ||
|
||
err = synthesis.NewRolloutController(mgr, rolloutCooldown) | ||
if err != nil { | ||
return fmt.Errorf("constructing rollout controller: %w", err) | ||
} | ||
|
||
err = synthesis.NewStatusController(mgr) | ||
if err != nil { | ||
return fmt.Errorf("constructing status controller: %w", err) | ||
} | ||
|
||
err = synthesis.NewPodLifecycleController(mgr, synconf) | ||
if err != nil { | ||
return fmt.Errorf("constructing pod lifecycle controller: %w", err) | ||
} | ||
|
||
return mgr.Start(ctx) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
FROM docker.io/golang:1.21 AS builder | ||
WORKDIR /app | ||
|
||
ADD go.mod . | ||
ADD go.sum . | ||
RUN go mod download | ||
|
||
COPY . . | ||
RUN CGO_ENABLED=0 go build ./cmd/eno-reconciler | ||
|
||
FROM scratch | ||
COPY --from=builder /app/eno-reconciler /eno-reconciler | ||
ENTRYPOINT ["/eno-reconciler"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package main | ||
|
||
import ( | ||
"flag" | ||
"fmt" | ||
"os" | ||
"time" | ||
|
||
"github.com/go-logr/zapr" | ||
"go.uber.org/zap" | ||
ctrl "sigs.k8s.io/controller-runtime" | ||
|
||
"github.com/Azure/eno/internal/controllers/reconciliation" | ||
"github.com/Azure/eno/internal/manager" | ||
"github.com/Azure/eno/internal/reconstitution" | ||
) | ||
|
||
func main() { | ||
if err := run(); err != nil { | ||
fmt.Fprintf(os.Stderr, "error: %s\n", err) | ||
os.Exit(1) | ||
} | ||
} | ||
|
||
// TODO: Label filters, etc. | ||
|
||
func run() error { | ||
ctx := ctrl.SetupSignalHandler() | ||
var ( | ||
rediscoverWhenNotFound bool | ||
writeBatchInterval time.Duration | ||
discoveryMaxRPS float32 | ||
) | ||
flag.BoolVar(&rediscoverWhenNotFound, "rediscover-when-not-found", true, "Invalidate discovery cache when any type is not found in the openapi spec. Set this to false on <= k8s 1.14") | ||
flag.DurationVar(&writeBatchInterval, "write-batch-interval", time.Second*5, "The max throughput of composition status updates") | ||
flag.Parse() | ||
|
||
zl, err := zap.NewProduction() | ||
if err != nil { | ||
return err | ||
} | ||
logger := zapr.NewLogger(zl) | ||
|
||
mgr, err := manager.New(logger, &manager.Options{ | ||
Rest: ctrl.GetConfigOrDie(), | ||
}) | ||
if err != nil { | ||
return fmt.Errorf("constructing manager: %w", err) | ||
} | ||
|
||
recmgr, err := reconstitution.New(mgr, writeBatchInterval) | ||
if err != nil { | ||
return fmt.Errorf("constructing reconstitution manager: %w", err) | ||
} | ||
|
||
err = reconciliation.New(recmgr, mgr.GetConfig(), discoveryMaxRPS, rediscoverWhenNotFound) | ||
if err != nil { | ||
return fmt.Errorf("constructing reconciliation controller: %w", err) | ||
} | ||
|
||
return mgr.Start(ctx) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#!/bin/bash | ||
|
||
set -e | ||
|
||
if [[ -z "${REGISTRY}" ]]; then | ||
echo "REGISTRY must be set" > /dev/stderr | ||
exit 1 | ||
fi | ||
|
||
export TAG="$(date +%s)" | ||
|
||
function build() { | ||
cmd=$(basename $1) | ||
buildah build -t "$REGISTRY/$cmd:$TAG" -f "$f/Dockerfile" | ||
buildah push "$REGISTRY/$cmd:$TAG" | ||
} | ||
|
||
# Build! | ||
for f in cmd/*; do | ||
build $f & | ||
done | ||
wait | ||
|
||
# Deploy! | ||
cat "$(dirname "$0")/deploy.yaml" | envsubst | kubectl apply -f - | ||
echo "Success! You're running tag: $TAG" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: eno-controller | ||
labels: | ||
app: eno-controller | ||
spec: | ||
replicas: 1 | ||
selector: | ||
matchLabels: | ||
app: eno-controller | ||
template: | ||
metadata: | ||
labels: | ||
app: eno-controller | ||
spec: | ||
containers: | ||
- name: eno-controller | ||
image: $REGISTRY/eno-controller:$TAG | ||
|
||
--- | ||
|
||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: eno-reconciler | ||
labels: | ||
app: eno-reconciler | ||
spec: | ||
replicas: 1 | ||
selector: | ||
matchLabels: | ||
app: eno-reconciler | ||
template: | ||
metadata: | ||
labels: | ||
app: eno-reconciler | ||
spec: | ||
containers: | ||
- name: eno-reconciler | ||
image: $REGISTRY/eno-reconciler:$TAG |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
apiVersion: eno.azure.io/v1 | ||
kind: Synthesizer | ||
metadata: | ||
name: test-synth | ||
spec: | ||
image: docker.io/ubuntu:latest | ||
command: | ||
- /bin/bash | ||
- -c | ||
- | | ||
echo '[{ | ||
"apiVersion": "v1", | ||
"kind": "ConfigMap", | ||
"metadata": { "name": "test-cm", "namespace": "default" }, | ||
"data": { "foo": "bar" } | ||
}]' | ||
--- | ||
|
||
apiVersion: eno.azure.io/v1 | ||
kind: Composition | ||
metadata: | ||
name: test-comp | ||
spec: | ||
synthesizer: | ||
name: test-synth |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters