Skip to content

Commit

Permalink
Upgrade turndownschedules CRD to apiextensions v1
Browse files Browse the repository at this point in the history
apiextensions.k8s.io/v1beta1 is removed as of K8s v1.22 [1], so all CRDs
have to be updated to apiextensions.k8s.io/v1. This commit does the
upgrade for the turndownschedule CRD.

As part of the API updates, K8s is enforcing things grouped under
*.k8s.io to be approved [2] because they are actually supposed to be
Kuberenetes community-managed APIs [3]. So this commit also changes the
CRD from:

turndownschedules.kubecost.k8s.io
to
turndownschedules.kubecost.com

This is in-line with K8s rules and links to our main domain.

Tested by applying cluster-turndown-full.yaml and example-schedule.yaml
successfully.

[1] https://cloud.google.com/kubernetes-engine/docs/deprecations/apis-1-22
[2] kubernetes/enhancements#1111
[3] kubernetes/enhancements#1111 (comment)
  • Loading branch information
michaelmdresser committed May 27, 2022
1 parent d83d9eb commit 4b898df
Show file tree
Hide file tree
Showing 10 changed files with 89 additions and 82 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,12 @@ $ kubectl get pods -l app=cluster-turndown -n turndown
Cluster Turndown uses a Kubernetes Custom Resource Definition to create schedules. There is an example resource located at `artifacts/example-schedule.yaml`:

