Skip to content

Commit

Permalink
Merge pull request #1 from appuio/initial-impl
Browse files Browse the repository at this point in the history
Initial implementation
  • Loading branch information
bastjan authored Aug 31, 2022
2 parents 2dabf8c + d576756 commit 0dc4c5a
Show file tree
Hide file tree
Showing 35 changed files with 9,007 additions and 70 deletions.
27 changes: 27 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# This is an example .goreleaser.yml file with some sensible defaults.
# Make sure to check the documentation at https://goreleaser.com
builds:
- env:
- CGO_ENABLED=0
goos:
- linux
- darwin
goarch:
- amd64
- arm64
checksum:
name_template: 'checksums.txt'
snapshot:
name_template: "{{ .Tag }}-next"
dockers:
- image_templates:
- "quay.io/appuio/scheduler-canary-controller:v{{ .Version }}"

# For prereleases, updating `latest` and the floating tags of the major
# version does not make sense. Only the image for the exact version should
# be pushed.
- "{{ if not .Prerelease }}quay.io/appuio/scheduler-canary-controller:latest{{ end }}"

- "{{ if .Prerelease }}quay.io/appuio/scheduler-canary-controller:next{{ end }}"
release:
prerelease: auto
24 changes: 2 additions & 22 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,27 +1,7 @@
# Build the manager binary
FROM golang:1.18 as builder

WORKDIR /workspace
# Copy the Go Modules manifests
COPY go.mod go.mod
COPY go.sum go.sum
# cache deps before building and copying source so that we don't need to re-download as much
# and so that source changes don't invalidate our downloaded layer
RUN go mod download

# Copy the go source
COPY main.go main.go
COPY api/ api/
COPY controllers/ controllers/

# Build
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -o manager main.go

# Use distroless as minimal base image to package the manager binary
# Refer to https://github.com/GoogleContainerTools/distroless for more details
FROM gcr.io/distroless/static:nonroot

WORKDIR /
COPY --from=builder /workspace/manager .
COPY scheduler-canary-controller manager
USER 65532:65532

ENTRYPOINT ["/manager"]
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
ENVTEST ?= $(LOCALBIN)/setup-envtest

## Tool Versions
KUSTOMIZE_VERSION ?= v3.8.7
KUSTOMIZE_VERSION ?= v4.5.7
CONTROLLER_TOOLS_VERSION ?= v0.9.2

KUSTOMIZE_INSTALL_SCRIPT ?= "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh"
Expand Down
3 changes: 3 additions & 0 deletions PROJECT
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,7 @@ resources:
kind: SchedulerCanary
path: github.com/appuio/scheduler-canary-controller/api/v1beta1
version: v1beta1
- controller: true
kind: Pod
version: v1
version: "3"
15 changes: 11 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
# scheduler-canary
// TODO(user): Add simple overview of use/purpose
# scheduler-canary-controller

Runs canary pods and measures state changes in their lifecycle.

## Description
// TODO(user): An in-depth paragraph about your project and overview of use

`scheduler-canary-controller` is a Kubernetes controller that runs canary pods and measures state changes in their lifecycle.

Canary pods can be created using the `monitoring.appuio.io.SchedulerCanary` custom resource. See [samples](https://github.com/appuio/scheduler-canary-controller/tree/HEAD/config/samples) for more information.

The canary pods are then tracked by the controller and the results are reported in the [`scheduler_canary_pod_.+` metrics](https://github.com/appuio/scheduler-canary-controller/blob/HEAD/controllers/metrics.go).

## Getting Started
You’ll need a Kubernetes cluster to run against. You can use [KIND](https://sigs.k8s.io/kind) to get a local cluster for testing, or run against a remote cluster.
Expand Down Expand Up @@ -42,7 +48,8 @@ make undeploy
```

## Contributing
// TODO(user): Add detailed information on how you would like others to contribute to this project

Submit Pull Requests at https://github.com/appuio/scheduler-canary-controller/pulls.

### How it works
This project aims to follow the Kubernetes [Operator pattern](https://kubernetes.io/docs/concepts/extend-kubernetes/operator/)
Expand Down
38 changes: 36 additions & 2 deletions api/v1beta1/schedulercanary_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ limitations under the License.
package v1beta1

import (
"time"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

corev1 "k8s.io/api/core/v1"
)

// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
Expand All @@ -28,18 +32,48 @@ type SchedulerCanarySpec struct {
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
// Important: Run "make" to regenerate code after modifying this file

// Foo is an example field of SchedulerCanary. Edit schedulercanary_types.go to remove/update
Foo string `json:"foo,omitempty"`
// MaxPodCompletionTimeout is the maximum amount of time to wait for a pod to complete.
// After the timeout expires, the pod will be deleted, the canary will be marked as failed, and a new canary will be created.
// The default is 15 minutes.
MaxPodCompletionTimeout metav1.Duration `json:"maxPodCompletionTimeout,omitempty"`

// Interval is the interval at which a canary pod will be created.
// The interval is not very precise.
// The default is 1 minute.
Interval metav1.Duration `json:"interval,omitempty"`

// PodTemplate is the pod template to use for the canary pods.
PodTemplate corev1.PodTemplateSpec `json:"podTemplate,omitempty"`
}

func (s SchedulerCanarySpec) MaxPodCompletionTimeoutWithDefault() time.Duration {
d := s.MaxPodCompletionTimeout.Duration
if d == 0 {
return 15 * time.Minute
}
return d
}

func (s SchedulerCanarySpec) IntervalWithDefault() time.Duration {
d := s.Interval.Duration
if d == 0 {
return time.Minute
}
return d
}

// SchedulerCanaryStatus defines the observed state of SchedulerCanary
type SchedulerCanaryStatus struct {
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
// Important: Run "make" to regenerate code after modifying this file

// LastCanaryCreatedAt is the timestamp of the last canary creation.
LastCanaryCreatedAt metav1.Time `json:"lastCanaryCreatedAt,omitempty"`
}

//+kubebuilder:object:root=true
//+kubebuilder:subresource:status
//+kubebuilder:printcolumn:name="LASTEXEC",type="string",JSONPath=`.status.lastCanaryCreatedAt`

// SchedulerCanary is the Schema for the schedulercanaries API
type SchedulerCanary struct {
Expand Down
8 changes: 6 additions & 2 deletions api/v1beta1/zz_generated.deepcopy.go

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

Loading

0 comments on commit 0dc4c5a

Please sign in to comment.