Skip to content

Commit

Permalink
feat(main): add automq status api
Browse files Browse the repository at this point in the history
  • Loading branch information
cuisongliu committed Oct 1, 2024
1 parent 4e6c577 commit fa00027
Show file tree
Hide file tree
Showing 9 changed files with 422 additions and 214 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ $(ENVTEST): $(LOCALBIN)


.PHONY: crd
crd: manifests kustomize ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
crd: manifests generate kustomize ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
@cp -rf config/crd/bases/* deploy/charts/automq-operator/crds/

info:
Expand Down
9 changes: 5 additions & 4 deletions api/v1beta1/automq_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,14 +166,15 @@ type AutoMQStatus struct {
// Phase represents the current phase of AutoMQ.
//+kubebuilder:default:=Unknown
Phase AutoMQPhase `json:"phase,omitempty"`
// Conditions contains the different condition statuses for this automq.
// +optional
Conditions []StatusCondition `json:"conditions"`
// ReadyPods is the number of ready pods for the AutoMQ
// +optional
// +kubebuilder:validation:Minimum=0
// +kubebuilder:default=0
ReadyPods int32 `json:"readyPods"`
// Message is a human-readable string indicating details about why the Setting is in this condition.
// +optional
Message string `json:"message,omitempty"`
// ShortMessage is a human-readable string indicating details about why the Setting is in this condition.
// ShortMessage is a human-readable string indicating details about why the AutoMQ is in this condition.
// +optional
ShortMessage string `json:"shortMessage,omitempty"`
}
Expand Down
78 changes: 78 additions & 0 deletions api/v1beta1/status.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
Copyright 2024 [email protected].
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 (
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

type ConditionType string

type StatusCondition struct {
// Type is the type of the condition.
Type ConditionType `json:"type"`
// Status is the status of the condition. One of True, False, Unknown.
Status v1.ConditionStatus `json:"status"`
// LastTransitionTime is the last time the condition changed from one status to another.
// +optional
LastTransitionTime metav1.Time `json:"lastTransitionTime,omitempty"`
// Reason is a (brief) reason for the condition's last status change.
// +optional
Reason string `json:"reason,omitempty"`
// Message is a human-readable message indicating details about the last status change.
// +optional
Message string `json:"message,omitempty"`
}

// SetCondition sets a condition on the status object. If the condition already
// exists, it will be replaced. SetCondition does not update the resource in
// the cluster.
func SetCondition(conditions []StatusCondition, condition StatusCondition) []StatusCondition {
now := metav1.Now()
for i := range conditions {
if conditions[i].Type == condition.Type {
if conditions[i].Status != condition.Status {
condition.LastTransitionTime = now
} else {
condition.LastTransitionTime = conditions[i].LastTransitionTime
}
conditions[i] = condition
return conditions
}
}

// If the condition does not exist,
// initialize the lastTransitionTime
condition.LastTransitionTime = now
conditions = append(conditions, condition)
return conditions
}

// RemoveCondition removes the condition with the passed condition type from
// the status object. If the condition is not already present, the returned
// status object is returned unchanged. RemoveCondition does not update the
// resource in the cluster.
func RemoveCondition(conditions []StatusCondition, conditionType ConditionType) []StatusCondition {
for i := range conditions {
if conditions[i].Type == conditionType {
conditions = append(conditions[:i], conditions[i+1:]...)
return conditions
}
}
return conditions
}
25 changes: 24 additions & 1 deletion api/v1beta1/zz_generated.deepcopy.go

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

65 changes: 60 additions & 5 deletions config/crd/bases/infra.cuisongliu.github.com_automqs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,12 @@ spec:
description: The key to select.
type: string
name:
default: ""
description: |-
Name of the referent.
This field is effectively required, but due to backwards compatibility is
allowed to be empty. Instances of this type with an empty value here are
almost certainly wrong.
More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
type: string
optional:
Expand Down Expand Up @@ -217,8 +221,12 @@ spec:
be a valid secret key.
type: string
name:
default: ""
description: |-
Name of the referent.
This field is effectively required, but due to backwards compatibility is
allowed to be empty. Instances of this type with an empty value here are
almost certainly wrong.
More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
type: string
optional:
Expand Down Expand Up @@ -265,6 +273,12 @@ spec:
the Pod where this field is used. It makes that resource available
inside a container.
type: string
request:
description: |-
Request is the name chosen for a request in the referenced claim.
If empty, everything from the claim is made available, otherwise
only the result of this request.
type: string
required:
- name
type: object
Expand Down Expand Up @@ -404,8 +418,12 @@ spec:
description: The key to select.
type: string
name:
default: ""
description: |-
Name of the referent.
This field is effectively required, but due to backwards compatibility is
allowed to be empty. Instances of this type with an empty value here are
almost certainly wrong.
More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
type: string
optional:
Expand Down Expand Up @@ -466,8 +484,12 @@ spec:
be a valid secret key.
type: string
name:
default: ""
description: |-
Name of the referent.
This field is effectively required, but due to backwards compatibility is
allowed to be empty. Instances of this type with an empty value here are
almost certainly wrong.
More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
type: string
optional:
Expand Down Expand Up @@ -514,6 +536,12 @@ spec:
the Pod where this field is used. It makes that resource available
inside a container.
type: string
request:
description: |-
Request is the name chosen for a request in the referenced claim.
If empty, everything from the claim is made available, otherwise
only the result of this request.
type: string
required:
- name
type: object
Expand Down Expand Up @@ -604,22 +632,49 @@ spec:
status:
description: AutoMQStatus defines the observed state of AutoMQ
properties:
message:
description: Message is a human-readable string indicating details
about why the Setting is in this condition.
type: string
conditions:
description: Conditions contains the different condition statuses
for this automq.
items:
properties:
lastTransitionTime:
description: LastTransitionTime is the last time the condition
changed from one status to another.
format: date-time
type: string
message:
description: Message is a human-readable message indicating
details about the last status change.
type: string
reason:
description: Reason is a (brief) reason for the condition's
last status change.
type: string
status:
description: Status is the status of the condition. One of True,
False, Unknown.
type: string
type:
description: Type is the type of the condition.
type: string
required:
- status
- type
type: object
type: array
phase:
default: Unknown
description: Phase represents the current phase of AutoMQ.
type: string
readyPods:
default: 0
description: ReadyPods is the number of ready pods for the AutoMQ
format: int32
minimum: 0
type: integer
shortMessage:
description: ShortMessage is a human-readable string indicating details
about why the Setting is in this condition.
about why the AutoMQ is in this condition.
type: string
type: object
type: object
Expand Down
Loading

0 comments on commit fa00027

Please sign in to comment.