-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cloudprovider): Implement rancher as a cloud provider.
- Loading branch information
UKS
committed
Apr 26, 2021
1 parent
8dc1afb
commit d30a5e3
Showing
15 changed files
with
1,885 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
cluster-autoscaler/cloudprovider/builder/builder_rancher.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// +build rancher | ||
|
||
/* | ||
Copyright 2021 The Kubernetes Authors. | ||
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 builder | ||
|
||
import ( | ||
"k8s.io/autoscaler/cluster-autoscaler/cloudprovider" | ||
"k8s.io/autoscaler/cluster-autoscaler/cloudprovider/rancher" | ||
"k8s.io/autoscaler/cluster-autoscaler/config" | ||
) | ||
|
||
// AvailableCloudProviders supported by the rancher provider builder. | ||
var AvailableCloudProviders = []string{ | ||
cloudprovider.RancherProviderName, | ||
} | ||
|
||
// DefaultCloudProvider for do-only build is rancher. | ||
const DefaultCloudProvider = cloudprovider.RancherProviderName | ||
|
||
func buildCloudProvider(opts config.AutoscalingOptions, do cloudprovider.NodeGroupDiscoveryOptions, rl *cloudprovider.ResourceLimiter) cloudprovider.CloudProvider { | ||
switch opts.CloudProviderName { | ||
case cloudprovider.RancherProviderName: | ||
return rancher.BuildRancher(opts, do, rl) | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
cluster-autoscaler/cloudprovider/rancher/examples/autoscaler-config-example.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
apiVersion: v1 | ||
kind: Secret | ||
metadata: | ||
name: cluster-autoscaler-cloud-config | ||
namespace: kube-system | ||
type: Opaque | ||
stringData: | ||
cloud-config: |- | ||
[Global] | ||
url=https://rancherapi.com/v3 | ||
access=token-abcdef | ||
secret=ksjdhfiusdhfkjsdfhisudhfnskjdfhskjdfhksdjfhksjdfhksdjf | ||
cluster-id=c-abcdef | ||
autoscaler_node_arg: "2:6:c-abcdef:np-abcde" |
118 changes: 118 additions & 0 deletions
118
cluster-autoscaler/cloudprovider/rancher/examples/autoscaler-noconfig-template.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: ClusterRole | ||
metadata: | ||
name: cluster-autoscaler-role | ||
rules: | ||
- apiGroups: [""] | ||
resources: ["events", "endpoints"] | ||
verbs: ["create", "patch"] | ||
- apiGroups: [""] | ||
resources: ["pods/eviction"] | ||
verbs: ["create"] | ||
- apiGroups: [""] | ||
resources: ["pods/status"] | ||
verbs: ["update"] | ||
- apiGroups: [""] | ||
resources: ["endpoints"] | ||
resourceNames: ["cluster-autoscaler"] | ||
verbs: ["get", "update"] | ||
- apiGroups: [""] | ||
resources: ["nodes"] | ||
verbs: ["watch", "list", "get", "update"] | ||
- apiGroups: [""] | ||
resources: | ||
- "pods" | ||
- "services" | ||
- "replicationcontrollers" | ||
- "persistentvolumeclaims" | ||
- "persistentvolumes" | ||
verbs: ["watch", "list", "get"] | ||
- apiGroups: ["batch"] | ||
resources: ["jobs"] | ||
verbs: ["watch", "list", "get"] | ||
- apiGroups: ["policy"] | ||
resources: ["poddisruptionbudgets"] | ||
verbs: ["watch", "list"] | ||
- apiGroups: ["apps"] | ||
resources: ["daemonsets", "replicasets", "statefulsets"] | ||
verbs: ["watch", "list", "get"] | ||
- apiGroups: ["storage.k8s.io"] | ||
resources: ["storageclasses", "csinodes"] | ||
verbs: ["watch", "list", "get"] | ||
- apiGroups: [""] | ||
resources: ["configmaps"] | ||
verbs: ["create","list","watch"] | ||
- apiGroups: [""] | ||
resources: ["configmaps"] | ||
resourceNames: ["cluster-autoscaler-status", "cluster-autoscaler-priority-expander"] | ||
verbs: ["delete", "get", "update"] | ||
- apiGroups: ["coordination.k8s.io"] | ||
resources: ["leases"] | ||
verbs: ["watch", "list", "get", "create", "update", "patch", "delete", "deletecollection"] | ||
|
||
--- | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: ClusterRoleBinding | ||
metadata: | ||
name: cluster-autoscaler-rolebinding | ||
namespace: kube-system | ||
roleRef: | ||
apiGroup: rbac.authorization.k8s.io | ||
kind: ClusterRole | ||
name: cluster-autoscaler-role | ||
subjects: | ||
- kind: ServiceAccount | ||
name: cluster-autoscaler-account | ||
namespace: kube-system | ||
|
||
--- | ||
apiVersion: v1 | ||
kind: ServiceAccount | ||
metadata: | ||
name: cluster-autoscaler-account | ||
namespace: kube-system | ||
|
||
--- | ||
kind: Deployment | ||
apiVersion: apps/v1 | ||
metadata: | ||
name: cluster-autoscaler | ||
namespace: kube-system | ||
labels: | ||
app: cluster-autoscaler | ||
spec: | ||
replicas: 1 | ||
selector: | ||
matchLabels: | ||
app: cluster-autoscaler | ||
template: | ||
metadata: | ||
namespace: kube-system | ||
labels: | ||
app: cluster-autoscaler | ||
spec: | ||
serviceAccountName: cluster-autoscaler-account | ||
containers: | ||
- name: cluster-autoscaler | ||
image: us.gcr.io/gns-hosting-dev/cluster-autoscaler-amd64:{{ env "TAG" }} | ||
imagePullPolicy: Always | ||
command: | ||
- ./cluster-autoscaler | ||
- --alsologtostderr | ||
- --cloud-config=/config/cloud-config | ||
- --cloud-provider=rancher | ||
- --nodes=$(NODE_ARG) | ||
volumeMounts: | ||
- name: cloud-config | ||
mountPath: /config | ||
readOnly: true | ||
env: | ||
- name: NODE_ARG | ||
valueFrom: | ||
secretKeyRef: | ||
name: cluster-autoscaler-cloud-config | ||
key: autoscaler_node_arg | ||
volumes: | ||
- name: cloud-config | ||
secret: | ||
secretName: cluster-autoscaler-cloud-config |
118 changes: 118 additions & 0 deletions
118
cluster-autoscaler/cloudprovider/rancher/examples/autoscaler-noconfig.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: ClusterRole | ||
metadata: | ||
name: cluster-autoscaler-role | ||
rules: | ||
- apiGroups: [""] | ||
resources: ["events", "endpoints"] | ||
verbs: ["create", "patch"] | ||
- apiGroups: [""] | ||
resources: ["pods/eviction"] | ||
verbs: ["create"] | ||
- apiGroups: [""] | ||
resources: ["pods/status"] | ||
verbs: ["update"] | ||
- apiGroups: [""] | ||
resources: ["endpoints"] | ||
resourceNames: ["cluster-autoscaler"] | ||
verbs: ["get", "update"] | ||
- apiGroups: [""] | ||
resources: ["nodes"] | ||
verbs: ["watch", "list", "get", "update"] | ||
- apiGroups: [""] | ||
resources: | ||
- "pods" | ||
- "services" | ||
- "replicationcontrollers" | ||
- "persistentvolumeclaims" | ||
- "persistentvolumes" | ||
verbs: ["watch", "list", "get"] | ||
- apiGroups: ["batch"] | ||
resources: ["jobs"] | ||
verbs: ["watch", "list", "get"] | ||
- apiGroups: ["policy"] | ||
resources: ["poddisruptionbudgets"] | ||
verbs: ["watch", "list"] | ||
- apiGroups: ["apps"] | ||
resources: ["daemonsets", "replicasets", "statefulsets"] | ||
verbs: ["watch", "list", "get"] | ||
- apiGroups: ["storage.k8s.io"] | ||
resources: ["storageclasses", "csinodes"] | ||
verbs: ["watch", "list", "get"] | ||
- apiGroups: [""] | ||
resources: ["configmaps"] | ||
verbs: ["create","list","watch"] | ||
- apiGroups: [""] | ||
resources: ["configmaps"] | ||
resourceNames: ["cluster-autoscaler-status", "cluster-autoscaler-priority-expander"] | ||
verbs: ["delete", "get", "update"] | ||
- apiGroups: ["coordination.k8s.io"] | ||
resources: ["leases"] | ||
verbs: ["watch", "list", "get", "create", "update", "patch", "delete", "deletecollection"] | ||
|
||
--- | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: ClusterRoleBinding | ||
metadata: | ||
name: cluster-autoscaler-rolebinding | ||
namespace: kube-system | ||
roleRef: | ||
apiGroup: rbac.authorization.k8s.io | ||
kind: ClusterRole | ||
name: cluster-autoscaler-role | ||
subjects: | ||
- kind: ServiceAccount | ||
name: cluster-autoscaler-account | ||
namespace: kube-system | ||
|
||
--- | ||
apiVersion: v1 | ||
kind: ServiceAccount | ||
metadata: | ||
name: cluster-autoscaler-account | ||
namespace: kube-system | ||
|
||
--- | ||
kind: Deployment | ||
apiVersion: apps/v1 | ||
metadata: | ||
name: cluster-autoscaler | ||
namespace: kube-system | ||
labels: | ||
app: cluster-autoscaler | ||
spec: | ||
replicas: 1 | ||
selector: | ||
matchLabels: | ||
app: cluster-autoscaler | ||
template: | ||
metadata: | ||
namespace: kube-system | ||
labels: | ||
app: cluster-autoscaler | ||
spec: | ||
serviceAccountName: cluster-autoscaler-account | ||
containers: | ||
- name: cluster-autoscaler | ||
image: cluster-autoscaler:latest | ||
imagePullPolicy: Always | ||
command: | ||
- ./cluster-autoscaler | ||
- --alsologtostderr | ||
- --cloud-config=/config/cloud-config | ||
- --cloud-provider=rancher | ||
- --nodes=$(NODE_ARG) | ||
volumeMounts: | ||
- name: cloud-config | ||
mountPath: /config | ||
readOnly: true | ||
env: | ||
- name: NODE_ARG | ||
valueFrom: | ||
secretKeyRef: | ||
name: cluster-autoscaler-cloud-config | ||
key: autoscaler_node_arg | ||
volumes: | ||
- name: cloud-config | ||
secret: | ||
secretName: cluster-autoscaler-cloud-config |
Oops, something went wrong.