|
| 1 | +/* |
| 2 | +Copyright 2020 The actions-runner-controller authors. |
| 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 | + "github.com/actions/actions-runner-controller/hash" |
| 21 | + corev1 "k8s.io/api/core/v1" |
| 22 | + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
| 23 | +) |
| 24 | + |
| 25 | +// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized. |
| 26 | + |
| 27 | +//+kubebuilder:object:root=true |
| 28 | +//+kubebuilder:subresource:status |
| 29 | +//+kubebuilder:printcolumn:JSONPath=".spec.minRunners",name=Minimum Runners,type=number |
| 30 | +//+kubebuilder:printcolumn:JSONPath=".spec.maxRunners",name=Maximum Runners,type=number |
| 31 | +//+kubebuilder:printcolumn:JSONPath=".status.currentRunners",name=Current Runners,type=number |
| 32 | +//+kubebuilder:printcolumn:JSONPath=".status.state",name=State,type=string |
| 33 | + |
| 34 | +// AutoscalingRunnerSet is the Schema for the autoscalingrunnersets API |
| 35 | +type AutoscalingRunnerSet struct { |
| 36 | + metav1.TypeMeta `json:",inline"` |
| 37 | + metav1.ObjectMeta `json:"metadata,omitempty"` |
| 38 | + |
| 39 | + Spec AutoscalingRunnerSetSpec `json:"spec,omitempty"` |
| 40 | + Status AutoscalingRunnerSetStatus `json:"status,omitempty"` |
| 41 | +} |
| 42 | + |
| 43 | +// AutoscalingRunnerSetSpec defines the desired state of AutoscalingRunnerSet |
| 44 | +type AutoscalingRunnerSetSpec struct { |
| 45 | + // Required |
| 46 | + GitHubConfigUrl string `json:"githubConfigUrl,omitempty"` |
| 47 | + |
| 48 | + // Required |
| 49 | + GitHubConfigSecret string `json:"githubConfigSecret,omitempty"` |
| 50 | + |
| 51 | + // +optional |
| 52 | + RunnerGroup string `json:"runnerGroup,omitempty"` |
| 53 | + |
| 54 | + // +optional |
| 55 | + Proxy *ProxyConfig `json:"proxy,omitempty"` |
| 56 | + |
| 57 | + // +optional |
| 58 | + GitHubServerTLS *GitHubServerTLSConfig `json:"githubServerTLS,omitempty"` |
| 59 | + |
| 60 | + // Required |
| 61 | + Template corev1.PodTemplateSpec `json:"template,omitempty"` |
| 62 | + |
| 63 | + // +optional |
| 64 | + // +kubebuilder:validation:Minimum:=0 |
| 65 | + MaxRunners *int `json:"maxRunners,omitempty"` |
| 66 | + |
| 67 | + // +optional |
| 68 | + // +kubebuilder:validation:Minimum:=0 |
| 69 | + MinRunners *int `json:"minRunners,omitempty"` |
| 70 | +} |
| 71 | + |
| 72 | +type GitHubServerTLSConfig struct { |
| 73 | + // Required |
| 74 | + RootCAsConfigMapRef string `json:"certConfigMapRef,omitempty"` |
| 75 | +} |
| 76 | + |
| 77 | +type ProxyConfig struct { |
| 78 | + // +optional |
| 79 | + HTTP *ProxyServerConfig `json:"http,omitempty"` |
| 80 | + |
| 81 | + // +optional |
| 82 | + HTTPS *ProxyServerConfig `json:"https,omitempty"` |
| 83 | +} |
| 84 | + |
| 85 | +type ProxyServerConfig struct { |
| 86 | + // Required |
| 87 | + Url string `json:"url,omitempty"` |
| 88 | + |
| 89 | + // +optional |
| 90 | + CredentialSecretRef string `json:"credentialSecretRef,omitempty"` |
| 91 | + |
| 92 | + // +optional |
| 93 | + NoProxy []string `json:"noProxy,omitempty"` |
| 94 | +} |
| 95 | + |
| 96 | +// AutoscalingRunnerSetStatus defines the observed state of AutoscalingRunnerSet |
| 97 | +type AutoscalingRunnerSetStatus struct { |
| 98 | + // +optional |
| 99 | + CurrentRunners int `json:"currentRunners,omitempty"` |
| 100 | + |
| 101 | + // +optional |
| 102 | + State string `json:"state,omitempty"` |
| 103 | +} |
| 104 | + |
| 105 | +func (ars *AutoscalingRunnerSet) ListenerSpecHash() string { |
| 106 | + type listenerSpec = AutoscalingRunnerSetSpec |
| 107 | + arsSpec := ars.Spec.DeepCopy() |
| 108 | + spec := arsSpec |
| 109 | + return hash.ComputeTemplateHash(&spec) |
| 110 | +} |
| 111 | + |
| 112 | +func (ars *AutoscalingRunnerSet) RunnerSetSpecHash() string { |
| 113 | + type runnerSetSpec struct { |
| 114 | + GitHubConfigUrl string |
| 115 | + GitHubConfigSecret string |
| 116 | + RunnerGroup string |
| 117 | + Proxy *ProxyConfig |
| 118 | + GitHubServerTLS *GitHubServerTLSConfig |
| 119 | + Template corev1.PodTemplateSpec |
| 120 | + } |
| 121 | + spec := &runnerSetSpec{ |
| 122 | + GitHubConfigUrl: ars.Spec.GitHubConfigUrl, |
| 123 | + GitHubConfigSecret: ars.Spec.GitHubConfigSecret, |
| 124 | + RunnerGroup: ars.Spec.RunnerGroup, |
| 125 | + Proxy: ars.Spec.Proxy, |
| 126 | + GitHubServerTLS: ars.Spec.GitHubServerTLS, |
| 127 | + Template: ars.Spec.Template, |
| 128 | + } |
| 129 | + return hash.ComputeTemplateHash(&spec) |
| 130 | +} |
| 131 | + |
| 132 | +//+kubebuilder:object:root=true |
| 133 | + |
| 134 | +// AutoscalingRunnerSetList contains a list of AutoscalingRunnerSet |
| 135 | +type AutoscalingRunnerSetList struct { |
| 136 | + metav1.TypeMeta `json:",inline"` |
| 137 | + metav1.ListMeta `json:"metadata,omitempty"` |
| 138 | + Items []AutoscalingRunnerSet `json:"items"` |
| 139 | +} |
| 140 | + |
| 141 | +func init() { |
| 142 | + SchemeBuilder.Register(&AutoscalingRunnerSet{}, &AutoscalingRunnerSetList{}) |
| 143 | +} |
0 commit comments