Skip to content

Commit

Permalink
Implement rudimentary version of ORI & controllers (#524)
Browse files Browse the repository at this point in the history
ORI is the `onmetal-runtime-interface`, a protobuf-based interface for
creating any `MachinePool` provider implementation.

The `ori` api defines the types and operations expected, the
`machinepoollet/controllers` tries to create a basic controller that,
using the `ori` interface, can reconcile `Machine`s for an `ori`
implementation.
  • Loading branch information
adracus authored Oct 31, 2022
1 parent 9e1dd12 commit b359256
Show file tree
Hide file tree
Showing 24 changed files with 16,502 additions and 216 deletions.
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ COPY controllers/ controllers/
COPY equality/ equality/
COPY generated/ generated/
COPY machinepoollet/ machinepoollet/
COPY ori/ ori/
COPY registry/ registry/
COPY serializer/ serializer/
COPY tableconvertor/ tableconvertor/
Expand Down
3 changes: 3 additions & 0 deletions apis/common/v1alpha1/common_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ const (
// Provider controllers that allow for selective reconciliation may check this label and proceed
// with reconciliation of the object only if this label and a configured value are present.
WatchLabel = "common.api.onmetal.de/watch-filter"

// ReconcileRequestAnnotation is an annotation that requested a reconciliation at a specific time.
ReconcileRequestAnnotation = "reconcile.common.api.onmetal.de/requested-at"
)

// ConfigMapKeySelector is a reference to a specific 'key' within a ConfigMap resource.
Expand Down
2 changes: 2 additions & 0 deletions apis/compute/machine_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,8 @@ const (
MachineStateShutdown MachineState = "Shutdown"
// MachineStateError means the machine is in an error state.
MachineStateError MachineState = "Error"
// MachineStateUnknown means the machine is in an unknown state.
MachineStateUnknown MachineState = "Unknown"
)

// MachineConditionType is a type a MachineCondition can have.
Expand Down
26 changes: 26 additions & 0 deletions apis/compute/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,29 @@ func MachineVolumeName(machineName string, volume Volume) string {
return ""
}
}

// MachineVolumeNames returns all Volume names of a machine.
func MachineVolumeNames(machine *Machine) []string {
var names []string
for _, volume := range machine.Spec.Volumes {
if name := MachineVolumeName(machine.Name, volume); name != "" {
names = append(names, name)
}
}
return names
}

// MachineSecretNames returns all secret names of a machine.
func MachineSecretNames(machine *Machine) []string {
var names []string

if imagePullSecretRef := machine.Spec.ImagePullSecretRef; imagePullSecretRef != nil {
names = append(names, imagePullSecretRef.Name)
}

if ignitionRef := machine.Spec.IgnitionRef; ignitionRef != nil {
names = append(names, ignitionRef.Name)
}

return names
}
2 changes: 2 additions & 0 deletions apis/compute/v1alpha1/machine_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,8 @@ const (
MachineStateShutdown MachineState = "Shutdown"
// MachineStateError means the machine is in an error state.
MachineStateError MachineState = "Error"
// MachineStateUnknown means the machine is in an unknown state.
MachineStateUnknown MachineState = "Unknown"
)

// MachineConditionType is a type a MachineCondition can have.
Expand Down
15 changes: 15 additions & 0 deletions apis/compute/v1alpha1/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,18 @@ func MachineVolumeNames(machine *Machine) []string {
}
return names
}

