|
| 1 | +package v1 |
| 2 | + |
| 3 | +import ( |
| 4 | + corev1 "k8s.io/api/core/v1" |
| 5 | + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
| 6 | + runtime "k8s.io/apimachinery/pkg/runtime" |
| 7 | +) |
| 8 | + |
| 9 | +// MyOperatorResource is an example operator configuration type |
| 10 | +type MyOperatorResource struct { |
| 11 | + metav1.TypeMeta `json:",inline"` |
| 12 | + metav1.ObjectMeta `json:"metadata"` |
| 13 | + |
| 14 | + Spec MyOperatorResourceSpec `json:"spec"` |
| 15 | + Status MyOperatorResourceStatus `json:"status"` |
| 16 | +} |
| 17 | + |
| 18 | +type MyOperatorResourceSpec struct { |
| 19 | + OperatorSpec `json:",inline"` |
| 20 | +} |
| 21 | + |
| 22 | +type MyOperatorResourceStatus struct { |
| 23 | + OperatorStatus `json:",inline"` |
| 24 | +} |
| 25 | + |
| 26 | +type ManagementState string |
| 27 | + |
| 28 | +var ( |
| 29 | + // Force means that the operator is actively managing its resources and ignoring unmet prereqs |
| 30 | + Force ManagementState = "Force" |
| 31 | + // Managed means that the operator is actively managing its resources and trying to keep the component active |
| 32 | + Managed ManagementState = "Managed" |
| 33 | + // Unmanaged means that the operator is not taking any action related to the component |
| 34 | + Unmanaged ManagementState = "Unmanaged" |
| 35 | + // Removed means that the operator is actively managing its resources and trying to remove all traces of the component |
| 36 | + Removed ManagementState = "Removed" |
| 37 | +) |
| 38 | + |
| 39 | +// OperatorSpec contains common fields for an operator to need. It is intended to be anonymous included |
| 40 | +// inside of the Spec struct for you particular operator. |
| 41 | +type OperatorSpec struct { |
| 42 | + // managementState indicates whether and how the operator should manage the component |
| 43 | + ManagementState ManagementState `json:"managementState"` |
| 44 | + |
| 45 | + // operandSpecs provide information about customization for particular units |
| 46 | + OperandSpecs []OperandSpec `json:"operandSpecs"` |
| 47 | + |
| 48 | + // unsupportedConfigOverrides holds a sparse config that will override any previously set options. It only needs to be the fields to override |
| 49 | + // it will end up overlaying in the following order: |
| 50 | + // 1. hardcoded defaults |
| 51 | + // 2. observedConfig |
| 52 | + // 3. unsupportedConfigOverrides |
| 53 | + UnsupportedConfigOverrides runtime.RawExtension `json:"unsupportedConfigOverrides"` |
| 54 | + |
| 55 | + // observedConfig holds a sparse config that controller has observed from the cluster state. It exists in spec because |
| 56 | + // it is an input to the level for the operator |
| 57 | + ObservedConfig runtime.RawExtension `json:"observedConfig"` |
| 58 | +} |
| 59 | + |
| 60 | +// ResourcePatch is a way to represent the patch you would issue to `kubectl patch` in the API |
| 61 | +type ResourcePatch struct { |
| 62 | + // type is the type of patch to apply: jsonmerge, strategicmerge |
| 63 | + Type string `json:"type"` |
| 64 | + // patch the patch itself |
| 65 | + Patch string `json:"patch"` |
| 66 | +} |
| 67 | + |
| 68 | +// OperandSpec holds information for customatization of a particular unit (logical pod) |
| 69 | +type OperandSpec struct { |
| 70 | + // name is the name of this unit. The operator must be aware of it. |
| 71 | + Name string `json:"name"` |
| 72 | + |
| 73 | + // operandContainerSpecs are per-container options |
| 74 | + OperandContainerSpecs []OperandContainerSpec `json:"operandContainerSpecs"` |
| 75 | + |
| 76 | + // Alternatively, we could simply include a RawExtension which is used in place of the "normal" default manifest |
| 77 | + UnsupportedResourcePatches []ResourcePatch `json:"unsupportedResourcePatches"` |
| 78 | +} |
| 79 | + |
| 80 | +type OperandContainerSpec struct { |
| 81 | + // name is the name of the container to modify |
| 82 | + Name string `json:"name"` |
| 83 | + |
| 84 | + // resources are the requests and limits to place in the container. Nil means to accept the defaults. |
| 85 | + Resources *corev1.ResourceRequirements `json:"resources,omitempty"` |
| 86 | + |
| 87 | + // logging contains parameters for setting log values on the operand. Nil means to accept the defaults. |
| 88 | + Logging LoggingConfig `json:"logging,omitempty"` |
| 89 | +} |
| 90 | + |
| 91 | +// LoggingConfig holds information about configuring logging |
| 92 | +type LoggingConfig struct { |
| 93 | + Type string `json:"type"` |
| 94 | + |
| 95 | + Glog *GlogConfig `json:"glog,omitempty"` |
| 96 | + CapnsLog *CapnsLogConfig `json:"capnsLog,omitempty"` |
| 97 | + Java *JavaLog `json:"java,omitempty"` |
| 98 | +} |
| 99 | + |
| 100 | +// GlogConfig holds information about configuring logging |
| 101 | +type GlogConfig struct { |
| 102 | + // level is passed to glog. |
| 103 | + Level int64 `json:"level"` |
| 104 | + |
| 105 | + // vmodule is passed to glog. |
| 106 | + Vmodule string `json:"vmodule"` |
| 107 | +} |
| 108 | + |
| 109 | +type CapnsLogConfig struct { |
| 110 | + // level is passed to capnslog: critical, error, warning, notice, info, debug, trace |
| 111 | + Level string `json:"level"` |
| 112 | + |
| 113 | + // There is some kind of repo/package level thing for this |
| 114 | +} |
| 115 | + |
| 116 | +type JavaLog struct { |
| 117 | + // level is passed to jsr47: fatal, error, warning, info, fine, finer, finest |
| 118 | + Level string `json:"level"` |
| 119 | + |
| 120 | + // There is some kind of repo/package level thing for this. might end up hierarchical |
| 121 | +} |
| 122 | + |
| 123 | +type OperatorStatus struct { |
| 124 | + // conditions is a list of conditions and their status |
| 125 | + Conditions []OperatorCondition `json:"conditions,omitempty"` |
| 126 | + |
| 127 | + // version is the level this availability applies to |
| 128 | + Version string `json:"version"` |
| 129 | + |
| 130 | + // readyReplicas indicates how many replicas are ready and at the desired state |
| 131 | + ReadyReplicas int32 `json:"readyReplicas"` |
| 132 | + |
| 133 | + // generations are used to determine when an item needs to be reconciled or has changed in a way that needs a reaction. |
| 134 | + Generations []GenerationStatus `json:"generations"` |
| 135 | +} |
| 136 | + |
| 137 | +// GenerationStatus keeps track of the generation for a given resource so that decisions about forced updated can be made. |
| 138 | +type GenerationStatus struct { |
| 139 | + // group is the group of the thing you're tracking |
| 140 | + Group string `json:"group"` |
| 141 | + // resource is the resource type of the thing you're tracking |
| 142 | + Resource string `json:"resource"` |
| 143 | + // namespace is where the thing you're tracking is |
| 144 | + Namespace string `json:"namespace"` |
| 145 | + // name is the name of the thing you're tracking |
| 146 | + Name string `json:"name"` |
| 147 | + // lastGeneration is the last generation of the workload controller involved |
| 148 | + LastGeneration int64 `json:"lastGeneration"` |
| 149 | + // hash is an optional field set for resources without generation that are content sensitive like secrets and configmaps |
| 150 | + Hash string `json:"hash"` |
| 151 | +} |
| 152 | + |
| 153 | +var ( |
| 154 | + // Available indicates that the operand is present and accessible in the cluster |
| 155 | + OperatorStatusTypeAvailable = "Available" |
| 156 | + // Progressing indicates that the operator is trying to transition the operand to a different state |
| 157 | + OperatorStatusTypeProgressing = "Progressing" |
| 158 | + // Failing indicates that the operator (not the operand) is unable to fulfill the user intent |
| 159 | + OperatorStatusTypeFailing = "Failing" |
| 160 | + // PrereqsSatisfied indicates that the things this operator depends on are present and at levels compatible with the |
| 161 | + // current and desired states. |
| 162 | + OperatorStatusTypePrereqsSatisfied = "PrereqsSatisfied" |
| 163 | + // Upgradeable indicates that the operator configuration itself (not prereqs) can be auto-upgraded by the CVO |
| 164 | + OperatorStatusTypeUpgradeable = "Upgradeable" |
| 165 | +) |
| 166 | + |
| 167 | +// OperatorCondition is just the standard condition fields. |
| 168 | +type OperatorCondition struct { |
| 169 | + Type string `json:"type"` |
| 170 | + Status ConditionStatus `json:"status"` |
| 171 | + LastTransitionTime metav1.Time `json:"lastTransitionTime,omitempty"` |
| 172 | + Reason string `json:"reason,omitempty"` |
| 173 | + Message string `json:"message,omitempty"` |
| 174 | +} |
| 175 | + |
| 176 | +type ConditionStatus string |
| 177 | + |
| 178 | +const ( |
| 179 | + ConditionTrue ConditionStatus = "True" |
| 180 | + ConditionFalse ConditionStatus = "False" |
| 181 | + ConditionUnknown ConditionStatus = "Unknown" |
| 182 | +) |
| 183 | + |
| 184 | +// StaticPodOperatorStatus is status for controllers that manage static pods. There are different needs because individual |
| 185 | +// node status must be tracked. |
| 186 | +type StaticPodOperatorStatus struct { |
| 187 | + OperatorStatus `json:",inline"` |
| 188 | + |
| 189 | + // latestAvailableDeploymentGeneration is the deploymentID of the most recent deployment |
| 190 | + LatestAvailableDeploymentGeneration int32 `json:"latestAvailableDeploymentGeneration"` |
| 191 | + |
| 192 | + // nodeStatuses track the deployment values and errors across individual nodes |
| 193 | + NodeStatuses []NodeStatus `json:"nodeStatuses"` |
| 194 | +} |
| 195 | + |
| 196 | +// NodeStatus provides information about the current state of a particular node managed by this operator. |
| 197 | +type NodeStatus struct { |
| 198 | + // nodeName is the name of the node |
| 199 | + NodeName string `json:"nodeName"` |
| 200 | + |
| 201 | + // currentDeploymentGeneration is the generation of the most recently successful deployment |
| 202 | + CurrentDeploymentGeneration int32 `json:"currentDeploymentGeneration"` |
| 203 | + // targetDeploymentGeneration is the generation of the deployment we're trying to apply |
| 204 | + TargetDeploymentGeneration int32 `json:"targetDeploymentGeneration"` |
| 205 | + // lastFailedDeploymentGeneration is the generation of the deployment we tried and failed to deploy. |
| 206 | + LastFailedDeploymentGeneration int32 `json:"lastFailedDeploymentGeneration"` |
| 207 | + |
| 208 | + // lastFailedDeploymentGenerationErrors is a list of the errors during the failed deployment referenced in lastFailedDeploymentGeneration |
| 209 | + LastFailedDeploymentErrors []string `json:"lastFailedDeploymentErrors"` |
| 210 | +} |
0 commit comments