Skip to content

Commit

Permalink
Implement UpgradeSuspensionWindow
Browse files Browse the repository at this point in the history
  • Loading branch information
bastjan committed Jun 20, 2024
1 parent 8db2971 commit c2173e8
Show file tree
Hide file tree
Showing 16 changed files with 833 additions and 17 deletions.
2 changes: 2 additions & 0 deletions api/v1beta1/upgradejob_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ const (
UpgradeJobReasonStarted = "Started"
// UpgradeJobReasonSucceeded is used when a step of the upgrade job did succeed
UpgradeJobReasonSucceeded = "Succeeded"
// UpgradeJobReasonSkipped is used when the upgrade job was skipped due to a suspension window
UpgradeJobReasonSkipped = "Skipped"
// UpgradeJobReasonCompleted is used when a step of the upgrade job did succeed
UpgradeJobReasonCompleted = "Completed"
// UpgradeJobReasonInProgress is used when the pre health check was done
Expand Down
1 change: 1 addition & 0 deletions api/v1beta1/upgradejobhook_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ var eventsInfluencingOutcome = []UpgradeEvent{
// UpgradeJobHookSpec defines the desired state of UpgradeJobHook
type UpgradeJobHookSpec struct {
// Events is the list of events to trigger the hook to be executed.
// Events should be idempotent and not assume any prior events have been executed.
// `Create`, `Start`, and `UpgradeComplete` are the events that influence the outcome of the upgrade.
// `Finish`, `Success`, and `Failure` do not influence the outcome of the upgrade,
// Job completion will not be checked, they are only used for informational purposes.
Expand Down
60 changes: 60 additions & 0 deletions api/v1beta1/upgradesuspensionwindow_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package v1beta1

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

// UpgradeSuspensionWindowSpec defines the desired state of UpgradeSuspensionWindow
type UpgradeSuspensionWindowSpec struct {
// Start is the time when the suspension window starts.
// +kubebuilder:validation:Required
// +required
Start metav1.Time `json:"start"`
// End is the time when the suspension window ends.
// +kubebuilder:validation:Required
// +required
End metav1.Time `json:"end"`
Reason string `json:"reason"`

// ConfigSelector is the selector for UpgradeConfigs to suspend upgrades for.
// An empty label selector matches all objects. A null label selector matches no objects.
// Matching UpgradeConfig objects won’t create UpgradeJob objects during the time window.
ConfigSelector *metav1.LabelSelector `json:"configSelector,omitempty"`
// JobSelector is the selector for UpgradeJobs to suspend upgrades for.
// An empty label selector matches all objects. A null label selector matches no objects.
// Matching UpgradeJob objects won’t start the upgrade during the time window.
// Skipped jobs will be marked as successful with reason skipped.
// Success and Finish hooks will be executed as normal.
// If the job was owned by a UpgradeConfig object, the object creates a new job with the current (possibly same) version in the next non-suspended time window.
// Already running jobs will be allowed to finish.
JobSelector *metav1.LabelSelector `json:"jobSelector,omitempty"`
}

// UpgradeSuspensionWindowStatus defines the observed state of UpgradeSuspensionWindow
type UpgradeSuspensionWindowStatus struct {
}

//+kubebuilder:object:root=true
//+kubebuilder:subresource:status

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

Spec UpgradeSuspensionWindowSpec `json:"spec,omitempty"`
Status UpgradeSuspensionWindowStatus `json:"status,omitempty"`
}

//+kubebuilder:object:root=true

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

func init() {
SchemeBuilder.Register(&UpgradeSuspensionWindow{}, &UpgradeSuspensionWindowList{})
}
101 changes: 101 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.

Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.15.0
name: upgradesuspensionwindows.managedupgrade.appuio.io
spec:
group: managedupgrade.appuio.io
names:
kind: UpgradeSuspensionWindow
listKind: UpgradeSuspensionWindowList
plural: upgradesuspensionwindows
singular: upgradesuspensionwindow
scope: Namespaced
versions:
- name: v1beta1
schema:
openAPIV3Schema:
description: UpgradeSuspensionWindow is the Schema for the upgradejobs API
properties:
apiVersion:
description: |-
APIVersion defines the versioned schema of this representation of an object.
Servers should convert recognized schemas to the latest internal value, and
may reject unrecognized values.
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources
type: string
kind:
description: |-
Kind is a string value representing the REST resource this object represents.
Servers may infer this from the endpoint the client submits requests to.
Cannot be updated.
In CamelCase.
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds
type: string
metadata:
type: object
spec:
description: UpgradeSuspensionWindowSpec defines the desired state of
UpgradeSuspensionWindow
properties:
configSelector:
description: |-
ConfigSelector is the selector for UpgradeConfigs to suspend upgrades for.
An empty label selector matches all objects. A null label selector matches no objects.
Matching UpgradeConfig objects won’t create UpgradeJob objects during the time window.
properties:
matchExpressions:
description: matchExpressions is a list of label selector requirements.
The requirements are ANDed.
items:
description: |-
A label selector requirement is a selector that contains values, a key, and an operator that
relates the key and values.
properties:
key:
description: key is the label key that the selector applies
to.
type: string
operator:
description: |-
operator represents a key's relationship to a set of values.
Valid operators are In, NotIn, Exists and DoesNotExist.
type: string
values:
description: |-
values is an array of string values. If the operator is In or NotIn,
the values array must be non-empty. If the operator is Exists or DoesNotExist,
the values array must be empty. This array is replaced during a strategic
merge patch.
items:
type: string
type: array
x-kubernetes-list-type: atomic
required:
- key
- operator
type: object
type: array
x-kubernetes-list-type: atomic
matchLabels:
additionalProperties:
type: string
description: |-
matchLabels is a map of {key,value} pairs. A single {key,value} in the matchLabels
map is equivalent to an element of matchExpressions, whose key field is "key", the
operator is "In", and the values array contains only "value". The requirements are ANDed.
type: object
type: object
x-kubernetes-map-type: atomic
end:
description: End is the time when the suspension window ends.
format: date-time
type: string
jobSelector:
description: |-
JobSelector is the selector for UpgradeJobs to suspend upgrades for.
An empty label selector matches all objects. A null label selector matches no objects.
Matching UpgradeJob objects won’t start the upgrade during the time window.
Skipped jobs will be marked as successful with reason skipped.
Success and Finish hooks will be executed as normal.
If the job was owned by a UpgradeConfig object, the object creates a new job with the current (possibly same) version in the next non-suspended time window.
Already running jobs will be allowed to finish.
properties:
matchExpressions:
description: matchExpressions is a list of label selector requirements.
The requirements are ANDed.
items:
description: |-
A label selector requirement is a selector that contains values, a key, and an operator that
relates the key and values.
properties:
key:
description: key is the label key that the selector applies
to.
type: string
operator:
description: |-
operator represents a key's relationship to a set of values.
Valid operators are In, NotIn, Exists and DoesNotExist.
type: string
values:
description: |-
values is an array of string values. If the operator is In or NotIn,
the values array must be non-empty. If the operator is Exists or DoesNotExist,
the values array must be empty. This array is replaced during a strategic
merge patch.
items:
type: string
type: array
x-kubernetes-list-type: atomic
required:
- key
- operator
type: object
type: array
x-kubernetes-list-type: atomic
matchLabels:
additionalProperties:
type: string
description: |-
matchLabels is a map of {key,value} pairs. A single {key,value} in the matchLabels
map is equivalent to an element of matchExpressions, whose key field is "key", the
operator is "In", and the values array contains only "value". The requirements are ANDed.
type: object
type: object
x-kubernetes-map-type: atomic
reason:
type: string
start:
description: Start is the time when the suspension window starts.
format: date-time
type: string
required:
- end
- reason
- start
type: object
status:
description: UpgradeSuspensionWindowStatus defines the observed state
of UpgradeSuspensionWindow
type: object
type: object
served: true
storage: true
subresources:
status: {}
3 changes: 3 additions & 0 deletions config/crd/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ resources:
- bases/managedupgrade.appuio.io_upgradejobs.yaml
- bases/managedupgrade.appuio.io_upgradeconfigs.yaml
- bases/managedupgrade.appuio.io_upgradejobhooks.yaml
- bases/managedupgrade.appuio.io_upgradesuspensionwindow.yaml
#+kubebuilder:scaffold:crdkustomizeresource

patchesStrategicMerge:
Expand All @@ -15,6 +16,7 @@ patchesStrategicMerge:
#- patches/webhook_in_upgradejobs.yaml
#- patches/webhook_in_upgradeconfigs.yaml
#- patches/webhook_in_upgradejobhooks.yaml
#- patches/webhook_in_upgradesuspensionwindows.yaml
#+kubebuilder:scaffold:crdkustomizewebhookpatch

# [CERTMANAGER] To enable cert-manager, uncomment all the sections with [CERTMANAGER] prefix.
Expand All @@ -23,6 +25,7 @@ patchesStrategicMerge:
#- patches/cainjection_in_upgradejobs.yaml
#- patches/cainjection_in_upgradeconfigs.yaml
#- patches/cainjection_in_upgradejobhooks.yaml
#- patches/cainjection_in_upgradesuspensionwindows.yaml
#+kubebuilder:scaffold:crdkustomizecainjectionpatch

# the following config is for teaching kustomize how to do kustomization for CRDs.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# The following patch adds a directive for certmanager to inject CA into the CRD
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
cert-manager.io/inject-ca-from: $(CERTIFICATE_NAMESPACE)/$(CERTIFICATE_NAME)
name: upgradesuspensionwindows.managedupgrade.appuio.io
Loading

0 comments on commit c2173e8

Please sign in to comment.