```yaml
apiVersion: kubecost.k8s.io/v1alpha1
apiVersion: kubecost.com/v1alpha1
kind: TurndownSchedule
metadata:
name: example-schedule
finalizers:
- "finalizer.kubecost.k8s.io"
- "finalizer.kubecost.com"
spec:
start: 2020-03-12T00:00:00Z
end: 2020-03-12T12:00:00Z
Expand Down Expand Up @@ -201,19 +201,19 @@ Details regarding the status of the turndown schedule can be found by outputting
```bash
$ kubectl get tds example-schedule -o yaml
apiVersion: kubecost.k8s.io/v1alpha1
apiVersion: kubecost.com/v1alpha1
kind: TurndownSchedule
metadata:
annotations:
kubectl.kubernetes.io/last-applied-configuration: |
{"apiVersion":"kubecost.k8s.io/v1alpha1","kind":"TurndownSchedule","metadata":{"annotations":{},"finalizers":["finalizer.kubecost.k8s.io"],"name":"example-schedule"},"spec":{"end":"2020-03-17T00:35:00Z","repeat":"daily","start":"2020-03-17T00:20:00Z"}}
{"apiVersion":"kubecost.com/v1alpha1","kind":"TurndownSchedule","metadata":{"annotations":{},"finalizers":["finalizer.kubecost.com"],"name":"example-schedule"},"spec":{"end":"2020-03-17T00:35:00Z","repeat":"daily","start":"2020-03-17T00:20:00Z"}}
creationTimestamp: "2020-03-17T00:18:39Z"
finalizers:
- finalizer.kubecost.k8s.io
- finalizer.kubecost.com
generation: 1
name: example-schedule
resourceVersion: "33573"
selfLink: /apis/kubecost.k8s.io/v1alpha1/turndownschedules/example-schedule
selfLink: /apis/kubecost.com/v1alpha1/turndownschedules/example-schedule
uid: d9b16aed-67e4-11ea-b591-42010a8e0075
spec:
end: "2020-03-17T00:35:00Z"
Expand Down
70 changes: 37 additions & 33 deletions artifacts/cluster-turndown-full.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ metadata:
app: cluster-turndown
rules:
- apiGroups:
- kubecost.k8s.io
- kubecost.com
resources:
- turndownschedules
- turndownschedules/status
Expand Down Expand Up @@ -204,13 +204,12 @@ spec:
secretName: cluster-turndown-service-key
---
# TurndownSchedule Custom Resource Definition for persistence
apiVersion: apiextensions.k8s.io/v1beta1
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
name: turndownschedules.kubecost.k8s.io
name: turndownschedules.kubecost.com
spec:
group: kubecost.k8s.io
version: v1alpha1
group: kubecost.com
names:
kind: TurndownSchedule
singular: turndownschedule
Expand All @@ -219,33 +218,38 @@ spec:
- td
- tds
scope: Cluster
subresources:
status: {}
validation:
openAPIV3Schema:
properties:
spec:
versions:
- name: v1alpha1
served: true
storage: true
subresources:
status: {}
schema:
openAPIV3Schema:
type: object
properties:
start:
type: string
format: date-time
end:
type: string
format: date-time
repeat:
type: string
enum: [none, daily, weekly]
additionalPrinterColumns:
- name: State
type: string
description: The state of the turndownschedule
JSONPath: .status.state
- name: Next Turndown
type: string
description: The next turndown date-time
JSONPath: .status.nextScaleDownTime
- name: Next Turn Up
type: string
description: The next turn up date-time
JSONPath: .status.nextScaleUpTime
spec:
type: object
properties:
start:
type: string
format: date-time
end:
type: string
format: date-time
repeat:
type: string
enum: [none, daily, weekly]
additionalPrinterColumns:
- name: State
type: string
description: The state of the turndownschedule
jsonPath: .status.state
- name: Next Turndown
type: string
description: The next turndown date-time
jsonPath: .status.nextScaleDownTime
- name: Next Turn Up
type: string
description: The next turn up date-time
jsonPath: .status.nextScaleUpTime
6 changes: 3 additions & 3 deletions artifacts/example-schedule.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
apiVersion: kubecost.k8s.io/v1alpha1
apiVersion: kubecost.com/v1alpha1
kind: TurndownSchedule
metadata:
name: example-schedule
finalizers:
- "finalizer.kubecost.k8s.io"
- "finalizer.kubecost.com"
spec:
start: 2020-03-12T00:00:00Z
end: 2020-03-12T12:00:00Z
repeat: daily
repeat: daily
69 changes: 36 additions & 33 deletions artifacts/turndown-schedule-definition.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
apiVersion: apiextensions.k8s.io/v1beta1
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
name: turndownschedules.kubecost.k8s.io
name: turndownschedules.kubecost.com
spec:
group: kubecost.k8s.io
version: v1alpha1
group: kubecost.com
names:
kind: TurndownSchedule
singular: turndownschedule
Expand All @@ -13,34 +12,38 @@ spec:
- td
- tds
scope: Cluster
subresources:
status: {}
validation:
openAPIV3Schema:
type: object
properties:
spec:
versions:
- name: v1alpha1
served: true
storage: true
subresources:
status: {}
schema:
openAPIV3Schema:
type: object
properties:
start:
type: string
format: date-time
end:
type: string
format: date-time
repeat:
type: string
enum: [none, daily, weekly]
additionalPrinterColumns:
- name: State
type: string
description: The state of the turndownschedule
JSONPath: .status.state
- name: Next Turndown
type: string
description: The next turndown date-time
JSONPath: .status.nextScaleDownTime
- name: Next Turn Up
type: string
description: The next turn up date-time
JSONPath: .status.nextScaleUpTime
spec:
type: object
properties:
start:
type: string
format: date-time
end:
type: string
format: date-time
repeat:
type: string
enum: [none, daily, weekly]
additionalPrinterColumns:
- name: State
type: string
description: The state of the turndownschedule
jsonPath: .status.state
- name: Next Turndown
type: string
description: The next turndown date-time
jsonPath: .status.nextScaleDownTime
- name: Next Turn Up
type: string
description: The next turn up date-time
jsonPath: .status.nextScaleUpTime
2 changes: 1 addition & 1 deletion pkg/apis/turndownschedule/register.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package turndownschedule

const (
GroupName = "kubecost.k8s.io"
GroupName = "kubecost.com"
)
2 changes: 1 addition & 1 deletion pkg/apis/turndownschedule/v1alpha1/doc.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// +k8s:deepcopy-gen=package,register
// +k8s:defaulter-gen=TypeMeta
// +k8s:openapi-gen=true
// +groupName=kubecost.k8s.io
// +groupName=kubecost.com

// Package v1alpha1 is the v1alpha1 version of the API.
package v1alpha1

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

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

2 changes: 1 addition & 1 deletion pkg/generated/informers/externalversions/generic.go

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

2 changes: 1 addition & 1 deletion pkg/turndown/schedulecontroller.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const (
// due to an existing turndown schedule.
ErrAlreadyScheduled = "ErrAlreadyScheduled"

TurndownScheduleFinalizer = "finalizer.kubecost.k8s.io"
TurndownScheduleFinalizer = "finalizer.kubecost.com"

ScheduleStateSuccess = "ScheduleSuccess"
ScheduleStateFailed = "ScheduleFailed"
Expand Down

0 comments on commit 4b898df

Please sign in to comment.