Skip to content

Commit

Permalink
feat: add resume profiles (#47)
Browse files Browse the repository at this point in the history
* feat: add resume profiles

* feat: update chart and admission

* refactory: remove file
  • Loading branch information
raffis committed May 5, 2023
1 parent 47a6da0 commit 19b5a47
Show file tree
Hide file tree
Showing 28 changed files with 692 additions and 52 deletions.
12 changes: 0 additions & 12 deletions .-

This file was deleted.

9 changes: 9 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ help: ## Display this help.
.PHONY: manifests
manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
$(CONTROLLER_GEN) rbac:roleName=manager-role crd webhook paths="./..." output:crd:artifacts:config=config/base/crd/bases
cp config/base/crd/bases/* chart/k8s-pause/crds/

.PHONY: generate
generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
Expand Down Expand Up @@ -118,6 +119,14 @@ deploy: manifests kustomize ## Deploy controller to the K8s cluster specified in
undeploy: ## Undeploy controller from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
$(KUSTOMIZE) build config/default | kubectl delete --ignore-not-found=$(ignore-not-found) -f -

CLUSTER=kind

.PHONY: kind-test
kind-test: docker-build ## Deploy including test
kind load docker-image ${IMG} --name ${CLUSTER}
kubectl delete pods -n k8s-pause-system --all --force
$(KUSTOMIZE) build config/default | kubectl --context kind-${CLUSTER} apply -f -

CONTROLLER_GEN = $(GOBIN)/controller-gen
.PHONY: controller-gen
controller-gen: ## Download controller-gen locally if necessary.
Expand Down
29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,35 @@ Resume:
kubectl annotate ns/my-namespace k8s-pause/suspend=false --overwrite
```

## Resume profiles

It is possible to define a set of pods which are allowed to start while a namespace is not paused.
The active profile can be annotated on the namespace just like the suspend annotation.
If no profile is defined all pods in the namespace are suspended if `k8s-pause/suspend=true` is set.

**Note**: The podSelector rules are or conditions. One ResumeProfile may match multiple pods by matchLabels or matchExpressions.
```yaml
apiVersion: pause.infra.doodle.com/v1beta1
kind: ResumeProfile
metadata:
name: garden-services
spec:
podSelector:
- matchLabels:
app: garden
service: backend
- matchLabels:
app: garden
service: frontend
- matchLabels:
app: postgres
```

Set resume profile:
```
kubectl annotate ns/my-namespace k8s-pause/profile=garden-services --overwrite
```

## Details

The suspend flag on namespace level will affect only but any pods. It will not touch any resources besides pods.
Expand Down
20 changes: 20 additions & 0 deletions api/v1beta1/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
Copyright 2023 Doodle.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

// Package v1beta1 contains API Schema definitions for the pause.infra.doodle.com v1beta1 API group.
// +kubebuilder:object:generate=true
// +groupName=pause.infra.doodle.com
package v1beta1
36 changes: 36 additions & 0 deletions api/v1beta1/groupversion_info.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
Copyright 2023 Doodle.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

// Package v1beta1 contains API Schema definitions for the pause.infra.doodle.com v1beta1 API group
// +kubebuilder:object:generate=true
// +groupName=pause.infra.doodle.com
package v1beta1

import (
"k8s.io/apimachinery/pkg/runtime/schema"
"sigs.k8s.io/controller-runtime/pkg/scheme"
)

var (
// GroupVersion is group version used to register these objects
GroupVersion = schema.GroupVersion{Group: "pause.infra.doodle.com", Version: "v1beta1"}

// SchemeBuilder is used to add go types to the GroupVersionKind scheme
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion}

// AddToScheme adds the types in this group-version to the given scheme.
AddToScheme = SchemeBuilder.AddToScheme
)
55 changes: 55 additions & 0 deletions api/v1beta1/patchrule_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
Copyright 2023 Doodle.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package v1beta1

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// ResumeProfileSpec defines the desired state of ResumeProfile
type ResumeProfileSpec struct {
// Prometheus holds information about where to find prometheus
// +required
PodSelector []metav1.LabelSelector `json:"podSelector"`
}

// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
// +kubebuilder:printcolumn:name="Active",type="string",JSONPath=".status.conditions[?(@.type==\"Active\")].status",description=""
// +kubebuilder:printcolumn:name="Reason",type="string",JSONPath=".status.conditions[?(@.type==\"Active\")].reason",description=""
// +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp",description=""

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

Spec ResumeProfileSpec `json:"spec,omitempty"`
}

//+kubebuilder:object:root=true

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

func init() {
SchemeBuilder.Register(&ResumeProfile{}, &ResumeProfileList{})
}
107 changes: 107 additions & 0 deletions api/v1beta1/zz_generated.deepcopy.go

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

2 changes: 1 addition & 1 deletion chart/k8s-pause/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ keywords:
name: k8s-pause
sources:
- https://github.com/DoodleScheduling/k8s-pause
version: 0.2.2
version: 0.2.3

0 comments on commit 19b5a47

Please sign in to comment.