// MachineSecretNames returns all secret names of a machine.
func MachineSecretNames(machine *Machine) []string {
var names []string

if imagePullSecretRef := machine.Spec.ImagePullSecretRef; imagePullSecretRef != nil {
names = append(names, imagePullSecretRef.Name)
}

if ignitionRef := machine.Spec.IgnitionRef; ignitionRef != nil {
names = append(names, ignitionRef.Name)
}

return names
}
4 changes: 2 additions & 2 deletions generated/openapi/zz_generated.openapi.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ require (
github.com/ahmetb/gen-crd-api-reference-docs v0.3.0
github.com/bits-and-blooms/bitset v1.3.3
github.com/go-logr/logr v1.2.3
github.com/gogo/protobuf v1.3.2
github.com/golang/mock v1.6.0
github.com/google/addlicense v1.0.0
github.com/google/go-cmp v0.5.8
Expand All @@ -19,7 +20,9 @@ require (
github.com/spf13/pflag v1.0.5
go.uber.org/atomic v1.10.0
go4.org/netipx v0.0.0-20220812043211-3cc044ffd68d
golang.org/x/exp v0.0.0-20221023144134-a1e5550cf13e
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f
google.golang.org/grpc v1.40.0
k8s.io/api v0.24.3
k8s.io/apimachinery v0.24.3
k8s.io/apiserver v0.24.3
Expand Down Expand Up @@ -62,7 +65,6 @@ require (
github.com/go-openapi/jsonpointer v0.19.5 // indirect
github.com/go-openapi/jsonreference v0.19.5 // indirect
github.com/go-openapi/swag v0.19.14 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/gnostic v0.5.7-v3refs // indirect
Expand Down Expand Up @@ -115,7 +117,6 @@ require (
gomodules.xyz/jsonpatch/v2 v2.2.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20220107163113-42d7afdf6368 // indirect
google.golang.org/grpc v1.40.0 // indirect
google.golang.org/protobuf v1.28.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/natefinch/lumberjack.v2 v2.0.0 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,8 @@ golang.org/x/exp v0.0.0-20191227195350-da58074b4299/go.mod h1:2RIsYlXP63K8oxa1u0
golang.org/x/exp v0.0.0-20200119233911-0405dc783f0a/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4=
golang.org/x/exp v0.0.0-20200207192155-f17229e696bd/go.mod h1:J/WKrq2StrnmMY6+EHIKF9dgMWnmCNThgcyBT1FY9mM=
golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6/go.mod h1:3jZMyOhIsHpP37uCMkUooju7aAi5cS1Q23tOzKc+0MU=
golang.org/x/exp v0.0.0-20221023144134-a1e5550cf13e h1:SkwG94eNiiYJhbeDE018Grw09HIN/KB9NlRmZsrzfWs=
golang.org/x/exp v0.0.0-20221023144134-a1e5550cf13e/go.mod h1:cyybsKvd6eL0RnXn6p/Grxp8F5bW7iYuBgsNCOHpMYE=
golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
Expand Down
2 changes: 2 additions & 0 deletions hack/tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,6 @@ import (
_ "github.com/ahmetb/gen-crd-api-reference-docs"
// Use mockgen for generating mocks.
_ "github.com/golang/mock/mockgen"
// Use gogoproto for protobuf generation.
_ "github.com/gogo/protobuf/gogoproto"
)
30 changes: 30 additions & 0 deletions hack/update-proto.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/usr/bin/env bash

set -o errexit
set -o nounset
set -o pipefail

SCRIPT_DIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
REPO_ROOT="$SCRIPT_DIR/.."
CODEGEN_PKG="${CODEGEN_PKG:-"$( (go mod download > /dev/null 2>&1) && go list -m -f '{{.Dir}}' k8s.io/code-generator)"}"

VGOPATH="$(mktemp -d)"
#trap 'rm -rf "$VGOPATH"' EXIT

# Setup virtual GOPATH so the codegen tools work as expected.
(
cd "$REPO_ROOT"
go run github.com/onmetal/vgopath "$VGOPATH"
)

export GOPATH="$VGOPATH"
export GO111MODULE=off

(
cd "$REPO_ROOT"
protoc \
--proto_path ./ori/apis/runtime/v1alpha1 \
--proto_path "$VGOPATH/src" \
--gogo_out=plugins=grpc:"$REPO_ROOT" \
./ori/apis/runtime/v1alpha1/api.proto
)
Loading

0 comments on commit b359256

Please sign in to comment.