Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce ManagedOSChangelog resource #891

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
199 changes: 199 additions & 0 deletions .obs/chartfile/elemental-operator-crds-helm/templates/crds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1140,6 +1140,205 @@ spec:
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
app.kubernetes.io/instance: '{{ .Release.Name }}'
app.kubernetes.io/part-of: Elemental Operator
app.kubernetes.io/version: '{{ .Chart.Version }}'
controller-gen.kubebuilder.io/version: v0.14.0
labels:
cluster.x-k8s.io/provider: infrastructure-elemental
cluster.x-k8s.io/v1beta1: v1beta1
release-name: '{{ .Release.Name }}'
name: managedoschangelogs.elemental.cattle.io
spec:
group: elemental.cattle.io
names:
kind: ManagedOSChangelog
listKind: ManagedOSChangelogList
plural: managedoschangelogs
singular: managedoschangelog
scope: Namespaced
versions:
- name: v1beta1
schema:
openAPIV3Schema:
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:
properties:
channelRef:
description: ManagedOSVersionChannelRef a referemce to the related
ManagedOSVersionChannel.
properties:
apiVersion:
description: API version of the referent.
type: string
fieldPath:
description: |-
If referring to a piece of an object instead of an entire object, this string
should contain a valid JSON/Go field access statement, such as desiredState.manifest.containers[2].
For example, if the object reference is to a container within a pod, this would take on a value like:
"spec.containers{name}" (where "name" refers to the name of the container that triggered
the event) or if no container name is specified "spec.containers[2]" (container with
index 2 in this pod). This syntax is chosen only to have some well-defined way of
referencing a part of an object.
TODO: this design is not final and this field is subject to change in the future.
type: string
kind:
description: |-
Kind of the referent.
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds
type: string
name:
description: |-
Name of the referent.
More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
type: string
namespace:
description: |-
Namespace of the referent.
More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/namespaces/
type: string
resourceVersion:
description: |-
Specific resourceVersion to which this reference is made, if any.
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#concurrency-control-and-consistency
type: string
uid:
description: |-
UID of the referent.
More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#uids
type: string
type: object
x-kubernetes-map-type: atomic
cleanupAfterMinutes:
default: 60
description: |-
LifetimeMinutes the time at which the changelog data will be cleaned up.
Default is 60 minutes, set to 0 to disable.
format: int32
type: integer
osVersion:
description: |-
ManagedOSVersion the name of the ManagedOSVersion resource for which the changelog
should be generated.
type: string
refresh:
description: Refresh triggers to build again a cleaned up changelog.
type: boolean
required:
- channelRef
type: object
status:
properties:
changelogURL:
description: ChangelogURL the URL where changelog data can be displayed
type: string
conditions:
description: Conditions describe the state of the changelog object.
items:
description: "Condition contains details for one aspect of the current
state of this API Resource.\n---\nThis struct is intended for
direct use as an array at the field path .status.conditions. For
example,\n\n\n\ttype FooStatus struct{\n\t // Represents the
observations of a foo's current state.\n\t // Known .status.conditions.type
are: \"Available\", \"Progressing\", and \"Degraded\"\n\t //
+patchMergeKey=type\n\t // +patchStrategy=merge\n\t // +listType=map\n\t
\ // +listMapKey=type\n\t Conditions []metav1.Condition `json:\"conditions,omitempty\"
patchStrategy:\"merge\" patchMergeKey:\"type\" protobuf:\"bytes,1,rep,name=conditions\"`\n\n\n\t
\ // other fields\n\t}"
properties:
lastTransitionTime:
description: |-
lastTransitionTime is the last time the condition transitioned from one status to another.
This should be when the underlying condition changed. If that is not known, then using the time when the API field changed is acceptable.
format: date-time
type: string
message:
description: |-
message is a human readable message indicating details about the transition.
This may be an empty string.
maxLength: 32768
type: string
observedGeneration:
description: |-
observedGeneration represents the .metadata.generation that the condition was set based upon.
For instance, if .metadata.generation is currently 12, but the .status.conditions[x].observedGeneration is 9, the condition is out of date
with respect to the current state of the instance.
format: int64
minimum: 0
type: integer
reason:
description: |-
reason contains a programmatic identifier indicating the reason for the condition's last transition.
Producers of specific condition types may define expected values and meanings for this field,
and whether the values are considered a guaranteed API.
The value should be a CamelCase string.
This field may not be empty.
maxLength: 1024
minLength: 1
pattern: ^[A-Za-z]([A-Za-z0-9_,:]*[A-Za-z0-9_])?$
type: string
status:
description: status of the condition, one of True, False, Unknown.
enum:
- "True"
- "False"
- Unknown
type: string
type:
description: |-
type of condition in CamelCase or in foo.example.com/CamelCase.
---
Many .condition.type values are consistent across resources like Available, but because arbitrary conditions can be
useful (see .node.status.conditions), the ability to deconflict is important.
The regex it matches is (dns1123SubdomainFmt/)?(qualifiedNameFmt)
maxLength: 316
pattern: ^([a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*/)?(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])$
type: string
required:
- lastTransitionTime
- message
- reason
- status
- type
type: object
type: array
state:
description: State reflect the state of the changelog generation process.
enum:
- Initialized
- Started
- Completed
- Failed
- NotStarted
type: string
type: object
type: object
served: true
storage: true
subresources:
status: {}
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
app.kubernetes.io/instance: '{{ .Release.Name }}'
Expand Down
26 changes: 26 additions & 0 deletions .obs/chartfile/elemental-operator-helm/templates/rbac.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,32 @@ rules:
- get
- patch
- update
- apiGroups:
- elemental.cattle.io
resources:
- managedoschangelogs
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- elemental.cattle.io
resources:
- managedoschangelogs/finalizers
verbs:
- update
- apiGroups:
- elemental.cattle.io
resources:
- managedoschangelogs/status
verbs:
- get
- patch
- update
- apiGroups:
- elemental.cattle.io
resources:
Expand Down
19 changes: 19 additions & 0 deletions api/v1beta1/condition_consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,25 @@ const (
ResourcesSuccessfullyCreatedReason = "ResourcesSuccessfullyCreated"
)

// Managed OS Changelog conditions
const (
// WorkerPodReadyCondition is the condition type tracking the state of the worked pod.
WorkerPodReadyCondition = "WorkerPodReady"
// WorkerPodNotStartedReason documents worker pod not being started.
WorkerPodNotStartedReason = "WorkerPodNotStarted"
// WorkerPodInitializing documents worker pod being initialized.
WorkerPodInitReason = "WorkerPodInitializing"
// WorkerPodCompletionFailureReason documents failure to successfully complete the worker pod tasks.
WorkerPodCompletionFailureReason = "WorkerPodCompletionFailure"
// WorkerPodCompletionSuccessReason documents worker pod completed its tasks and is successfully running.
WorkerPodCompletionSuccessReason = "WorkerPodCompletionSuccess"
// WorkerPodDeadline documents worker pod deadline has elapsed.
WorkerPodDeadline = "WorkerPodDeadline"
// WorkerPodUnknown documents worker pod in an unknown status.
WorkerPodUnknown = "WorkerPodUnknown"
)

// Seed Image conditions
const (
// SeedImageConditionReady is the condition type tracking the state of the seed image build pod.
SeedImageConditionReady = "SeedImageReady"
Expand Down
89 changes: 89 additions & 0 deletions api/v1beta1/managedoschangelog_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/*
Copyright © 2022 - 2024 SUSE LLC

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 (
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

const (
ManagedOSChangelogFinalizer = "managedoschangelog.elemental.cattle.io"
)

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

type ManagedOSChangelog struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec ManagedOSChangelogSpec `json:"spec,omitempty"`
Status ManagedOSChangelogStatus `json:"status,omitempty"`
}

type ManagedOSChangelogSpec struct {
// ManagedOSVersionChannelRef a referemce to the related ManagedOSVersionChannel.
ManagedOSVersionChannelRef *corev1.ObjectReference `json:"channelRef"`
// ManagedOSVersion the name of the ManagedOSVersion resource for which the changelog
// should be generated.
ManagedOSVersion string `json:"osVersion,omitempty"`
// LifetimeMinutes the time at which the changelog data will be cleaned up.
// Default is 60 minutes, set to 0 to disable.
// +kubebuilder:default:=60
// +optional
LifetimeMinutes int32 `json:"cleanupAfterMinutes"`
// Refresh triggers to build again a cleaned up changelog.
// +optional
Refresh bool `json:"refresh"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this should be part of the spec. IMHO this belongs to the state and should be handled there. I know subresources update via kubectl is still a beta feature and expected to be fully supported starting from v1.31, but I think it would make more sense to track it as a condition.
I am not sure having some user input being manipulated and updated in spec by the controller is good pattern. This is prone to cache miss errors and issues during backup & restore.

}

type ChangelogState string

const (
ChangelogInit ChangelogState = "Initialized"
ChangelogStarted ChangelogState = "Started"
ChangelogCompleted ChangelogState = "Completed"
ChangelogFailed ChangelogState = "Failed"
ChangelogNotStarted ChangelogState = "NotStarted"
)

type ManagedOSChangelogStatus struct {
// Conditions describe the state of the changelog object.
// +optional
Conditions []metav1.Condition `json:"conditions,omitempty" patchStrategy:"merge" patchMergeKey:"type"`
// ChangelogURL the URL where changelog data can be displayed
// +optional
ChangelogURL string `json:"changelogURL,omitempty"`
// State reflect the state of the changelog generation process.
// +kubebuilder:validation:Enum=Initialized;Started;Completed;Failed;NotStarted
// +optional
State ChangelogState `json:"state,omitempty"`
}

// +kubebuilder:object:root=true

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

func init() {
SchemeBuilder.Register(&ManagedOSChangelog{}, &ManagedOSChangelogList{})
}
Loading
Loading