|
| 1 | +/* |
| 2 | +Copyright 2024. |
| 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 v1alpha1 |
| 18 | + |
| 19 | +import ( |
| 20 | + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
| 21 | +) |
| 22 | + |
| 23 | +// RequiredStatusCheckCommitStatusSpec defines the desired state of RequiredStatusCheckCommitStatus |
| 24 | +type RequiredStatusCheckCommitStatusSpec struct { |
| 25 | + // PromotionStrategyRef references the PromotionStrategy that owns this controller |
| 26 | + // +required |
| 27 | + PromotionStrategyRef ObjectReference `json:"promotionStrategyRef"` |
| 28 | +} |
| 29 | + |
| 30 | +// RequiredStatusCheckCommitStatusStatus defines the observed state of RequiredStatusCheckCommitStatus |
| 31 | +type RequiredStatusCheckCommitStatusStatus struct { |
| 32 | + // Environments contains status for each environment's branch protection checks |
| 33 | + // +listType=map |
| 34 | + // +listMapKey=branch |
| 35 | + // +optional |
| 36 | + Environments []RequiredStatusCheckEnvironmentStatus `json:"environments,omitempty"` |
| 37 | + |
| 38 | + // Conditions represent the latest available observations of the resource's state |
| 39 | + // +listType=map |
| 40 | + // +listMapKey=type |
| 41 | + // +optional |
| 42 | + Conditions []metav1.Condition `json:"conditions,omitempty"` |
| 43 | +} |
| 44 | + |
| 45 | +// RequiredStatusCheckEnvironmentStatus defines the observed required check status for a specific environment. |
| 46 | +type RequiredStatusCheckEnvironmentStatus struct { |
| 47 | + // Branch is the target branch being monitored |
| 48 | + // +required |
| 49 | + Branch string `json:"branch"` |
| 50 | + |
| 51 | + // Sha is the commit SHA being checked |
| 52 | + // +required |
| 53 | + Sha string `json:"sha"` |
| 54 | + |
| 55 | + // RequiredChecks lists all required checks discovered from GitHub Rulesets |
| 56 | + // +listType=map |
| 57 | + // +listMapKey=context |
| 58 | + // +optional |
| 59 | + RequiredChecks []RequiredCheckStatus `json:"requiredChecks,omitempty"` |
| 60 | + |
| 61 | + // Phase is the aggregated phase of all required checks |
| 62 | + // +kubebuilder:validation:Enum=pending;success;failure |
| 63 | + // +required |
| 64 | + Phase CommitStatusPhase `json:"phase"` |
| 65 | +} |
| 66 | + |
| 67 | +// RequiredCheckStatus defines the status of a single required check. |
| 68 | +type RequiredCheckStatus struct { |
| 69 | + // Context is the GitHub check context name |
| 70 | + // +required |
| 71 | + Context string `json:"context"` |
| 72 | + |
| 73 | + // Phase is the current phase of this check |
| 74 | + // +kubebuilder:validation:Enum=pending;success;failure |
| 75 | + // +required |
| 76 | + Phase CommitStatusPhase `json:"phase"` |
| 77 | + |
| 78 | + // CommitStatusName is the name of the CommitStatus resource created for this check |
| 79 | + // +optional |
| 80 | + CommitStatusName string `json:"commitStatusName,omitempty"` |
| 81 | +} |
| 82 | + |
| 83 | +// +kubebuilder:object:root=true |
| 84 | +// +kubebuilder:subresource:status |
| 85 | + |
| 86 | +// RequiredStatusCheckCommitStatus is the Schema for the requiredstatuscheckcommitstatuses API |
| 87 | +// +kubebuilder:printcolumn:name="PromotionStrategy",type=string,JSONPath=`.spec.promotionStrategyRef.name` |
| 88 | +// +kubebuilder:printcolumn:name="Ready",type=string,JSONPath=`.status.conditions[?(@.type=="Ready")].status` |
| 89 | +type RequiredStatusCheckCommitStatus struct { |
| 90 | + metav1.TypeMeta `json:",inline"` |
| 91 | + |
| 92 | + // metadata is a standard object metadata |
| 93 | + // +optional |
| 94 | + metav1.ObjectMeta `json:"metadata,omitempty"` |
| 95 | + |
| 96 | + // spec defines the desired state of RequiredStatusCheckCommitStatus |
| 97 | + // +required |
| 98 | + Spec RequiredStatusCheckCommitStatusSpec `json:"spec"` |
| 99 | + |
| 100 | + // status defines the observed state of RequiredStatusCheckCommitStatus |
| 101 | + // +optional |
| 102 | + Status RequiredStatusCheckCommitStatusStatus `json:"status,omitempty"` |
| 103 | +} |
| 104 | + |
| 105 | +// +kubebuilder:object:root=true |
| 106 | + |
| 107 | +// RequiredStatusCheckCommitStatusList contains a list of RequiredStatusCheckCommitStatus |
| 108 | +type RequiredStatusCheckCommitStatusList struct { |
| 109 | + metav1.TypeMeta `json:",inline"` |
| 110 | + metav1.ListMeta `json:"metadata,omitempty"` |
| 111 | + Items []RequiredStatusCheckCommitStatus `json:"items"` |
| 112 | +} |
| 113 | + |
| 114 | +// GetConditions returns the conditions of the RequiredStatusCheckCommitStatus. |
| 115 | +func (rsccs *RequiredStatusCheckCommitStatus) GetConditions() *[]metav1.Condition { |
| 116 | + return &rsccs.Status.Conditions |
| 117 | +} |
| 118 | + |
| 119 | +func init() { |
| 120 | + SchemeBuilder.Register(&RequiredStatusCheckCommitStatus{}, &RequiredStatusCheckCommitStatusList{}) |
| 121 | +} |
0 commit comments