Skip to content

Commit 19b5a47

Browse files
authored
feat: add resume profiles (#47)
* feat: add resume profiles * feat: update chart and admission * refactory: remove file
1 parent 47a6da0 commit 19b5a47

28 files changed

+692
-52
lines changed

.-

Lines changed: 0 additions & 12 deletions
This file was deleted.

Makefile

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

4647
.PHONY: generate
4748
generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
@@ -118,6 +119,14 @@ deploy: manifests kustomize ## Deploy controller to the K8s cluster specified in
118119
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.
119120
$(KUSTOMIZE) build config/default | kubectl delete --ignore-not-found=$(ignore-not-found) -f -
120121

122+
CLUSTER=kind
123+
124+
.PHONY: kind-test
125+
kind-test: docker-build ## Deploy including test
126+
kind load docker-image ${IMG} --name ${CLUSTER}
127+
kubectl delete pods -n k8s-pause-system --all --force
128+
$(KUSTOMIZE) build config/default | kubectl --context kind-${CLUSTER} apply -f -
129+
121130
CONTROLLER_GEN = $(GOBIN)/controller-gen
122131
.PHONY: controller-gen
123132
controller-gen: ## Download controller-gen locally if necessary.

README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,35 @@ Resume:
2424
kubectl annotate ns/my-namespace k8s-pause/suspend=false --overwrite
2525
```
2626

27+
## Resume profiles
28+
29+
It is possible to define a set of pods which are allowed to start while a namespace is not paused.
30+
The active profile can be annotated on the namespace just like the suspend annotation.
31+
If no profile is defined all pods in the namespace are suspended if `k8s-pause/suspend=true` is set.
32+
33+
**Note**: The podSelector rules are or conditions. One ResumeProfile may match multiple pods by matchLabels or matchExpressions.
34+
```yaml
35+
apiVersion: pause.infra.doodle.com/v1beta1
36+
kind: ResumeProfile
37+
metadata:
38+
name: garden-services
39+
spec:
40+
podSelector:
41+
- matchLabels:
42+
app: garden
43+
service: backend
44+
- matchLabels:
45+
app: garden
46+
service: frontend
47+
- matchLabels:
48+
app: postgres
49+
```
50+
51+
Set resume profile:
52+
```
53+
kubectl annotate ns/my-namespace k8s-pause/profile=garden-services --overwrite
54+
```
55+
2756
## Details
2857

2958
The suspend flag on namespace level will affect only but any pods. It will not touch any resources besides pods.

api/v1beta1/doc.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
Copyright 2023 Doodle.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
// Package v1beta1 contains API Schema definitions for the pause.infra.doodle.com v1beta1 API group.
18+
// +kubebuilder:object:generate=true
19+
// +groupName=pause.infra.doodle.com
20+
package v1beta1

api/v1beta1/groupversion_info.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
Copyright 2023 Doodle.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
// Package v1beta1 contains API Schema definitions for the pause.infra.doodle.com v1beta1 API group
18+
// +kubebuilder:object:generate=true
19+
// +groupName=pause.infra.doodle.com
20+
package v1beta1
21+
22+
import (
23+
"k8s.io/apimachinery/pkg/runtime/schema"
24+
"sigs.k8s.io/controller-runtime/pkg/scheme"
25+
)
26+
27+
var (
28+
// GroupVersion is group version used to register these objects
29+
GroupVersion = schema.GroupVersion{Group: "pause.infra.doodle.com", Version: "v1beta1"}
30+
31+
// SchemeBuilder is used to add go types to the GroupVersionKind scheme
32+
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion}
33+
34+
// AddToScheme adds the types in this group-version to the given scheme.
35+
AddToScheme = SchemeBuilder.AddToScheme
36+
)

api/v1beta1/patchrule_types.go

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
Copyright 2023 Doodle.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package v1beta1
18+
19+
import (
20+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
21+
)
22+
23+
// ResumeProfileSpec defines the desired state of ResumeProfile
24+
type ResumeProfileSpec struct {
25+
// Prometheus holds information about where to find prometheus
26+
// +required
27+
PodSelector []metav1.LabelSelector `json:"podSelector"`
28+
}
29+
30+
// +kubebuilder:object:root=true
31+
// +kubebuilder:subresource:status
32+
// +kubebuilder:printcolumn:name="Active",type="string",JSONPath=".status.conditions[?(@.type==\"Active\")].status",description=""
33+
// +kubebuilder:printcolumn:name="Reason",type="string",JSONPath=".status.conditions[?(@.type==\"Active\")].reason",description=""
34+
// +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp",description=""
35+
36+
// ResumeProfile is the Schema for the patchrules API
37+
type ResumeProfile struct {
38+
metav1.TypeMeta `json:",inline"`
39+
metav1.ObjectMeta `json:"metadata,omitempty"`
40+
41+
Spec ResumeProfileSpec `json:"spec,omitempty"`
42+
}
43+
44+
//+kubebuilder:object:root=true
45+
46+
// ResumeProfileList contains a list of ResumeProfile
47+
type ResumeProfileList struct {
48+
metav1.TypeMeta `json:",inline"`
49+
metav1.ListMeta `json:"metadata,omitempty"`
50+
Items []ResumeProfile `json:"items"`
51+
}
52+
53+
func init() {
54+
SchemeBuilder.Register(&ResumeProfile{}, &ResumeProfileList{})
55+
}

api/v1beta1/zz_generated.deepcopy.go

Lines changed: 107 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

chart/k8s-pause/Chart.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ keywords:
1414
name: k8s-pause
1515
sources:
1616
- https://github.com/DoodleScheduling/k8s-pause
17-
version: 0.2.2
17+
version: 0.2.3

0 commit comments

Comments
 (0)