|
| 1 | +// Copyright 2025 Google LLC |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +package v1alpha1 |
| 16 | + |
| 17 | +import ( |
| 18 | + refs "github.com/GoogleCloudPlatform/k8s-config-connector/apis/refs/v1beta1" |
| 19 | + "github.com/GoogleCloudPlatform/k8s-config-connector/pkg/apis/k8s/v1alpha1" |
| 20 | + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
| 21 | +) |
| 22 | + |
| 23 | +var DeployDeployPolicyGVK = GroupVersion.WithKind("CloudDeployDeployPolicy") |
| 24 | + |
| 25 | +type Parent struct { |
| 26 | + // +required |
| 27 | + ProjectRef *refs.ProjectRef `json:"projectRef"` |
| 28 | + |
| 29 | + // +kubebuilder:validation:XValidation:rule="self == oldSelf",message="Location field is immutable" |
| 30 | + // Immutable. |
| 31 | + // +required |
| 32 | + Location string `json:"location"` |
| 33 | +} |
| 34 | + |
| 35 | +// DeployPolicySpec defines the desired state of DeployDeployPolicy |
| 36 | +// +kcc:proto=google.cloud.deploy.v1.DeployPolicy |
| 37 | +type DeployPolicySpec struct { |
| 38 | + Parent `json:",inline"` |
| 39 | + |
| 40 | + // The DeployDeployPolicy name. If not given, the metadata.name will be used. |
| 41 | + ResourceID *string `json:"resourceID,omitempty"` |
| 42 | + |
| 43 | + // Description of the `DeployPolicy`. Max length is 255 characters. |
| 44 | + // +kcc:proto:field=google.cloud.deploy.v1.DeployPolicy.description |
| 45 | + Description *string `json:"description,omitempty"` |
| 46 | + |
| 47 | + // NOT YET |
| 48 | + // // User annotations. These attributes can only be set and used by the |
| 49 | + // // user, and not by Cloud Deploy. Annotations must meet the following |
| 50 | + // // constraints: |
| 51 | + // // |
| 52 | + // // * Annotations are key/value pairs. |
| 53 | + // // * Valid annotation keys have two segments: an optional prefix and name, |
| 54 | + // // separated by a slash (`/`). |
| 55 | + // // * The name segment is required and must be 63 characters or less, |
| 56 | + // // beginning and ending with an alphanumeric character (`[a-z0-9A-Z]`) with |
| 57 | + // // dashes (`-`), underscores (`_`), dots (`.`), and alphanumerics between. |
| 58 | + // // * The prefix is optional. If specified, the prefix must be a DNS subdomain: |
| 59 | + // // a series of DNS labels separated by dots(`.`), not longer than 253 |
| 60 | + // // characters in total, followed by a slash (`/`). |
| 61 | + // // |
| 62 | + // // See |
| 63 | + // // https://kubernetes.io/docs/concepts/overview/working-with-objects/annotations/#syntax-and-character-set |
| 64 | + // // for more details. |
| 65 | + // // +kcc:proto:field=google.cloud.deploy.v1.DeployPolicy.annotations |
| 66 | + // Annotations map[string]string `json:"annotations,omitempty"` |
| 67 | + |
| 68 | + // // Labels are attributes that can be set and used by both the |
| 69 | + // // user and by Cloud Deploy. Labels must meet the following constraints: |
| 70 | + // // |
| 71 | + // // * Keys and values can contain only lowercase letters, numeric characters, |
| 72 | + // // underscores, and dashes. |
| 73 | + // // * All characters must use UTF-8 encoding, and international characters are |
| 74 | + // // allowed. |
| 75 | + // // * Keys must start with a lowercase letter or international character. |
| 76 | + // // * Each resource is limited to a maximum of 64 labels. |
| 77 | + // // |
| 78 | + // // Both keys and values are additionally constrained to be <= 128 bytes. |
| 79 | + // // +kcc:proto:field=google.cloud.deploy.v1.DeployPolicy.labels |
| 80 | + // Labels map[string]string `json:"labels,omitempty"` |
| 81 | + |
| 82 | + // When suspended, the policy will not prevent actions from occurring, even |
| 83 | + // if the action violates the policy. |
| 84 | + // +kcc:proto:field=google.cloud.deploy.v1.DeployPolicy.suspended |
| 85 | + Suspended *bool `json:"suspended,omitempty"` |
| 86 | + |
| 87 | + // Required. Selected resources to which the policy will be applied. At least |
| 88 | + // one selector is required. If one selector matches the resource the policy |
| 89 | + // applies. For example, if there are two selectors and the action being |
| 90 | + // attempted matches one of them, the policy will apply to that action. |
| 91 | + // +kcc:proto:field=google.cloud.deploy.v1.DeployPolicy.selectors |
| 92 | + Selectors []DeployPolicyResourceSelector `json:"selectors,omitempty"` |
| 93 | + |
| 94 | + // Required. Rules to apply. At least one rule must be present. |
| 95 | + // +kcc:proto:field=google.cloud.deploy.v1.DeployPolicy.rules |
| 96 | + Rules []PolicyRule `json:"rules,omitempty"` |
| 97 | + |
| 98 | + // NOT YET |
| 99 | + // // The weak etag of the `Automation` resource. |
| 100 | + // // This checksum is computed by the server based on the value of other |
| 101 | + // // fields, and may be sent on update and delete requests to ensure the |
| 102 | + // // client has an up-to-date value before proceeding. |
| 103 | + // // +kcc:proto:field=google.cloud.deploy.v1.DeployPolicy.etag |
| 104 | + // Etag *string `json:"etag,omitempty"` |
| 105 | +} |
| 106 | + |
| 107 | +// DeployPolicyStatus defines the config connector machine state of DeployDeployPolicy |
| 108 | +type DeployPolicyStatus struct { |
| 109 | + /* Conditions represent the latest available observations of the |
| 110 | + object's current state. */ |
| 111 | + Conditions []v1alpha1.Condition `json:"conditions,omitempty"` |
| 112 | + |
| 113 | + // ObservedGeneration is the generation of the resource that was most recently observed by the Config Connector controller. If this is equal to metadata.generation, then that means that the current reported status reflects the most recent desired state of the resource. |
| 114 | + ObservedGeneration *int64 `json:"observedGeneration,omitempty"` |
| 115 | + |
| 116 | + // A unique specifier for the DeployDeployPolicy resource in GCP. |
| 117 | + ExternalRef *string `json:"externalRef,omitempty"` |
| 118 | + |
| 119 | + // ObservedState is the state of the resource as most recently observed in GCP. |
| 120 | + ObservedState *DeployPolicyObservedState `json:"observedState,omitempty"` |
| 121 | +} |
| 122 | + |
| 123 | +// DeployPolicyObservedState is the state of the DeployDeployPolicy resource as most recently observed in GCP. |
| 124 | +// +kcc:proto=google.cloud.deploy.v1.DeployPolicy |
| 125 | +type DeployPolicyObservedState struct { |
| 126 | + // Output only. Name of the `DeployPolicy`. Format is |
| 127 | + // `projects/{project}/locations/{location}/deployPolicies/{deployPolicy}`. |
| 128 | + // The `deployPolicy` component must match `[a-z]([a-z0-9-]{0,61}[a-z0-9])?` |
| 129 | + // +kcc:proto:field=google.cloud.deploy.v1.DeployPolicy.name |
| 130 | + Name *string `json:"name,omitempty"` |
| 131 | + |
| 132 | + // Output only. Unique identifier of the `DeployPolicy`. |
| 133 | + // +kcc:proto:field=google.cloud.deploy.v1.DeployPolicy.uid |
| 134 | + Uid *string `json:"uid,omitempty"` |
| 135 | + |
| 136 | + // Output only. Time at which the deploy policy was created. |
| 137 | + // +kcc:proto:field=google.cloud.deploy.v1.DeployPolicy.create_time |
| 138 | + CreateTime *string `json:"createTime,omitempty"` |
| 139 | + |
| 140 | + // Output only. Most recent time at which the deploy policy was updated. |
| 141 | + // +kcc:proto:field=google.cloud.deploy.v1.DeployPolicy.update_time |
| 142 | + UpdateTime *string `json:"updateTime,omitempty"` |
| 143 | +} |
| 144 | + |
| 145 | +// +genclient |
| 146 | +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object |
| 147 | +// +kubebuilder:resource:categories=gcp,shortName=gcpcodedeploydeploypolicy;gcpcodedeploydeploypolicies |
| 148 | +// +kubebuilder:subresource:status |
| 149 | +// +kubebuilder:metadata:labels="cnrm.cloud.google.com/managed-by-kcc=true";"cnrm.cloud.google.com/system=true" |
| 150 | +// +kubebuilder:printcolumn:name="Age",JSONPath=".metadata.creationTimestamp",type="date" |
| 151 | +// +kubebuilder:printcolumn:name="Ready",JSONPath=".status.conditions[?(@.type=='Ready')].status",type="string",description="When 'True', the most recent reconcile of the resource succeeded" |
| 152 | +// +kubebuilder:printcolumn:name="Status",JSONPath=".status.conditions[?(@.type=='Ready')].reason",type="string",description="The reason for the value in 'Ready'" |
| 153 | +// +kubebuilder:printcolumn:name="Status Age",JSONPath=".status.conditions[?(@.type=='Ready')].lastTransitionTime",type="date",description="The last transition time for the value in 'Status'" |
| 154 | + |
| 155 | +// CloudDeployDeployPolicy is the Schema for the CloudDeployDeployPolicy API |
| 156 | +// +k8s:openapi-gen=true |
| 157 | +type CloudDeployDeployPolicy struct { |
| 158 | + metav1.TypeMeta `json:",inline"` |
| 159 | + metav1.ObjectMeta `json:"metadata,omitempty"` |
| 160 | + |
| 161 | + // +required |
| 162 | + Spec DeployPolicySpec `json:"spec,omitempty"` |
| 163 | + Status DeployPolicyStatus `json:"status,omitempty"` |
| 164 | +} |
| 165 | + |
| 166 | +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object |
| 167 | +// CloudDeployDeployPolicyList contains a list of DeployDeployPolicy |
| 168 | +type CloudDeployDeployPolicyList struct { |
| 169 | + metav1.TypeMeta `json:",inline"` |
| 170 | + metav1.ListMeta `json:"metadata,omitempty"` |
| 171 | + Items []CloudDeployDeployPolicy `json:"items"` |
| 172 | +} |
| 173 | + |
| 174 | +func init() { |
| 175 | + SchemeBuilder.Register(&CloudDeployDeployPolicy{}, &CloudDeployDeployPolicyList{}) |
| 176 | +} |
0 commit comments