Skip to content

Commit

Permalink
feat: garm runners will be reflected into kubernetes as runner resour…
Browse files Browse the repository at this point in the history
…ce (#23)

with 
```bash
$ kubectl get runner
```
one can now list and with 

```bash
$ kubectl delete runner my-garm-runner
```
one can delete a runner from within a cluster.
Also, if accidently a runner get deleted via cli from within the
garm-server itself, der controller cleans up not matching runner CRs in
k8s

Todo:
- [x] implement tests

---------

Signed-off-by: Mario Constanti <mario.constanti@mercedes-benz.com>
Co-authored-by: Mario Constanti <mario.constanti@mercedes-benz.com>
Co-authored-by: Mario Constanti <github@constanti.de>
  • Loading branch information
3 people committed Dec 11, 2023
1 parent c9c5840 commit 94cf503
Show file tree
Hide file tree
Showing 28 changed files with 1,443 additions and 72 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ GOVULNCHECK ?= $(LOCALBIN)/govulncheck
## Tool Versions
KUSTOMIZE_VERSION ?= v5.0.1
CONTROLLER_TOOLS_VERSION ?= v0.12.0
GOLANGCI_LINT_VERSION ?= v1.53.3
GOLANGCI_LINT_VERSION ?= v1.55.2
MOCKGEN_VERSION ?= v0.2.0
GORELEASER_VERSION ?= v1.21.0
MDTOC_VERSION ?= v1.1.0
Expand Down
9 changes: 9 additions & 0 deletions PROJECT
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,13 @@ resources:
defaulting: true
validation: true
webhookVersion: v1
- api:
crdVersion: v1
namespaced: true
controller: true
domain: mercedes-benz.com
group: garm-operator
kind: Runner
path: github.com/mercedes-benz/garm-operator/api/v1alpha1
version: v1alpha1
version: "3"
1 change: 1 addition & 0 deletions Tiltfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ k8s_resource(
'images.garm-operator.mercedes-benz.com:customresourcedefinition',
'organizations.garm-operator.mercedes-benz.com:customresourcedefinition',
'pools.garm-operator.mercedes-benz.com:customresourcedefinition',
'runners.garm-operator.mercedes-benz.com:customresourcedefinition',
'repositories.garm-operator.mercedes-benz.com:customresourcedefinition',
'garm-operator-controller-manager:serviceaccount',
'garm-operator-leader-election-role:role',
Expand Down
6 changes: 6 additions & 0 deletions api/v1alpha1/pool_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,12 @@ func MatchesGitHubScope(name, kind string) Predicate {
}
}

func MatchesID(id string) Predicate {
return func(p Pool) bool {
return p.Status.ID == id
}
}

func (p *PoolList) FilterByFields(predicates ...Predicate) {
var filteredItems []Pool

Expand Down
108 changes: 108 additions & 0 deletions api/v1alpha1/runner_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
// SPDX-License-Identifier: MIT

package v1alpha1

import (
commonParams "github.com/cloudbase/garm-provider-common/params"
"github.com/cloudbase/garm/params"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.

// RunnerSpec defines the desired state of Runner
type RunnerSpec struct{}

// RunnerStatus defines the observed state of Runner
type RunnerStatus struct {
// ID is the database ID of this instance.
ID string `json:"id,omitempty"`

// PeoviderID is the unique ID the provider associated
// with the compute instance. We use this to identify the
// instance in the provider.
ProviderID string `json:"providerId,omitempty"`

// AgentID is the github runner agent ID.
AgentID int64 `json:"agentId"`

// Name is the name associated with an instance. Depending on
// the provider, this may or may not be useful in the context of
// the provider, but we can use it internally to identify the
// instance.
Name string `json:"name,omitempty"`

// OSType is the operating system type. For now, only Linux and
// Windows are supported.
OSType commonParams.OSType `json:"osType,omitempty"`

// OSName is the name of the OS. Eg: ubuntu, centos, etc.
OSName string `json:"osName,omitempty"`

// OSVersion is the version of the operating system.
OSVersion string `json:"osVersion,omitempty"`

// OSArch is the operating system architecture.
OSArch commonParams.OSArch `json:"osArch,omitempty"`

// Addresses is a list of IP addresses the provider reports
// for this instance.
Addresses []commonParams.Address `json:"addresses,omitempty"`

// Status is the status of the instance inside the provider (eg: running, stopped, etc)
Status commonParams.InstanceStatus `json:"status,omitempty"`

// RunnerStatus is the github runner status as it appears on GitHub.
InstanceStatus params.RunnerStatus `json:"instanceStatus,omitempty"`

// PoolID is the ID of the garm pool to which a runner belongs.
PoolID string `json:"poolId,omitempty"`

// ProviderFault holds any error messages captured from the IaaS provider that is
// responsible for managing the lifecycle of the runner.
ProviderFault string `json:"providerFault,omitempty"`

// StatusMessages is a list of status messages sent back by the runner as it sets itself
// up.

//// UpdatedAt is the timestamp of the last update to this runner.
// UpdatedAt time.Time `json:"updated_at"`

// GithubRunnerGroup is the github runner group to which the runner belongs.
// The runner group must be created by someone with access to the enterprise.
GitHubRunnerGroup string `json:"githubRunnerGroup"`
}

//+kubebuilder:object:root=true
//+kubebuilder:resource:path=runners,scope=Namespaced,categories=garm,shortName=run
//+kubebuilder:subresource:status
//+kubebuilder:printcolumn:name="ID",type="string",JSONPath=".status.id",description="Runner ID"
//+kubebuilder:printcolumn:name="Pool",type="string",JSONPath=".status.poolId",description="Pool CR Name"
//+kubebuilder:printcolumn:name="Garm Runner Status",type="string",JSONPath=".status.status",description="Garm Runner Status"
//+kubebuilder:printcolumn:name="Provider Runner Status",type="string",JSONPath=".status.instanceStatus",description="Provider Runner Status"
//+kubebuilder:printcolumn:name="Provider ID",type="string",JSONPath=".status.providerId",description="Provider ID",priority=1
//+kubebuilder:printcolumn:name="Agent ID",type="string",JSONPath=".status.agentId",description="Agent ID",priority=1
//+kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp"

// Runner is the Schema for the runners API
type Runner struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec RunnerSpec `json:"spec,omitempty"`
Status RunnerStatus `json:"status,omitempty"`
}

//+kubebuilder:object:root=true

// RunnerList contains a list of Runner
type RunnerList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []Runner `json:"items"`
}

func init() {
SchemeBuilder.Register(&Runner{}, &RunnerList{})
}
95 changes: 95 additions & 0 deletions api/v1alpha1/zz_generated.deepcopy.go

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

0 comments on commit 94cf503

Please sign in to comment.