Skip to content
This repository was archived by the owner on Mar 24, 2025. It is now read-only.
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
11 changes: 8 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ build-rig-operator: ## 🔨 Build rig-operator binary
gen: proto manifests generate-k8s ## 🪄 Run code generation (proto and k8s)

.PHONY: proto
proto: proto-internal proto-public ## 🪄 Generate all protobuf
proto: proto-internal proto-public proto-operator ## 🪄 Generate all protobuf

gen/go/rig/go.mod:
@mkdir -p gen/go/rig
@printf "module github.com/rigdev/rig-go-api\n\ngo 1.20\n" > $@

.PHONY: proto-internal
proto-internal: buf protoc-gen-go protoc-gen-connect-go ## 🪄 Generate internal protobuf
@find . -path './gen/go/*' -not -path './gen/go/rig/*' -type f -name '*.go' -delete
@find . -path './gen/go/*' -not -path './gen/go/rig/*' -not -path './gen/go/operator/*' -type f -name '*.go' -delete
$(BUF) generate proto/internal --template proto/buf.gen.internal.yaml

.PHONY: proto-public
Expand All @@ -46,6 +46,11 @@ proto-public: gen/go/rig/go.mod buf protoc-gen-go protoc-gen-connect-go ## 🪄
$(BUF) generate proto/rig --template proto/buf.gen.yaml
@(cd gen/go/rig/; go get -u ./...)

.PHONY: proto-operator
proto-operator: buf protoc-gen-go protoc-gen-connect-go ## 🪄 Generate operator protobuf
@find . -path './gen/go/operator/*' -type f -name '*.go' -delete
$(BUF) generate proto/operator --template proto/buf.gen.operator.yaml

.PHONY: manifests
manifests: controller-gen ## 🪄 Generate k8s manifests
$(CONTROLLER_GEN) rbac:roleName=rig crd webhook \
Expand Down Expand Up @@ -128,7 +133,7 @@ kind-load: kind docker ## 🐋 Load docker image into kind cluster
$(KIND) load docker-image ghcr.io/rigdev/rig-operator:$(TAG) -n rig

.PHONY: kind-deploy
kind-deploy: kind kind-load deploy ## 🐋 Deploy rig to kind cluster
kind-deploy: kind kind-load deploy-operator ## 🐋 Deploy rig to kind cluster
$(KUBECTL) rollout restart deployment -n rig-system rig-operator

.PHONY: kind-clean
Expand Down
2 changes: 1 addition & 1 deletion build/package/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ RUN --mount=type=cache,target=/go/pkg/mod \
COPY . .
RUN --mount=type=cache,target=/go/pkg/mod \
--mount=type=cache,target=/root/.cache/go-build \
make build-rig-operator
make proto-operator build-rig-operator

FROM scratch

Expand Down
1 change: 1 addition & 0 deletions build/package/Dockerfile.dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
!/Makefile
!/tools/go.mod
!/tools/go.sum
!/proto
!/cmd
!/pkg
!/internal
76 changes: 70 additions & 6 deletions cmd/rig-operator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,23 @@ package main

import (
"context"
"errors"
"net/http"
"os"
"os/signal"
"syscall"
"time"

grpcreflect "github.com/bufbuild/connect-grpcreflect-go"
"github.com/rigdev/rig/gen/go/operator/api/v1/capabilities/capabilitiesconnect"
"github.com/rigdev/rig/pkg/build"
"github.com/rigdev/rig/pkg/config"
"github.com/rigdev/rig/pkg/handler/api/capabilities"
"github.com/rigdev/rig/pkg/manager"
svccapabilities "github.com/rigdev/rig/pkg/service/capabilities"
"github.com/rigdev/rig/pkg/service/config"
"github.com/spf13/cobra"
"golang.org/x/net/http2"
"golang.org/x/net/http2/h2c"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
)
Expand Down Expand Up @@ -41,17 +53,69 @@ func run(cmd *cobra.Command, args []string) error {

scheme := manager.NewScheme()

cfg, err := config.NewLoader(scheme).Load(cfgFile)
cfg, err := config.NewService(cfgFile, scheme)

log := zap.New(zap.UseDevMode(cfg.Get().DevModeEnabled))

ctrl.SetLogger(log)

mgr, err := manager.NewManager(cfg, scheme)
if err != nil {
return err
}

ctrl.SetLogger(zap.New(zap.UseDevMode(cfg.DevModeEnabled)))
mgrCtx, mgrCancel := context.WithCancel(cmd.Context())
defer mgrCancel()

mgr, err := manager.NewManager(cfg, scheme)
if err != nil {
go func() {
log.Info("starting manager server")
mgr.Start(mgrCtx)
}()

capabilitiesSvc := svccapabilities.NewService(cfg)
capabilitiesH := capabilities.NewHandler(capabilitiesSvc)

mux := http.NewServeMux()
mux.Handle(capabilitiesconnect.NewServiceHandler(
capabilitiesH,
))
mux.Handle(grpcreflect.NewHandlerV1(
grpcreflect.NewStaticReflector(capabilitiesconnect.ServiceName),
))
mux.Handle(grpcreflect.NewHandlerV1Alpha(
grpcreflect.NewStaticReflector(capabilitiesconnect.ServiceName),
))

srv := &http.Server{
Addr: ":9000",
Handler: h2c.NewHandler(mux, &http2.Server{}),
ReadHeaderTimeout: time.Second,
ReadTimeout: 5 * time.Minute,
WriteTimeout: 5 * time.Minute,
MaxHeaderBytes: 8 * 1024, // 8KiB
}

go func() {
log.Info("starting GRPC server")
if err := srv.ListenAndServe(); err != nil && !errors.Is(err, http.ErrServerClosed) {
log.Error(err, "could not start GRPC server")
}
}()

signals := make(chan os.Signal, 1)
signal.Notify(signals, os.Interrupt, syscall.SIGTERM)

<-signals

log.Info("received stop signal")

log.Info("stopping GRPC server...")
grpcCTX, grpcCancel := context.WithTimeout(cmd.Context(), time.Second)
defer grpcCancel()
if err := srv.Shutdown(grpcCTX); err != nil {
return err
}

return mgr.Start(cmd.Context())
log.Info("stopping manager...")
return nil
}
2 changes: 1 addition & 1 deletion deploy/charts/rig-operator/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type: application
# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.1.1
version: 0.1.2

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
Expand Down
3 changes: 3 additions & 0 deletions deploy/charts/rig-operator/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ spec:
containerPort: 9443
protocol: TCP
{{- end }}
- name: grpc
containerPort: 9000
protocol: TCP
- name: metrics
containerPort: 8080
protocol: TCP
Expand Down
4 changes: 4 additions & 0 deletions deploy/charts/rig-operator/templates/service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ spec:
port: 9443
targetPort: webhooks
protocol: TCP
- name: grpc
port: 9000
targetPort: http
protocol: TCP
- name: metrics
port: 8080
targetPort: metrics
Expand Down
Loading