├── vsphere ├── vclib │ ├── fixtures │ │ ├── invalid.pem │ │ ├── README.md │ │ ├── server.csr │ │ ├── ca.pem │ │ ├── server.pem │ │ ├── fixtures.go │ │ ├── createCerts.sh │ │ ├── ca.key │ │ └── server.key │ ├── vmoptions.go │ ├── custom_errors.go │ ├── folder.go │ ├── utils_test.go │ ├── constants.go │ ├── folder_test.go │ ├── datastore_test.go │ ├── diskmanagers │ │ └── virtualdisk.go │ └── virtualmachine_test.go ├── OWNERS ├── doc.go ├── vsphere_util_unsupported.go ├── vsphere_util_linux.go ├── testing │ └── testing.go ├── vsphere_util_windows.go └── vsphere_util_test.go ├── code-of-conduct.md ├── gce ├── OWNERS ├── doc.go ├── metrics_test.go ├── gce_alpha.go ├── gce_annotations_test.go ├── gce_firewall.go ├── support.go ├── gce_cert.go ├── gce_interfaces.go ├── gce_urlmap.go ├── gce_fake.go ├── gce_targetpool.go ├── gce_healthchecks_test.go ├── gce_zones.go ├── metrics.go └── gce_clusters.go ├── .github └── PULL_REQUEST_TEMPLATE.md ├── openstack ├── OWNERS ├── MAINTAINERS.md ├── openstack_metrics.go ├── metadata_test.go ├── openstack_routes_test.go └── openstack_client.go ├── OWNERS ├── azure ├── OWNERS ├── auth │ └── doc.go ├── cache │ └── doc.go ├── clients │ ├── doc.go │ ├── armclient │ │ ├── doc.go │ │ └── mockarmclient │ │ │ └── doc.go │ ├── vmssclient │ │ ├── doc.go │ │ ├── mockvmssclient │ │ │ └── doc.go │ │ └── interface.go │ ├── diskclient │ │ ├── doc.go │ │ ├── mockdiskclient │ │ │ ├── doc.go │ │ │ └── interface.go │ │ └── interface.go │ ├── routeclient │ │ ├── doc.go │ │ ├── mockrouteclient │ │ │ ├── doc.go │ │ │ └── interface.go │ │ ├── interface.go │ │ └── azure_routeclient_test.go │ ├── vmclient │ │ ├── doc.go │ │ ├── mockvmclient │ │ │ └── doc.go │ │ └── interface.go │ ├── subnetclient │ │ ├── doc.go │ │ ├── mocksubnetclient │ │ │ └── doc.go │ │ └── interface.go │ ├── snapshotclient │ │ ├── doc.go │ │ ├── mocksnapshotclient │ │ │ └── doc.go │ │ └── interface.go │ ├── vmsizeclient │ │ ├── doc.go │ │ ├── mockvmsizeclient │ │ │ ├── doc.go │ │ │ └── interface.go │ │ ├── interface.go │ │ └── azure_vmsizeclient_test.go │ ├── publicipclient │ │ ├── doc.go │ │ ├── mockpublicipclient │ │ │ └── doc.go │ │ └── interface.go │ ├── routetableclient │ │ ├── doc.go │ │ ├── mockroutetableclient │ │ │ ├── doc.go │ │ │ └── interface.go │ │ └── interface.go │ ├── vmssvmclient │ │ ├── doc.go │ │ ├── mockvmssvmclient │ │ │ └── doc.go │ │ └── interface.go │ ├── interfaceclient │ │ ├── doc.go │ │ ├── mockinterfaceclient │ │ │ └── doc.go │ │ └── interface.go │ ├── loadbalancerclient │ │ ├── doc.go │ │ ├── mockloadbalancerclient │ │ │ └── doc.go │ │ └── interface.go │ ├── securitygroupclient │ │ ├── doc.go │ │ ├── mocksecuritygroupclient │ │ │ └── doc.go │ │ └── interface.go │ ├── storageaccountclient │ │ ├── doc.go │ │ ├── mockstorageaccountclient │ │ │ └── doc.go │ │ └── interface.go │ ├── azure_client_config_test.go │ └── azure_client_config.go ├── metrics │ ├── doc.go │ └── azure_metrics_test.go ├── doc.go ├── main_test.go ├── retry │ └── doc.go ├── azure_utils.go ├── azure_storageaccount_test.go ├── azure_utils_test.go ├── azure_storage.go └── azure_config.go ├── aws ├── OWNERS ├── doc.go ├── aws_utils.go ├── log_handler.go ├── aws_metrics.go ├── device_allocator_test.go └── aws_instancegroups.go ├── SECURITY_CONTACTS ├── README.md └── go.mod /vsphere/vclib/fixtures/invalid.pem: -------------------------------------------------------------------------------- 1 | this is some invalid content 2 | -------------------------------------------------------------------------------- /vsphere/vclib/fixtures/README.md: -------------------------------------------------------------------------------- 1 | Keys in this directory are generated for testing purposes only. 2 | -------------------------------------------------------------------------------- /code-of-conduct.md: -------------------------------------------------------------------------------- 1 | # Kubernetes Community Code of Conduct 2 | 3 | Please refer to our [Kubernetes Community Code of Conduct](https://git.k8s.io/community/code-of-conduct.md) 4 | -------------------------------------------------------------------------------- /gce/OWNERS: -------------------------------------------------------------------------------- 1 | # See the OWNERS docs at https://go.k8s.io/owners 2 | 3 | approvers: 4 | - saad-ali 5 | - jingxu97 6 | - bowei 7 | - freehan 8 | - mrhohn 9 | - cheftako 10 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | Sorry, we do not accept changes directly against this repository. Please see 2 | CONTRIBUTING.md for information on where and how to contribute instead. 3 | -------------------------------------------------------------------------------- /openstack/OWNERS: -------------------------------------------------------------------------------- 1 | # See the OWNERS docs at https://go.k8s.io/owners 2 | 3 | approvers: 4 | - anguslees 5 | - NickrenREN 6 | - dims 7 | - FengyunPan2 8 | reviewers: 9 | - anguslees 10 | - NickrenREN 11 | - dims 12 | - FengyunPan2 13 | -------------------------------------------------------------------------------- /openstack/MAINTAINERS.md: -------------------------------------------------------------------------------- 1 | # Maintainers 2 | 3 | * [Angus Lees](https://github.com/anguslees) 4 | 5 | 6 | [![Analytics](https://kubernetes-site.appspot.com/UA-36037335-10/GitHub/staging/src/k8s.io/legacy-cloud-providers/openstack/MAINTAINERS.md?pixel)]() 7 | -------------------------------------------------------------------------------- /OWNERS: -------------------------------------------------------------------------------- 1 | # See the OWNERS docs at https://go.k8s.io/owners 2 | 3 | approvers: 4 | - mikedanese 5 | - dims 6 | - andrewsykim 7 | - cheftako 8 | - mcrute 9 | reviewers: 10 | - mikedanese 11 | - dims 12 | - andrewsykim 13 | - cheftako 14 | - mcrute 15 | labels: 16 | - sig/cloud-provider 17 | - area/cloudprovider 18 | -------------------------------------------------------------------------------- /azure/OWNERS: -------------------------------------------------------------------------------- 1 | # See the OWNERS docs at https://go.k8s.io/owners 2 | 3 | approvers: 4 | - andyzhangx 5 | - brendandburns 6 | - feiskyer 7 | - karataliu 8 | - khenidak 9 | reviewers: 10 | - andyzhangx 11 | - aramase 12 | - brendandburns 13 | - feiskyer 14 | - justaugustus 15 | - karataliu 16 | - khenidak 17 | - ritazh 18 | -------------------------------------------------------------------------------- /aws/OWNERS: -------------------------------------------------------------------------------- 1 | # See the OWNERS docs at https://go.k8s.io/owners 2 | 3 | approvers: 4 | - justinsb 5 | - zmerlynn 6 | - gnufied 7 | - jsafrane 8 | - micahhausler 9 | - mcrute 10 | - m00nf1sh 11 | reviewers: 12 | - gnufied 13 | - jsafrane 14 | - justinsb 15 | - zmerlynn 16 | - chrislovecnm 17 | - nckturner 18 | - micahhausler 19 | - m00nf1sh 20 | -------------------------------------------------------------------------------- /vsphere/OWNERS: -------------------------------------------------------------------------------- 1 | # See the OWNERS docs at https://go.k8s.io/owners 2 | 3 | approvers: 4 | - abrarshivani 5 | - baludontu 6 | - divyenpatel 7 | - imkin 8 | - frapposelli 9 | - dougm 10 | - SandeepPissay 11 | reviewers: 12 | - abrarshivani 13 | - baludontu 14 | - divyenpatel 15 | - imkin 16 | - frapposelli 17 | - dougm 18 | - SandeepPissay 19 | -------------------------------------------------------------------------------- /aws/doc.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2019 The Kubernetes 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 aws 18 | -------------------------------------------------------------------------------- /vsphere/doc.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2019 The Kubernetes 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 vsphere 18 | -------------------------------------------------------------------------------- /SECURITY_CONTACTS: -------------------------------------------------------------------------------- 1 | # Defined below are the security contacts for this repo. 2 | # 3 | # They are the contact point for the Product Security Committee to reach out 4 | # to for triaging and handling of incoming issues. 5 | # 6 | # The below names agree to abide by the 7 | # [Embargo Policy](https://git.k8s.io/security/private-distributors-list.md#embargo-policy) 8 | # and will be removed and replaced if they violate that agreement. 9 | # 10 | # DO NOT REPORT SECURITY VULNERABILITIES DIRECTLY TO THESE NAMES, FOLLOW THE 11 | # INSTRUCTIONS AT https://kubernetes.io/security/ 12 | 13 | cheftako 14 | andrewsykim 15 | dims 16 | cjcullen 17 | joelsmith 18 | liggitt 19 | philips 20 | tallclair 21 | -------------------------------------------------------------------------------- /azure/auth/doc.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2019 The Kubernetes 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 auth provides a general libraty to authorize Azure ARM clients. 18 | package auth // import "k8s.io/legacy-cloud-providers/azure/auth" 19 | -------------------------------------------------------------------------------- /azure/cache/doc.go: -------------------------------------------------------------------------------- 1 | // +build !providerless 2 | 3 | /* 4 | Copyright 2019 The Kubernetes Authors. 5 | 6 | Licensed under the Apache License, Version 2.0 (the "License"); 7 | you may not use this file except in compliance with the License. 8 | You may obtain a copy of the License at 9 | 10 | http://www.apache.org/licenses/LICENSE-2.0 11 | 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | */ 18 | 19 | // Package cache is an implementation of Azure caches. 20 | package cache // import "k8s.io/legacy-cloud-providers/azure/cache" 21 | -------------------------------------------------------------------------------- /gce/doc.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2014 The Kubernetes 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 gce is an implementation of Interface, LoadBalancer 18 | // and Instances for Google Compute Engine. 19 | package gce // import "k8s.io/legacy-cloud-providers/gce" 20 | -------------------------------------------------------------------------------- /azure/clients/doc.go: -------------------------------------------------------------------------------- 1 | // +build !providerless 2 | 3 | /* 4 | Copyright 2019 The Kubernetes Authors. 5 | 6 | Licensed under the Apache License, Version 2.0 (the "License"); 7 | you may not use this file except in compliance with the License. 8 | You may obtain a copy of the License at 9 | 10 | http://www.apache.org/licenses/LICENSE-2.0 11 | 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | */ 18 | 19 | // Package clients contains a set of Azure ARM clients. 20 | package clients // import "k8s.io/legacy-cloud-providers/azure/clients" 21 | -------------------------------------------------------------------------------- /azure/clients/armclient/doc.go: -------------------------------------------------------------------------------- 1 | // +build !providerless 2 | 3 | /* 4 | Copyright 2019 The Kubernetes Authors. 5 | 6 | Licensed under the Apache License, Version 2.0 (the "License"); 7 | you may not use this file except in compliance with the License. 8 | You may obtain a copy of the License at 9 | 10 | http://www.apache.org/licenses/LICENSE-2.0 11 | 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | */ 18 | 19 | // Package armclient implements the client for ARM. 20 | package armclient // import "k8s.io/legacy-cloud-providers/azure/clients/armclient" 21 | -------------------------------------------------------------------------------- /azure/metrics/doc.go: -------------------------------------------------------------------------------- 1 | // +build !providerless 2 | 3 | /* 4 | Copyright 2019 The Kubernetes Authors. 5 | 6 | Licensed under the Apache License, Version 2.0 (the "License"); 7 | you may not use this file except in compliance with the License. 8 | You may obtain a copy of the License at 9 | 10 | http://www.apache.org/licenses/LICENSE-2.0 11 | 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | */ 18 | 19 | // Package metrics is an implementation of Azure CloudProvider metrics. 20 | package metrics // import "k8s.io/legacy-cloud-providers/azure/metrics" 21 | -------------------------------------------------------------------------------- /azure/clients/vmssclient/doc.go: -------------------------------------------------------------------------------- 1 | // +build !providerless 2 | 3 | /* 4 | Copyright 2019 The Kubernetes Authors. 5 | 6 | Licensed under the Apache License, Version 2.0 (the "License"); 7 | you may not use this file except in compliance with the License. 8 | You may obtain a copy of the License at 9 | 10 | http://www.apache.org/licenses/LICENSE-2.0 11 | 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | */ 18 | 19 | // Package vmssclient implements the client for VMSS. 20 | package vmssclient // import "k8s.io/legacy-cloud-providers/azure/clients/vmssclient" 21 | -------------------------------------------------------------------------------- /azure/clients/diskclient/doc.go: -------------------------------------------------------------------------------- 1 | // +build !providerless 2 | 3 | /* 4 | Copyright 2020 The Kubernetes Authors. 5 | 6 | Licensed under the Apache License, Version 2.0 (the "License"); 7 | you may not use this file except in compliance with the License. 8 | You may obtain a copy of the License at 9 | 10 | http://www.apache.org/licenses/LICENSE-2.0 11 | 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | */ 18 | 19 | // Package diskclient implements the client for Disks. 20 | package diskclient // import "k8s.io/legacy-cloud-providers/azure/clients/diskclient" 21 | -------------------------------------------------------------------------------- /azure/clients/routeclient/doc.go: -------------------------------------------------------------------------------- 1 | // +build !providerless 2 | 3 | /* 4 | Copyright 2020 The Kubernetes Authors. 5 | 6 | Licensed under the Apache License, Version 2.0 (the "License"); 7 | you may not use this file except in compliance with the License. 8 | You may obtain a copy of the License at 9 | 10 | http://www.apache.org/licenses/LICENSE-2.0 11 | 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | */ 18 | 19 | // Package routeclient implements the client for Route. 20 | package routeclient // import "k8s.io/legacy-cloud-providers/azure/clients/routeclient" 21 | -------------------------------------------------------------------------------- /azure/clients/vmclient/doc.go: -------------------------------------------------------------------------------- 1 | // +build !providerless 2 | 3 | /* 4 | Copyright 2020 The Kubernetes Authors. 5 | 6 | Licensed under the Apache License, Version 2.0 (the "License"); 7 | you may not use this file except in compliance with the License. 8 | You may obtain a copy of the License at 9 | 10 | http://www.apache.org/licenses/LICENSE-2.0 11 | 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | */ 18 | 19 | // Package vmclient implements the client for VirtualMachines. 20 | package vmclient // import "k8s.io/legacy-cloud-providers/azure/clients/vmclient" 21 | -------------------------------------------------------------------------------- /azure/clients/subnetclient/doc.go: -------------------------------------------------------------------------------- 1 | // +build !providerless 2 | 3 | /* 4 | Copyright 2020 The Kubernetes Authors. 5 | 6 | Licensed under the Apache License, Version 2.0 (the "License"); 7 | you may not use this file except in compliance with the License. 8 | You may obtain a copy of the License at 9 | 10 | http://www.apache.org/licenses/LICENSE-2.0 11 | 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | */ 18 | 19 | // Package subnetclient implements the client for Subnet. 20 | package subnetclient // import "k8s.io/legacy-cloud-providers/azure/clients/subnetclient" 21 | -------------------------------------------------------------------------------- /azure/doc.go: -------------------------------------------------------------------------------- 1 | // +build !providerless 2 | 3 | /* 4 | Copyright 2019 The Kubernetes Authors. 5 | 6 | Licensed under the Apache License, Version 2.0 (the "License"); 7 | you may not use this file except in compliance with the License. 8 | You may obtain a copy of the License at 9 | 10 | http://www.apache.org/licenses/LICENSE-2.0 11 | 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | */ 18 | 19 | // Package azure is an implementation of CloudProvider Interface, LoadBalancer 20 | // and Instances for Azure. 21 | package azure // import "k8s.io/legacy-cloud-providers/azure" 22 | -------------------------------------------------------------------------------- /azure/main_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 The Kubernetes 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 azure 18 | 19 | import ( 20 | "math/rand" 21 | "os" 22 | "testing" 23 | "time" 24 | ) 25 | 26 | func TestMain(m *testing.M) { 27 | rand.Seed(time.Now().UnixNano()) 28 | os.Exit(m.Run()) 29 | } 30 | -------------------------------------------------------------------------------- /azure/clients/snapshotclient/doc.go: -------------------------------------------------------------------------------- 1 | // +build !providerless 2 | 3 | /* 4 | Copyright 2020 The Kubernetes Authors. 5 | 6 | Licensed under the Apache License, Version 2.0 (the "License"); 7 | you may not use this file except in compliance with the License. 8 | You may obtain a copy of the License at 9 | 10 | http://www.apache.org/licenses/LICENSE-2.0 11 | 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | */ 18 | 19 | // Package snapshotclient implements the client for Snapshots. 20 | package snapshotclient // import "k8s.io/legacy-cloud-providers/azure/clients/snapshotclient" 21 | -------------------------------------------------------------------------------- /azure/clients/vmsizeclient/doc.go: -------------------------------------------------------------------------------- 1 | // +build !providerless 2 | 3 | /* 4 | Copyright 2020 The Kubernetes Authors. 5 | 6 | Licensed under the Apache License, Version 2.0 (the "License"); 7 | you may not use this file except in compliance with the License. 8 | You may obtain a copy of the License at 9 | 10 | http://www.apache.org/licenses/LICENSE-2.0 11 | 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | */ 18 | 19 | // Package vmsizeclient implements the client for VirtualMachineSizes. 20 | package vmsizeclient // import "k8s.io/legacy-cloud-providers/azure/clients/vmsizeclient" 21 | -------------------------------------------------------------------------------- /azure/retry/doc.go: -------------------------------------------------------------------------------- 1 | // +build !providerless 2 | 3 | /* 4 | Copyright 2019 The Kubernetes Authors. 5 | 6 | Licensed under the Apache License, Version 2.0 (the "License"); 7 | you may not use this file except in compliance with the License. 8 | You may obtain a copy of the License at 9 | 10 | http://www.apache.org/licenses/LICENSE-2.0 11 | 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | */ 18 | 19 | // Package retry defines a general library to handle errors and retries for various 20 | // Azure clients. 21 | package retry // import "k8s.io/legacy-cloud-providers/azure/retry" 22 | -------------------------------------------------------------------------------- /azure/clients/publicipclient/doc.go: -------------------------------------------------------------------------------- 1 | // +build !providerless 2 | 3 | /* 4 | Copyright 2019 The Kubernetes Authors. 5 | 6 | Licensed under the Apache License, Version 2.0 (the "License"); 7 | you may not use this file except in compliance with the License. 8 | You may obtain a copy of the License at 9 | 10 | http://www.apache.org/licenses/LICENSE-2.0 11 | 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | */ 18 | 19 | // Package publicipclient implements the client for PublicIPAddress. 20 | package publicipclient // import "k8s.io/legacy-cloud-providers/azure/clients/publicipclient" 21 | -------------------------------------------------------------------------------- /azure/clients/routetableclient/doc.go: -------------------------------------------------------------------------------- 1 | // +build !providerless 2 | 3 | /* 4 | Copyright 2020 The Kubernetes Authors. 5 | 6 | Licensed under the Apache License, Version 2.0 (the "License"); 7 | you may not use this file except in compliance with the License. 8 | You may obtain a copy of the License at 9 | 10 | http://www.apache.org/licenses/LICENSE-2.0 11 | 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | */ 18 | 19 | // Package routetableclient implements the client for RouteTable. 20 | package routetableclient // import "k8s.io/legacy-cloud-providers/azure/clients/routetableclient" 21 | -------------------------------------------------------------------------------- /azure/clients/vmssvmclient/doc.go: -------------------------------------------------------------------------------- 1 | // +build !providerless 2 | 3 | /* 4 | Copyright 2019 The Kubernetes Authors. 5 | 6 | Licensed under the Apache License, Version 2.0 (the "License"); 7 | you may not use this file except in compliance with the License. 8 | You may obtain a copy of the License at 9 | 10 | http://www.apache.org/licenses/LICENSE-2.0 11 | 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | */ 18 | 19 | // Package vmssvmclient implements the client for VirtualMachineScaleSetVM. 20 | package vmssvmclient // import "k8s.io/legacy-cloud-providers/azure/clients/vmssvmclient" 21 | -------------------------------------------------------------------------------- /azure/clients/interfaceclient/doc.go: -------------------------------------------------------------------------------- 1 | // +build !providerless 2 | 3 | /* 4 | Copyright 2020 The Kubernetes Authors. 5 | 6 | Licensed under the Apache License, Version 2.0 (the "License"); 7 | you may not use this file except in compliance with the License. 8 | You may obtain a copy of the License at 9 | 10 | http://www.apache.org/licenses/LICENSE-2.0 11 | 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | */ 18 | 19 | // Package interfaceclient implements the client for network interfaces. 20 | package interfaceclient // import "k8s.io/legacy-cloud-providers/azure/clients/interfaceclient" 21 | -------------------------------------------------------------------------------- /azure/clients/armclient/mockarmclient/doc.go: -------------------------------------------------------------------------------- 1 | // +build !providerless 2 | 3 | /* 4 | Copyright 2019 The Kubernetes Authors. 5 | 6 | Licensed under the Apache License, Version 2.0 (the "License"); 7 | you may not use this file except in compliance with the License. 8 | You may obtain a copy of the License at 9 | 10 | http://www.apache.org/licenses/LICENSE-2.0 11 | 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | */ 18 | 19 | // Package mockarmclient implements the mock client for ARM. 20 | package mockarmclient // import "k8s.io/legacy-cloud-providers/azure/clients/armclient/mockarmclient" 21 | -------------------------------------------------------------------------------- /azure/clients/loadbalancerclient/doc.go: -------------------------------------------------------------------------------- 1 | // +build !providerless 2 | 3 | /* 4 | Copyright 2020 The Kubernetes Authors. 5 | 6 | Licensed under the Apache License, Version 2.0 (the "License"); 7 | you may not use this file except in compliance with the License. 8 | You may obtain a copy of the License at 9 | 10 | http://www.apache.org/licenses/LICENSE-2.0 11 | 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | */ 18 | 19 | // Package loadbalancerclient implements the client for LoadBalancer. 20 | package loadbalancerclient // import "k8s.io/legacy-cloud-providers/azure/clients/loadbalancerclient" 21 | -------------------------------------------------------------------------------- /azure/clients/diskclient/mockdiskclient/doc.go: -------------------------------------------------------------------------------- 1 | // +build !providerless 2 | 3 | /* 4 | Copyright 2020 The Kubernetes Authors. 5 | 6 | Licensed under the Apache License, Version 2.0 (the "License"); 7 | you may not use this file except in compliance with the License. 8 | You may obtain a copy of the License at 9 | 10 | http://www.apache.org/licenses/LICENSE-2.0 11 | 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | */ 18 | 19 | // Package mockdiskclient implements the mock client for Disks. 20 | package mockdiskclient // import "k8s.io/legacy-cloud-providers/azure/clients/diskclient/mockdiskclient" 21 | -------------------------------------------------------------------------------- /azure/clients/vmclient/mockvmclient/doc.go: -------------------------------------------------------------------------------- 1 | // +build !providerless 2 | 3 | /* 4 | Copyright 2020 The Kubernetes Authors. 5 | 6 | Licensed under the Apache License, Version 2.0 (the "License"); 7 | you may not use this file except in compliance with the License. 8 | You may obtain a copy of the License at 9 | 10 | http://www.apache.org/licenses/LICENSE-2.0 11 | 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | */ 18 | 19 | // Package mockvmclient implements the mock client for VirtualMachines. 20 | package mockvmclient // import "k8s.io/legacy-cloud-providers/azure/clients/vmclient/mockvmclient" 21 | -------------------------------------------------------------------------------- /azure/clients/vmssclient/mockvmssclient/doc.go: -------------------------------------------------------------------------------- 1 | // +build !providerless 2 | 3 | /* 4 | Copyright 2019 The Kubernetes Authors. 5 | 6 | Licensed under the Apache License, Version 2.0 (the "License"); 7 | you may not use this file except in compliance with the License. 8 | You may obtain a copy of the License at 9 | 10 | http://www.apache.org/licenses/LICENSE-2.0 11 | 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | */ 18 | 19 | // Package mockvmssclient implements the mock client for VMSS. 20 | package mockvmssclient // import "k8s.io/legacy-cloud-providers/azure/clients/vmssclient/mockvmssclient" 21 | -------------------------------------------------------------------------------- /azure/clients/routeclient/mockrouteclient/doc.go: -------------------------------------------------------------------------------- 1 | // +build !providerless 2 | 3 | /* 4 | Copyright 2020 The Kubernetes Authors. 5 | 6 | Licensed under the Apache License, Version 2.0 (the "License"); 7 | you may not use this file except in compliance with the License. 8 | You may obtain a copy of the License at 9 | 10 | http://www.apache.org/licenses/LICENSE-2.0 11 | 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | */ 18 | 19 | // Package mockrouteclient implements the mock client for Route. 20 | package mockrouteclient // import "k8s.io/legacy-cloud-providers/azure/clients/routeclient/mockrouteclient" 21 | -------------------------------------------------------------------------------- /azure/clients/securitygroupclient/doc.go: -------------------------------------------------------------------------------- 1 | // +build !providerless 2 | 3 | /* 4 | Copyright 2020 The Kubernetes Authors. 5 | 6 | Licensed under the Apache License, Version 2.0 (the "License"); 7 | you may not use this file except in compliance with the License. 8 | You may obtain a copy of the License at 9 | 10 | http://www.apache.org/licenses/LICENSE-2.0 11 | 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | */ 18 | 19 | // Package securitygroupclient implements the client for SecurityGroups. 20 | package securitygroupclient // import "k8s.io/legacy-cloud-providers/azure/clients/securitygroupclient" 21 | -------------------------------------------------------------------------------- /azure/clients/storageaccountclient/doc.go: -------------------------------------------------------------------------------- 1 | // +build !providerless 2 | 3 | /* 4 | Copyright 2020 The Kubernetes Authors. 5 | 6 | Licensed under the Apache License, Version 2.0 (the "License"); 7 | you may not use this file except in compliance with the License. 8 | You may obtain a copy of the License at 9 | 10 | http://www.apache.org/licenses/LICENSE-2.0 11 | 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | */ 18 | 19 | // Package storageaccountclient implements the client for StorageAccounts. 20 | package storageaccountclient // import "k8s.io/legacy-cloud-providers/azure/clients/storageaccountclient" 21 | -------------------------------------------------------------------------------- /azure/clients/subnetclient/mocksubnetclient/doc.go: -------------------------------------------------------------------------------- 1 | // +build !providerless 2 | 3 | /* 4 | Copyright 2020 The Kubernetes Authors. 5 | 6 | Licensed under the Apache License, Version 2.0 (the "License"); 7 | you may not use this file except in compliance with the License. 8 | You may obtain a copy of the License at 9 | 10 | http://www.apache.org/licenses/LICENSE-2.0 11 | 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | */ 18 | 19 | // Package mocksubnetclient implements the mock client for Subnet. 20 | package mocksubnetclient // import "k8s.io/legacy-cloud-providers/azure/clients/subnetclient/mocksubnetclient" 21 | -------------------------------------------------------------------------------- /vsphere/vsphere_util_unsupported.go: -------------------------------------------------------------------------------- 1 | // +build !providerless 2 | // +build !windows,!linux 3 | 4 | /* 5 | Copyright 2018 The Kubernetes Authors. 6 | 7 | Licensed under the Apache License, Version 2.0 (the "License"); 8 | you may not use this file except in compliance with the License. 9 | You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | 13 | Unless required by applicable law or agreed to in writing, software 14 | distributed under the License is distributed on an "AS IS" BASIS, 15 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | See the License for the specific language governing permissions and 17 | limitations under the License. 18 | */ 19 | 20 | package vsphere 21 | 22 | import "fmt" 23 | 24 | func getRawUUID() (string, error) { 25 | return "", fmt.Errorf("Retrieving VM UUID on this build is not implemented.") 26 | } 27 | -------------------------------------------------------------------------------- /azure/clients/snapshotclient/mocksnapshotclient/doc.go: -------------------------------------------------------------------------------- 1 | // +build !providerless 2 | 3 | /* 4 | Copyright 2020 The Kubernetes Authors. 5 | 6 | Licensed under the Apache License, Version 2.0 (the "License"); 7 | you may not use this file except in compliance with the License. 8 | You may obtain a copy of the License at 9 | 10 | http://www.apache.org/licenses/LICENSE-2.0 11 | 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | */ 18 | 19 | // Package mocksnapshotclient implements the mock client for Snapshots. 20 | package mocksnapshotclient // import "k8s.io/legacy-cloud-providers/azure/clients/snapshotclient/mocksnapshotclient" 21 | -------------------------------------------------------------------------------- /azure/clients/vmssvmclient/mockvmssvmclient/doc.go: -------------------------------------------------------------------------------- 1 | // +build !providerless 2 | 3 | /* 4 | Copyright 2019 The Kubernetes Authors. 5 | 6 | Licensed under the Apache License, Version 2.0 (the "License"); 7 | you may not use this file except in compliance with the License. 8 | You may obtain a copy of the License at 9 | 10 | http://www.apache.org/licenses/LICENSE-2.0 11 | 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | */ 18 | 19 | // Package mockvmssvmclient implements the mock client for VirtualMachineScaleSetVM. 20 | package mockvmssvmclient // import "k8s.io/legacy-cloud-providers/azure/clients/vmssvmclient/mockvmssvmclient" 21 | -------------------------------------------------------------------------------- /azure/clients/publicipclient/mockpublicipclient/doc.go: -------------------------------------------------------------------------------- 1 | // +build !providerless 2 | 3 | /* 4 | Copyright 2020 The Kubernetes Authors. 5 | 6 | Licensed under the Apache License, Version 2.0 (the "License"); 7 | you may not use this file except in compliance with the License. 8 | You may obtain a copy of the License at 9 | 10 | http://www.apache.org/licenses/LICENSE-2.0 11 | 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | */ 18 | 19 | // Package mockpublicipclient implements the mock client for PublicIPAddress. 20 | package mockpublicipclient // import "k8s.io/legacy-cloud-providers/azure/clients/publicipclient/mockpublicipclient" 21 | -------------------------------------------------------------------------------- /azure/clients/routetableclient/mockroutetableclient/doc.go: -------------------------------------------------------------------------------- 1 | // +build !providerless 2 | 3 | /* 4 | Copyright 2020 The Kubernetes Authors. 5 | 6 | Licensed under the Apache License, Version 2.0 (the "License"); 7 | you may not use this file except in compliance with the License. 8 | You may obtain a copy of the License at 9 | 10 | http://www.apache.org/licenses/LICENSE-2.0 11 | 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | */ 18 | 19 | // Package mockroutetableclient implements the mock client for RouteTable. 20 | package mockroutetableclient // import "k8s.io/legacy-cloud-providers/azure/clients/routetableclient/mockroutetableclient" 21 | -------------------------------------------------------------------------------- /azure/clients/vmsizeclient/mockvmsizeclient/doc.go: -------------------------------------------------------------------------------- 1 | // +build !providerless 2 | 3 | /* 4 | Copyright 2020 The Kubernetes Authors. 5 | 6 | Licensed under the Apache License, Version 2.0 (the "License"); 7 | you may not use this file except in compliance with the License. 8 | You may obtain a copy of the License at 9 | 10 | http://www.apache.org/licenses/LICENSE-2.0 11 | 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | */ 18 | 19 | // Package mockvmsizeclient implements the mock client for VirtualMachineSizes. 20 | package mockvmsizeclient // import "k8s.io/legacy-cloud-providers/azure/clients/virtualmachinesizeclient/mockvmsizeclient" 21 | -------------------------------------------------------------------------------- /azure/clients/interfaceclient/mockinterfaceclient/doc.go: -------------------------------------------------------------------------------- 1 | // +build !providerless 2 | 3 | /* 4 | Copyright 2020 The Kubernetes Authors. 5 | 6 | Licensed under the Apache License, Version 2.0 (the "License"); 7 | you may not use this file except in compliance with the License. 8 | You may obtain a copy of the License at 9 | 10 | http://www.apache.org/licenses/LICENSE-2.0 11 | 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | */ 18 | 19 | // Package mockinterfaceclient implements the mock client for network interfaces. 20 | package mockinterfaceclient // import "k8s.io/legacy-cloud-providers/azure/clients/interfaceclient/mockinterfaceclient" 21 | -------------------------------------------------------------------------------- /vsphere/vclib/vmoptions.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2016 The Kubernetes 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 vclib 18 | 19 | import ( 20 | "github.com/vmware/govmomi/object" 21 | ) 22 | 23 | // VMOptions provides helper objects for provisioning volume with SPBM Policy 24 | type VMOptions struct { 25 | VMFolder *Folder 26 | VMResourcePool *object.ResourcePool 27 | } 28 | -------------------------------------------------------------------------------- /azure/clients/loadbalancerclient/mockloadbalancerclient/doc.go: -------------------------------------------------------------------------------- 1 | // +build !providerless 2 | 3 | /* 4 | Copyright 2020 The Kubernetes Authors. 5 | 6 | Licensed under the Apache License, Version 2.0 (the "License"); 7 | you may not use this file except in compliance with the License. 8 | You may obtain a copy of the License at 9 | 10 | http://www.apache.org/licenses/LICENSE-2.0 11 | 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | */ 18 | 19 | // Package mockloadbalancerclient implements the mock client for LoadBalancer. 20 | package mockloadbalancerclient // import "k8s.io/legacy-cloud-providers/azure/clients/loadbalancerclient/mockloadbalancerclient" 21 | -------------------------------------------------------------------------------- /azure/clients/securitygroupclient/mocksecuritygroupclient/doc.go: -------------------------------------------------------------------------------- 1 | // +build !providerless 2 | 3 | /* 4 | Copyright 2020 The Kubernetes Authors. 5 | 6 | Licensed under the Apache License, Version 2.0 (the "License"); 7 | you may not use this file except in compliance with the License. 8 | You may obtain a copy of the License at 9 | 10 | http://www.apache.org/licenses/LICENSE-2.0 11 | 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | */ 18 | 19 | // Package mocksecuritygroupclient implements the mock client for SecurityGroups. 20 | package mocksecuritygroupclient // import "k8s.io/legacy-cloud-providers/azure/clients/securitygroupclient/mocksecuritygroupclient" 21 | -------------------------------------------------------------------------------- /azure/clients/storageaccountclient/mockstorageaccountclient/doc.go: -------------------------------------------------------------------------------- 1 | // +build !providerless 2 | 3 | /* 4 | Copyright 2020 The Kubernetes Authors. 5 | 6 | Licensed under the Apache License, Version 2.0 (the "License"); 7 | you may not use this file except in compliance with the License. 8 | You may obtain a copy of the License at 9 | 10 | http://www.apache.org/licenses/LICENSE-2.0 11 | 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | */ 18 | 19 | // Package mockstorageaccountclient implements the mock client for StorageAccounts. 20 | package mockstorageaccountclient // import "k8s.io/legacy-cloud-providers/azure/clients/storageaccountclient/mockstorageaccountclient" 21 | -------------------------------------------------------------------------------- /vsphere/vsphere_util_linux.go: -------------------------------------------------------------------------------- 1 | // +build !providerless 2 | // +build linux 3 | 4 | /* 5 | Copyright 2018 The Kubernetes Authors. 6 | 7 | Licensed under the Apache License, Version 2.0 (the "License"); 8 | you may not use this file except in compliance with the License. 9 | You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | 13 | Unless required by applicable law or agreed to in writing, software 14 | distributed under the License is distributed on an "AS IS" BASIS, 15 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | See the License for the specific language governing permissions and 17 | limitations under the License. 18 | */ 19 | 20 | package vsphere 21 | 22 | import ( 23 | "io/ioutil" 24 | ) 25 | 26 | const UUIDPath = "/sys/class/dmi/id/product_serial" 27 | 28 | func getRawUUID() (string, error) { 29 | id, err := ioutil.ReadFile(UUIDPath) 30 | if err != nil { 31 | return "", err 32 | } 33 | return string(id), nil 34 | } 35 | -------------------------------------------------------------------------------- /gce/metrics_test.go: -------------------------------------------------------------------------------- 1 | // +build !providerless 2 | 3 | /* 4 | Copyright 2017 The Kubernetes Authors. 5 | 6 | Licensed under the Apache License, Version 2.0 (the "License"); 7 | you may not use this file except in compliance with the License. 8 | You may obtain a copy of the License at 9 | 10 | http://www.apache.org/licenses/LICENSE-2.0 11 | 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | */ 18 | 19 | package gce 20 | 21 | import ( 22 | "testing" 23 | 24 | "github.com/stretchr/testify/assert" 25 | ) 26 | 27 | func TestVerifyMetricLabelCardinality(t *testing.T) { 28 | mc := newGenericMetricContext("foo", "get", "us-central1", "", "alpha") 29 | assert.Len(t, mc.attributes, len(metricLabels), "cardinalities of labels and values must match") 30 | } 31 | -------------------------------------------------------------------------------- /vsphere/testing/testing.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2019 The Kubernetes 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 testing 18 | 19 | import ( 20 | // test dependencies for k8s.io/legacy-cloud-providers/vsphere 21 | // import this package to vendor test dependencies since go modules does not 22 | // vendor transitive test dependencies 23 | _ "github.com/vmware/govmomi/lookup/simulator" 24 | _ "github.com/vmware/govmomi/simulator" 25 | _ "github.com/vmware/govmomi/sts/simulator" 26 | _ "github.com/vmware/govmomi/vapi/simulator" 27 | ) 28 | -------------------------------------------------------------------------------- /aws/aws_utils.go: -------------------------------------------------------------------------------- 1 | // +build !providerless 2 | 3 | /* 4 | Copyright 2014 The Kubernetes Authors. 5 | 6 | Licensed under the Apache License, Version 2.0 (the "License"); 7 | you may not use this file except in compliance with the License. 8 | You may obtain a copy of the License at 9 | 10 | http://www.apache.org/licenses/LICENSE-2.0 11 | 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | */ 18 | 19 | package aws 20 | 21 | import ( 22 | "github.com/aws/aws-sdk-go/aws" 23 | 24 | "k8s.io/apimachinery/pkg/util/sets" 25 | ) 26 | 27 | func stringSetToPointers(in sets.String) []*string { 28 | if in == nil { 29 | return nil 30 | } 31 | out := make([]*string, 0, len(in)) 32 | for k := range in { 33 | out = append(out, aws.String(k)) 34 | } 35 | return out 36 | } 37 | 38 | func stringSetFromPointers(in []*string) sets.String { 39 | if in == nil { 40 | return nil 41 | } 42 | out := sets.NewString() 43 | for i := range in { 44 | out.Insert(aws.StringValue(in[i])) 45 | } 46 | return out 47 | } 48 | -------------------------------------------------------------------------------- /vsphere/vsphere_util_windows.go: -------------------------------------------------------------------------------- 1 | // +build !providerless 2 | // +build windows 3 | 4 | /* 5 | Copyright 2018 The Kubernetes Authors. 6 | 7 | Licensed under the Apache License, Version 2.0 (the "License"); 8 | you may not use this file except in compliance with the License. 9 | You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | 13 | Unless required by applicable law or agreed to in writing, software 14 | distributed under the License is distributed on an "AS IS" BASIS, 15 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | See the License for the specific language governing permissions and 17 | limitations under the License. 18 | */ 19 | 20 | package vsphere 21 | 22 | import ( 23 | "fmt" 24 | "os/exec" 25 | "strings" 26 | ) 27 | 28 | func getRawUUID() (string, error) { 29 | result, err := exec.Command("wmic", "bios", "get", "serialnumber").Output() 30 | if err != nil { 31 | return "", err 32 | } 33 | lines := strings.FieldsFunc(string(result), func(r rune) bool { 34 | switch r { 35 | case '\n', '\r': 36 | return true 37 | default: 38 | return false 39 | } 40 | }) 41 | if len(lines) != 2 { 42 | return "", fmt.Errorf("received unexpected value retrieving vm uuid: %q", string(result)) 43 | } 44 | return lines[1], nil 45 | } 46 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # legacy-cloud-providers 2 | 3 | This repository hosts the legacy cloud providers that were previously hosted under 4 | `k8s.io/kubernetes/pkg/cloudprovider/providers`. Out-of-tree cloud providers can consume 5 | packages in this repo to support legacy implementations of their Kubernetes cloud provider. 6 | 7 | **Note:** go-get or vendor this package as `k8s.io/legacy-cloud-providers`. 8 | 9 | ## Purpose 10 | 11 | To be consumed by out-of-tree cloud providers that wish to support legacy behavior 12 | from their in-tree equivalents. 13 | 14 | ## Compatibility 15 | 16 | The legacy providers here follow the same compatibility rules as cloud providers that 17 | were previously in `k8s.io/kubernetes/pkg/cloudprovider/providers`. 18 | 19 | ## Where does it come from? 20 | 21 | `legacy-cloud-providers` is synced from https://github.com/kubernetes/kubernetes/blob/master/staging/src/k8s.io/legacy-cloud-providers. 22 | Code changes are made in that location, merged into `k8s.io/kubernetes` and later synced here. 23 | 24 | ## Things you should NOT do 25 | 26 | 1. Add a new cloud provider here. 27 | 2. Directly modify anything under this repo. Those are driven from `k8s.io/kubernetes/staging/src/k8s.io/legacy-cloud-providers`. 28 | sig-cloudprovider. 29 | 3. Add new features/integrations to a cloud provider in this repo. Changes sync here should only be incremental bug fixes. 30 | -------------------------------------------------------------------------------- /azure/metrics/azure_metrics_test.go: -------------------------------------------------------------------------------- 1 | // +build !providerless 2 | 3 | /* 4 | Copyright 2017 The Kubernetes Authors. 5 | 6 | Licensed under the Apache License, Version 2.0 (the "License"); 7 | you may not use this file except in compliance with the License. 8 | You may obtain a copy of the License at 9 | 10 | http://www.apache.org/licenses/LICENSE-2.0 11 | 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | */ 18 | 19 | package metrics 20 | 21 | import ( 22 | "testing" 23 | 24 | "github.com/stretchr/testify/assert" 25 | ) 26 | 27 | func TestAzureMetricLabelCardinality(t *testing.T) { 28 | mc := NewMetricContext("test", "create", "resource_group", "subscription_id", "source") 29 | assert.Len(t, mc.attributes, len(metricLabels), "cardinalities of labels and values must match") 30 | } 31 | 32 | func TestAzureMetricLabelPrefix(t *testing.T) { 33 | mc := NewMetricContext("prefix", "request", "resource_group", "subscription_id", "source") 34 | found := false 35 | for _, attribute := range mc.attributes { 36 | if attribute == "prefix_request" { 37 | found = true 38 | } 39 | } 40 | assert.True(t, found, "request label must be prefixed") 41 | } 42 | -------------------------------------------------------------------------------- /vsphere/vclib/custom_errors.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2016 The Kubernetes 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 vclib 18 | 19 | import "errors" 20 | 21 | // Error Messages 22 | const ( 23 | FileAlreadyExistErrMsg = "File requested already exist" 24 | NoDiskUUIDFoundErrMsg = "No disk UUID found" 25 | NoDevicesFoundErrMsg = "No devices found" 26 | DiskNotFoundErrMsg = "No vSphere disk ID found" 27 | InvalidVolumeOptionsErrMsg = "VolumeOptions verification failed" 28 | NoVMFoundErrMsg = "No VM found" 29 | ) 30 | 31 | // Error constants 32 | var ( 33 | ErrFileAlreadyExist = errors.New(FileAlreadyExistErrMsg) 34 | ErrNoDiskUUIDFound = errors.New(NoDiskUUIDFoundErrMsg) 35 | ErrNoDevicesFound = errors.New(NoDevicesFoundErrMsg) 36 | ErrNoDiskIDFound = errors.New(DiskNotFoundErrMsg) 37 | ErrInvalidVolumeOptions = errors.New(InvalidVolumeOptionsErrMsg) 38 | ErrNoVMFound = errors.New(NoVMFoundErrMsg) 39 | ) 40 | -------------------------------------------------------------------------------- /vsphere/vclib/folder.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2016 The Kubernetes 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 vclib 18 | 19 | import ( 20 | "context" 21 | 22 | "github.com/vmware/govmomi/object" 23 | "k8s.io/klog" 24 | ) 25 | 26 | // Folder extends the govmomi Folder object 27 | type Folder struct { 28 | *object.Folder 29 | Datacenter *Datacenter 30 | } 31 | 32 | // GetVirtualMachines returns list of VirtualMachine inside a folder. 33 | func (folder *Folder) GetVirtualMachines(ctx context.Context) ([]*VirtualMachine, error) { 34 | vmFolders, err := folder.Children(ctx) 35 | if err != nil { 36 | klog.Errorf("Failed to get children from Folder: %s. err: %+v", folder.InventoryPath, err) 37 | return nil, err 38 | } 39 | var vmObjList []*VirtualMachine 40 | for _, vmFolder := range vmFolders { 41 | if vmFolder.Reference().Type == VirtualMachineType { 42 | vmObj := VirtualMachine{object.NewVirtualMachine(folder.Client(), vmFolder.Reference()), folder.Datacenter} 43 | vmObjList = append(vmObjList, &vmObj) 44 | } 45 | } 46 | return vmObjList, nil 47 | } 48 | -------------------------------------------------------------------------------- /azure/clients/vmsizeclient/interface.go: -------------------------------------------------------------------------------- 1 | // +build !providerless 2 | 3 | /* 4 | Copyright 2020 The Kubernetes Authors. 5 | 6 | Licensed under the Apache License, Version 2.0 (the "License"); 7 | you may not use this file except in compliance with the License. 8 | You may obtain a copy of the License at 9 | 10 | http://www.apache.org/licenses/LICENSE-2.0 11 | 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | */ 18 | 19 | package vmsizeclient 20 | 21 | import ( 22 | "context" 23 | 24 | "github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2019-07-01/compute" 25 | "k8s.io/legacy-cloud-providers/azure/retry" 26 | ) 27 | 28 | const ( 29 | // APIVersion is the API version for compute. 30 | APIVersion = "2019-07-01" 31 | ) 32 | 33 | // Interface is the client interface for VirtualMachineSizes. 34 | // Don't forget to run the following command to generate the mock client: 35 | // mockgen -source=$GOPATH/src/k8s.io/kubernetes/staging/src/k8s.io/legacy-cloud-providers/azure/clients/vmsizeclient/interface.go -package=mockvmsizeclient Interface > $GOPATH/src/k8s.io/kubernetes/staging/src/k8s.io/legacy-cloud-providers/azure/clients/vmsizeclient/mockvmsizeclient/interface.go 36 | type Interface interface { 37 | // List gets compute.VirtualMachineSizeListResult. 38 | List(ctx context.Context, location string) (result compute.VirtualMachineSizeListResult, rerr *retry.Error) 39 | } 40 | -------------------------------------------------------------------------------- /aws/log_handler.go: -------------------------------------------------------------------------------- 1 | // +build !providerless 2 | 3 | /* 4 | Copyright 2015 The Kubernetes Authors. 5 | 6 | Licensed under the Apache License, Version 2.0 (the "License"); 7 | you may not use this file except in compliance with the License. 8 | You may obtain a copy of the License at 9 | 10 | http://www.apache.org/licenses/LICENSE-2.0 11 | 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | */ 18 | 19 | package aws 20 | 21 | import ( 22 | "github.com/aws/aws-sdk-go/aws/request" 23 | "k8s.io/klog" 24 | ) 25 | 26 | // Handler for aws-sdk-go that logs all requests 27 | func awsHandlerLogger(req *request.Request) { 28 | service, name := awsServiceAndName(req) 29 | klog.V(4).Infof("AWS request: %s %s", service, name) 30 | } 31 | 32 | func awsSendHandlerLogger(req *request.Request) { 33 | service, name := awsServiceAndName(req) 34 | klog.V(4).Infof("AWS API Send: %s %s %v %v", service, name, req.Operation, req.Params) 35 | } 36 | 37 | func awsValidateResponseHandlerLogger(req *request.Request) { 38 | service, name := awsServiceAndName(req) 39 | klog.V(4).Infof("AWS API ValidateResponse: %s %s %v %v %s", service, name, req.Operation, req.Params, req.HTTPResponse.Status) 40 | } 41 | 42 | func awsServiceAndName(req *request.Request) (string, string) { 43 | service := req.ClientInfo.ServiceName 44 | 45 | name := "?" 46 | if req.Operation != nil { 47 | name = req.Operation.Name 48 | } 49 | return service, name 50 | } 51 | -------------------------------------------------------------------------------- /vsphere/vclib/fixtures/server.csr: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE REQUEST----- 2 | MIIEtTCCAp0CAQAwQzELMAkGA1UEBhMCVVMxCzAJBgNVBAgMAkNBMRMwEQYDVQQK 3 | DApBY21lLCBJbmMuMRIwEAYDVQQDDAlsb2NhbGhvc3QwggIiMA0GCSqGSIb3DQEB 4 | AQUAA4ICDwAwggIKAoICAQCVkk5HMKNvMXVJoJcUfKK252UT6rdnlsaFLZOlcbp3 5 | otqiq3A2jhQLeL5Ocyd22s/ak2RX9liK+ynV8fP3YWoUBP5elhwbykubiIvSTRS5 6 | 85Z0s9NfzscImMpnivt+bOy3KOoriy/0jfJ7WMqLRUTUEusXUpW8QT/U9cK6DrwQ 7 | E/9oXTr669yvqjyFsxjOB0pLOFFib0LeQZxrA2h+oAP8qT/Of6kyTgGWjLhSC1cV 8 | eCPZsSeZUT61FbIu/b5M42WYuddoFbf8y9m0oLeYizYob7poE25jw91bNa8y2nfS 9 | v+JuCcfO4wq29cnldGFNpJPhBhc1sbBvVshXXKWdfzN1c8RCS5hNANy1phAJ7RFe 10 | 3Uj0WneBVBHHJMz7Qh61uxTST1W8HBDTuaBTxGKTcPFWd9u4lj/BEScRFOSC/qiO 11 | 1HCKzOsYhjnHfql5GzfQKpEy/e4m2oL8VTqcJBsfHCyxDIH+6Y3ovttymxAUPJ14 12 | r3mG9FDLq1va/+8xzDswyjmRIVQeOgvllzgM5vCKqz6nsXtLRYgkwHMk5yOaAIzO 13 | BnsmZztsyaubjcYvM5pUsiO49VWk6ntiAn+WpF/sreFlesx1peQKbTVovwvn137d 14 | V92Oncce+ZikKHxtz4qOz+dH1Fz7Ykor8fXcsfdbkKvwWdz8U/pOBu+83CxBXTWA 15 | bwIDAQABoC0wKwYJKoZIhvcNAQkOMR4wHDAaBgNVHREEEzARgglsb2NhbGhvc3SH 16 | BH8AAAEwDQYJKoZIhvcNAQELBQADggIBADgJfI3xRKlOInZQjg+afz+L477IiFmP 17 | Pf0qwO/EqBkCmbDbmvXpXi/y9Ffh6bMx2naN873nW3k1uVG2W0O4Bl7di9PkmRxY 18 | ktcWY+CaxDT5+Y3LmrqICgrZmELTuV5G8xX2/7bpdEtY4sWpoOeOun+CeGTCeUGx 19 | sGxOWrhydYwrkowupPthYreIIBBPHWl2gEw/m+Y7aJZGtKnDD9eCbF6RxmXRWHDu 20 | 0Ly+F3veXbht9LjKPFsgfsogo33Nl8+W1LCActKNY7NMDdGkc+RqaTyxhYEwomui 21 | N1NDOW1qHqSyp2RC13cXokfLL58WGXS6PpNhSln9u4ZG9a+TY+vw1qC//1CyTicY 22 | ylyEn2qfqTSG3W7T/u6ZTL0MpMjFv8VigpffJcFDjq6lVH8LyTniSXdCREy78jAo 23 | 8O/2tzJtWrar8bbeN7KCwVcJVaK15a1GWZmo5Ei33U/2Tm+UyRbWL8eISO2Hs3WM 24 | 90aFPaHfqKpiPsJrnnOm270lZclgqEtpsyuLsAClqxytCYPw4zTa6WOfDJtmVUrT 25 | 1fvMjqwzvs7jbNrgfkwSxXiABwTMQQWeAtuSO+zZH4Ms10qyANoh4FFi/oS3dRKQ 26 | 0kdu7AsJqnou9q9HWq1WCTqMcyNE0KPHuo4xhtOlWoGbsugTs7XBml30D7bKJVfG 27 | PazsY1b0/cx7 28 | -----END CERTIFICATE REQUEST----- 29 | -------------------------------------------------------------------------------- /azure/clients/routeclient/interface.go: -------------------------------------------------------------------------------- 1 | // +build !providerless 2 | 3 | /* 4 | Copyright 2020 The Kubernetes Authors. 5 | 6 | Licensed under the Apache License, Version 2.0 (the "License"); 7 | you may not use this file except in compliance with the License. 8 | You may obtain a copy of the License at 9 | 10 | http://www.apache.org/licenses/LICENSE-2.0 11 | 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | */ 18 | 19 | package routeclient 20 | 21 | import ( 22 | "context" 23 | 24 | "github.com/Azure/azure-sdk-for-go/services/network/mgmt/2019-06-01/network" 25 | "k8s.io/legacy-cloud-providers/azure/retry" 26 | ) 27 | 28 | const ( 29 | // APIVersion is the API version for network. 30 | APIVersion = "2019-06-01" 31 | ) 32 | 33 | // Interface is the client interface for Route. 34 | // Don't forget to run the following command to generate the mock client: 35 | // mockgen -source=$GOPATH/src/k8s.io/kubernetes/staging/src/k8s.io/legacy-cloud-providers/azure/clients/routeclient/interface.go -package=mockrouteclient Interface > $GOPATH/src/k8s.io/kubernetes/staging/src/k8s.io/legacy-cloud-providers/azure/clients/routeclient/mockrouteclient/interface.go 36 | type Interface interface { 37 | // CreateOrUpdate creates or updates a Route. 38 | CreateOrUpdate(ctx context.Context, resourceGroupName string, routeTableName string, routeName string, routeParameters network.Route, etag string) *retry.Error 39 | 40 | // Delete deletes a Route by name. 41 | Delete(ctx context.Context, resourceGroupName string, routeTableName string, routeName string) *retry.Error 42 | } 43 | -------------------------------------------------------------------------------- /azure/clients/routetableclient/interface.go: -------------------------------------------------------------------------------- 1 | // +build !providerless 2 | 3 | /* 4 | Copyright 2020 The Kubernetes Authors. 5 | 6 | Licensed under the Apache License, Version 2.0 (the "License"); 7 | you may not use this file except in compliance with the License. 8 | You may obtain a copy of the License at 9 | 10 | http://www.apache.org/licenses/LICENSE-2.0 11 | 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | */ 18 | 19 | package routetableclient 20 | 21 | import ( 22 | "context" 23 | 24 | "github.com/Azure/azure-sdk-for-go/services/network/mgmt/2019-06-01/network" 25 | "k8s.io/legacy-cloud-providers/azure/retry" 26 | ) 27 | 28 | const ( 29 | // APIVersion is the API version for network. 30 | APIVersion = "2019-06-01" 31 | ) 32 | 33 | // Interface is the client interface for RouteTable. 34 | // Don't forget to run the following command to generate the mock client: 35 | // mockgen -source=$GOPATH/src/k8s.io/kubernetes/staging/src/k8s.io/legacy-cloud-providers/azure/clients/routetableclient/interface.go -package=mockroutetableclient Interface > $GOPATH/src/k8s.io/kubernetes/staging/src/k8s.io/legacy-cloud-providers/azure/clients/routetableclient/mockroutetableclient/interface.go 36 | type Interface interface { 37 | // Get gets a RouteTable. 38 | Get(ctx context.Context, resourceGroupName string, routeTableName string, expand string) (result network.RouteTable, rerr *retry.Error) 39 | 40 | // CreateOrUpdate creates or updates a RouteTable. 41 | CreateOrUpdate(ctx context.Context, resourceGroupName string, routeTableName string, parameters network.RouteTable, etag string) *retry.Error 42 | } 43 | -------------------------------------------------------------------------------- /vsphere/vclib/fixtures/ca.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIE/jCCAuYCCQDRJ2qPhdmG0DANBgkqhkiG9w0BAQsFADBAMQswCQYDVQQGEwJV 3 | UzELMAkGA1UECAwCQ0ExEzARBgNVBAoMCkFjbWUsIEluYy4xDzANBgNVBAMMBnNv 4 | bWVDQTAgFw0xODA2MDgxMzM5MjFaGA8yMjE4MDQyMTEzMzkyMVowQDELMAkGA1UE 5 | BhMCVVMxCzAJBgNVBAgMAkNBMRMwEQYDVQQKDApBY21lLCBJbmMuMQ8wDQYDVQQD 6 | DAZzb21lQ0EwggIiMA0GCSqGSIb3DQEBAQUAA4ICDwAwggIKAoICAQDgIovAI/Ax 7 | QhVoaG9nEuZcTMN+UgtVoYJlFEFt9i5x/KzKVP8ko8yUqzc5E1VbVx2JbXP9lSUC 8 | U356qrjRZJVAmotR5eW2x9nB6Z0WZ/dIBYi72/3AjmaEtAkyHZc8o0gsIGGsRP8A 9 | 0tU9s5slQW8Zq+lH1dVdNewtS+4JH6hKkO9BjKdYonl0DCopoXHcYIQUCbR02dLO 10 | WJCvMoU4TQNQzEVAfku3YRgsevJr4rhm1htfmcpf75P1HmlmzSemqZNBL+sh9+/a 11 | FPz20p2o/P8wK3nHCaOwA7a6uLk75ZotQiR/wF1+ZUC6wT/m/anfHcwfStRdo0+D 12 | sWouPVydtzAeqq3c+ZWX1Vkg2Q9ucceK5rbUY2oMBn8b+8/z+GVfAh4Tx3pg+xI+ 13 | bg0QfQq77KTRMQvpCQYUxhinILDUE1gZd37O9/XGNm0atxWIeF6zG6/vWcZ0ls1K 14 | LvPCRhfJ1IoI2eMn46rKKnm5QL4ObJ2pwlNAtxlbk5s194Hw8vPpS5WJ0x9+Hx68 15 | TXcvrRxLnBnJlaF6syoH4j+5ES3TmCKQK2UlU6iyG4tLRCNsr8g1gJIUEmO3TGvB 16 | NvDXdJCwSGS1Bh2pMdoMFaLq6H6lxj2awXWNkn4YAQ9hwvMrejb+QTqDT1NndAN4 17 | /1sQNOWUv6YizgkaJYY0L94aMZ/LICd+YQIDAQABMA0GCSqGSIb3DQEBCwUAA4IC 18 | AQBYBRH/q3gB4gEiOAUl9HbnoUb7MznZ0uQTH7fUYqr66ceZkg9w1McbwiAeZAaY 19 | qQWwr3u4A8/Bg8csE2yQTsXeA33FP3Q6obyuYn4q7e++4+9SLkbSSQfbB67pGUK5 20 | /pal6ULrLGzs69fbL1tOaA/VKQJndg3N9cftyiIUWTzHDop8SLmIobWVRtPQHf00 21 | oKq8loakyluQdxQxnGdl7vMXwSpSpIH84TOdy2JN90MzVLgOz55sb/wRYfhClNFD 22 | +1sb2V4nL2w1kXaO2UVPzk7qpG5FE54JPvvN67Ec4JjMSnGo8l3dJ9jGEmgBIML3 23 | l1onrti2HStSs1vR4Ax0xok08okRlrGA4FqQiSx853T5uLa/JLmWfLKg9ixR4ZV+ 24 | dF+2ZrFwDLZUr4VeaDd2v2mQFBNLvdZrqp1OZ4B/1+H5S8ucb+oVhGqzDkEvRCc+ 25 | WYpNxx7kpwZPTLmMYTXXKdTWfpgz9GL0LSkY8d1rxLwHxtV8EzAkV+zIWix4h/IE 26 | 0FG4WvhrttMCu8ulZhGGoVqy7gdb4+ViWnUYNuCCjIcRJj7SeZaDawBASa/jZwik 27 | Hxrwn0osGUqEUBmvjDdXJpTaKCr2GFOvhCM2pG6AXa14b5hS2DgbX+NZYcScYtVC 28 | vn2HMDjnIEF4uOfDJU5eLok4jli5+VwzOQ7hOHs3DIm4+g== 29 | -----END CERTIFICATE----- 30 | -------------------------------------------------------------------------------- /azure/clients/diskclient/interface.go: -------------------------------------------------------------------------------- 1 | // +build !providerless 2 | 3 | /* 4 | Copyright 2020 The Kubernetes Authors. 5 | 6 | Licensed under the Apache License, Version 2.0 (the "License"); 7 | you may not use this file except in compliance with the License. 8 | You may obtain a copy of the License at 9 | 10 | http://www.apache.org/licenses/LICENSE-2.0 11 | 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | */ 18 | 19 | package diskclient 20 | 21 | import ( 22 | "context" 23 | 24 | "github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2019-07-01/compute" 25 | "k8s.io/legacy-cloud-providers/azure/retry" 26 | ) 27 | 28 | const ( 29 | // APIVersion is the API version for compute. 30 | APIVersion = "2019-07-01" 31 | ) 32 | 33 | // Interface is the client interface for Disks. 34 | // Don't forget to run the following command to generate the mock client: 35 | // mockgen -source=$GOPATH/src/k8s.io/kubernetes/staging/src/k8s.io/legacy-cloud-providers/azure/clients/diskclient/interface.go -package=mockdiskclient Interface > $GOPATH/src/k8s.io/kubernetes/staging/src/k8s.io/legacy-cloud-providers/azure/clients/diskclient/mockdiskclient/interface.go 36 | type Interface interface { 37 | // Get gets a Disk. 38 | Get(ctx context.Context, resourceGroupName string, diskName string) (result compute.Disk, rerr *retry.Error) 39 | 40 | // CreateOrUpdate creates or updates a Disk. 41 | CreateOrUpdate(ctx context.Context, resourceGroupName string, diskName string, diskParameter compute.Disk) *retry.Error 42 | 43 | // Delete deletes a Disk by name. 44 | Delete(ctx context.Context, resourceGroupName string, diskName string) *retry.Error 45 | } 46 | -------------------------------------------------------------------------------- /vsphere/vclib/fixtures/server.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIFJjCCAw6gAwIBAgIJAOcEAbv8NslfMA0GCSqGSIb3DQEBCwUAMEAxCzAJBgNV 3 | BAYTAlVTMQswCQYDVQQIDAJDQTETMBEGA1UECgwKQWNtZSwgSW5jLjEPMA0GA1UE 4 | AwwGc29tZUNBMCAXDTE4MDYwODEzMzkyNFoYDzIyMTgwNDIxMTMzOTI0WjBDMQsw 5 | CQYDVQQGEwJVUzELMAkGA1UECAwCQ0ExEzARBgNVBAoMCkFjbWUsIEluYy4xEjAQ 6 | BgNVBAMMCWxvY2FsaG9zdDCCAiIwDQYJKoZIhvcNAQEBBQADggIPADCCAgoCggIB 7 | AJWSTkcwo28xdUmglxR8orbnZRPqt2eWxoUtk6Vxunei2qKrcDaOFAt4vk5zJ3ba 8 | z9qTZFf2WIr7KdXx8/dhahQE/l6WHBvKS5uIi9JNFLnzlnSz01/OxwiYymeK+35s 9 | 7Lco6iuLL/SN8ntYyotFRNQS6xdSlbxBP9T1wroOvBAT/2hdOvrr3K+qPIWzGM4H 10 | Sks4UWJvQt5BnGsDaH6gA/ypP85/qTJOAZaMuFILVxV4I9mxJ5lRPrUVsi79vkzj 11 | ZZi512gVt/zL2bSgt5iLNihvumgTbmPD3Vs1rzLad9K/4m4Jx87jCrb1yeV0YU2k 12 | k+EGFzWxsG9WyFdcpZ1/M3VzxEJLmE0A3LWmEAntEV7dSPRad4FUEcckzPtCHrW7 13 | FNJPVbwcENO5oFPEYpNw8VZ327iWP8ERJxEU5IL+qI7UcIrM6xiGOcd+qXkbN9Aq 14 | kTL97ibagvxVOpwkGx8cLLEMgf7pjei+23KbEBQ8nXiveYb0UMurW9r/7zHMOzDK 15 | OZEhVB46C+WXOAzm8IqrPqexe0tFiCTAcyTnI5oAjM4GeyZnO2zJq5uNxi8zmlSy 16 | I7j1VaTqe2ICf5akX+yt4WV6zHWl5AptNWi/C+fXft1X3Y6dxx75mKQofG3Pio7P 17 | 50fUXPtiSivx9dyx91uQq/BZ3PxT+k4G77zcLEFdNYBvAgMBAAGjHjAcMBoGA1Ud 18 | EQQTMBGCCWxvY2FsaG9zdIcEfwAAATANBgkqhkiG9w0BAQsFAAOCAgEABL8kffi7 19 | 48qSD+/l/UwCYdmqta1vAbOkvLnPtfXe1XlDpJipNuPxUBc8nNTemtrbg0erNJnC 20 | jQHodqmdKBJJOdaEKTwAGp5pYvvjlU3WasmhfJy+QwOWgeqjJcTUo3+DEaHRls16 21 | AZXlsp3hB6z0gzR/qzUuZwpMbL477JpuZtAcwLYeVvLG8bQRyWyEy8JgGDoYSn8s 22 | Z16s+r6AX+cnL/2GHkZ+oc3iuXJbnac4xfWTKDiYnyzK6RWRnoyro7X0jiPz6XX3 23 | wyoWzB1uMSCXscrW6ZcKyKqz75lySLuwGxOMhX4nGOoYHY0ZtrYn5WK2ZAJxsQnn 24 | 8QcjPB0nq37U7ifk1uebmuXe99iqyKnWaLvlcpe+HnO5pVxFkSQEf7Zh+hEnRDkN 25 | IBzLFnqwDS1ug/oQ1aSvc8oBh2ylKDJuGtPNqGKibNJyb2diXO/aEUOKRUKPAxKa 26 | dbKsc4Y1bhZNN3/MICMoyghwAOiuwUQMR5uhxTkQmZUwNrPFa+eW6GvyoYLFUsZs 27 | hZfWLNGD5mLADElxs0HF7F9Zk6pSocTDXba4d4lfxsq88SyZZ7PbjJYFRfLQPzd1 28 | CfvpRPqolEmZo1Y5Q644PELYiJRKpBxmX5GtC5j5eaUD9XdGKvXsGhb0m0gW75rq 29 | iUnnLkZt2ya1cDJDiCnJjo7r5KxMo0XXFDc= 30 | -----END CERTIFICATE----- 31 | -------------------------------------------------------------------------------- /openstack/openstack_metrics.go: -------------------------------------------------------------------------------- 1 | // +build !providerless 2 | 3 | /* 4 | Copyright 2017 The Kubernetes Authors. 5 | 6 | Licensed under the Apache License, Version 2.0 (the "License"); 7 | you may not use this file except in compliance with the License. 8 | You may obtain a copy of the License at 9 | 10 | http://www.apache.org/licenses/LICENSE-2.0 11 | 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | */ 18 | 19 | package openstack 20 | 21 | import ( 22 | "sync" 23 | 24 | "k8s.io/component-base/metrics" 25 | "k8s.io/component-base/metrics/legacyregistry" 26 | ) 27 | 28 | const ( 29 | openstackSubsystem = "openstack" 30 | openstackOperationKey = "cloudprovider_openstack_api_request_duration_seconds" 31 | openstackOperationErrorKey = "cloudprovider_openstack_api_request_errors" 32 | ) 33 | 34 | var ( 35 | openstackOperationsLatency = metrics.NewHistogramVec( 36 | &metrics.HistogramOpts{ 37 | Subsystem: openstackSubsystem, 38 | Name: openstackOperationKey, 39 | Help: "Latency of openstack api call", 40 | StabilityLevel: metrics.ALPHA, 41 | }, 42 | []string{"request"}, 43 | ) 44 | 45 | openstackAPIRequestErrors = metrics.NewCounterVec( 46 | &metrics.CounterOpts{ 47 | Subsystem: openstackSubsystem, 48 | Name: openstackOperationErrorKey, 49 | Help: "Cumulative number of openstack Api call errors", 50 | StabilityLevel: metrics.ALPHA, 51 | }, 52 | []string{"request"}, 53 | ) 54 | ) 55 | 56 | var registerOnce sync.Once 57 | 58 | func registerMetrics() { 59 | registerOnce.Do(func() { 60 | legacyregistry.MustRegister(openstackOperationsLatency) 61 | legacyregistry.MustRegister(openstackAPIRequestErrors) 62 | }) 63 | } 64 | -------------------------------------------------------------------------------- /vsphere/vclib/utils_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 The Kubernetes 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 vclib 18 | 19 | import ( 20 | "context" 21 | "testing" 22 | 23 | "github.com/vmware/govmomi" 24 | "github.com/vmware/govmomi/simulator" 25 | ) 26 | 27 | func TestUtils(t *testing.T) { 28 | ctx := context.Background() 29 | 30 | model := simulator.VPX() 31 | // Child folder "F0" will be created under the root folder and datacenter folders, 32 | // and all resources are created within the "F0" child folders. 33 | model.Folder = 1 34 | 35 | defer model.Remove() 36 | err := model.Create() 37 | if err != nil { 38 | t.Fatal(err) 39 | } 40 | 41 | s := model.Service.NewServer() 42 | defer s.Close() 43 | 44 | c, err := govmomi.NewClient(ctx, s.URL, true) 45 | if err != nil { 46 | t.Fatal(err) 47 | } 48 | 49 | vc := &VSphereConnection{Client: c.Client} 50 | 51 | dc, err := GetDatacenter(ctx, vc, TestDefaultDatacenter) 52 | if err != nil { 53 | t.Error(err) 54 | } 55 | 56 | finder := getFinder(dc) 57 | datastores, err := finder.DatastoreList(ctx, "*") 58 | if err != nil { 59 | t.Fatal(err) 60 | } 61 | 62 | count := model.Count() 63 | if count.Datastore != len(datastores) { 64 | t.Errorf("got %d Datastores, expected: %d", len(datastores), count.Datastore) 65 | } 66 | 67 | _, err = finder.Datastore(ctx, testNameNotFound) 68 | if !IsNotFound(err) { 69 | t.Errorf("unexpected error: %s", err) 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /gce/gce_alpha.go: -------------------------------------------------------------------------------- 1 | // +build !providerless 2 | 3 | /* 4 | Copyright 2017 The Kubernetes Authors. 5 | 6 | Licensed under the Apache License, Version 2.0 (the "License"); 7 | you may not use this file except in compliance with the License. 8 | You may obtain a copy of the License at 9 | 10 | http://www.apache.org/licenses/LICENSE-2.0 11 | 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | */ 18 | 19 | package gce 20 | 21 | const ( 22 | // AlphaFeatureNetworkTiers allows Services backed by a GCP load balancer to choose 23 | // what network tier to use. Currently supports "Standard" and "Premium" (default). 24 | // 25 | // alpha: v1.8 (for Services) 26 | AlphaFeatureNetworkTiers = "NetworkTiers" 27 | // AlphaFeatureILBSubsets allows InternalLoadBalancer services to include a subset 28 | // of cluster nodes as backends instead of all nodes. 29 | AlphaFeatureILBSubsets = "ILBSubsets" 30 | // AlphaFeatureILBCustomSubnet allows InternalLoadBalancer services to specify a 31 | // network subnet to allocate ip addresses from. 32 | AlphaFeatureILBCustomSubnet = "ILBCustomSubnet" 33 | ) 34 | 35 | // AlphaFeatureGate contains a mapping of alpha features to whether they are enabled 36 | type AlphaFeatureGate struct { 37 | features map[string]bool 38 | } 39 | 40 | // Enabled returns true if the provided alpha feature is enabled 41 | func (af *AlphaFeatureGate) Enabled(key string) bool { 42 | if af == nil || af.features == nil { 43 | return false 44 | } 45 | return af.features[key] 46 | } 47 | 48 | // NewAlphaFeatureGate marks the provided alpha features as enabled 49 | func NewAlphaFeatureGate(features []string) *AlphaFeatureGate { 50 | featureMap := make(map[string]bool) 51 | for _, name := range features { 52 | featureMap[name] = true 53 | } 54 | return &AlphaFeatureGate{featureMap} 55 | } 56 | -------------------------------------------------------------------------------- /azure/azure_utils.go: -------------------------------------------------------------------------------- 1 | // +build !providerless 2 | 3 | /* 4 | Copyright 2019 The Kubernetes Authors. 5 | 6 | Licensed under the Apache License, Version 2.0 (the "License"); 7 | you may not use this file except in compliance with the License. 8 | You may obtain a copy of the License at 9 | 10 | http://www.apache.org/licenses/LICENSE-2.0 11 | 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | */ 18 | 19 | package azure 20 | 21 | import ( 22 | "context" 23 | "sync" 24 | ) 25 | 26 | // lockMap used to lock on entries 27 | type lockMap struct { 28 | sync.Mutex 29 | mutexMap map[string]*sync.Mutex 30 | } 31 | 32 | // NewLockMap returns a new lock map 33 | func newLockMap() *lockMap { 34 | return &lockMap{ 35 | mutexMap: make(map[string]*sync.Mutex), 36 | } 37 | } 38 | 39 | // LockEntry acquires a lock associated with the specific entry 40 | func (lm *lockMap) LockEntry(entry string) { 41 | lm.Lock() 42 | // check if entry does not exists, then add entry 43 | if _, exists := lm.mutexMap[entry]; !exists { 44 | lm.addEntry(entry) 45 | } 46 | 47 | lm.Unlock() 48 | lm.lockEntry(entry) 49 | } 50 | 51 | // UnlockEntry release the lock associated with the specific entry 52 | func (lm *lockMap) UnlockEntry(entry string) { 53 | lm.Lock() 54 | defer lm.Unlock() 55 | 56 | if _, exists := lm.mutexMap[entry]; !exists { 57 | return 58 | } 59 | lm.unlockEntry(entry) 60 | } 61 | 62 | func (lm *lockMap) addEntry(entry string) { 63 | lm.mutexMap[entry] = &sync.Mutex{} 64 | } 65 | 66 | func (lm *lockMap) lockEntry(entry string) { 67 | lm.mutexMap[entry].Lock() 68 | } 69 | 70 | func (lm *lockMap) unlockEntry(entry string) { 71 | lm.mutexMap[entry].Unlock() 72 | } 73 | 74 | func getContextWithCancel() (context.Context, context.CancelFunc) { 75 | return context.WithCancel(context.Background()) 76 | } 77 | -------------------------------------------------------------------------------- /azure/clients/snapshotclient/interface.go: -------------------------------------------------------------------------------- 1 | // +build !providerless 2 | 3 | /* 4 | Copyright 2020 The Kubernetes Authors. 5 | 6 | Licensed under the Apache License, Version 2.0 (the "License"); 7 | you may not use this file except in compliance with the License. 8 | You may obtain a copy of the License at 9 | 10 | http://www.apache.org/licenses/LICENSE-2.0 11 | 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | */ 18 | 19 | package snapshotclient 20 | 21 | import ( 22 | "context" 23 | 24 | "github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2019-07-01/compute" 25 | "k8s.io/legacy-cloud-providers/azure/retry" 26 | ) 27 | 28 | const ( 29 | // APIVersion is the API version for compute. 30 | APIVersion = "2019-07-01" 31 | ) 32 | 33 | // Interface is the client interface for Snapshots. 34 | // Don't forget to run the following command to generate the mock client: 35 | // mockgen -source=$GOPATH/src/k8s.io/kubernetes/staging/src/k8s.io/legacy-cloud-providers/azure/clients/snapshotclient/interface.go -package=mocksnapshotclient Interface > $GOPATH/src/k8s.io/kubernetes/staging/src/k8s.io/legacy-cloud-providers/azure/clients/snapshotclient/mocksnapshotclient/interface.go 36 | type Interface interface { 37 | // Get gets a Snapshot. 38 | Get(ctx context.Context, resourceGroupName string, snapshotName string) (compute.Snapshot, *retry.Error) 39 | 40 | // Delete deletes a Snapshot by name. 41 | Delete(ctx context.Context, resourceGroupName string, snapshotName string) *retry.Error 42 | 43 | // ListByResourceGroup get a list snapshots by resourceGroup. 44 | ListByResourceGroup(ctx context.Context, resourceGroupName string) ([]compute.Snapshot, *retry.Error) 45 | 46 | // CreateOrUpdate creates or updates a Snapshot. 47 | CreateOrUpdate(ctx context.Context, resourceGroupName string, snapshotName string, snapshot compute.Snapshot) *retry.Error 48 | } 49 | -------------------------------------------------------------------------------- /vsphere/vclib/constants.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2016 The Kubernetes 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 vclib 18 | 19 | // Volume Constants 20 | const ( 21 | ThinDiskType = "thin" 22 | PreallocatedDiskType = "preallocated" 23 | EagerZeroedThickDiskType = "eagerZeroedThick" 24 | ZeroedThickDiskType = "zeroedThick" 25 | ) 26 | 27 | // Controller Constants 28 | const ( 29 | SCSIControllerLimit = 4 30 | SCSIControllerDeviceLimit = 15 31 | SCSIDeviceSlots = 16 32 | SCSIReservedSlot = 7 33 | 34 | SCSIControllerType = "scsi" 35 | LSILogicControllerType = "lsiLogic" 36 | BusLogicControllerType = "busLogic" 37 | LSILogicSASControllerType = "lsiLogic-sas" 38 | PVSCSIControllerType = "pvscsi" 39 | ) 40 | 41 | // Other Constants 42 | const ( 43 | LogLevel = 4 44 | DatastoreProperty = "datastore" 45 | ResourcePoolProperty = "resourcePool" 46 | DatastoreInfoProperty = "info" 47 | VirtualMachineType = "VirtualMachine" 48 | RoundTripperDefaultCount = 3 49 | VSANDatastoreType = "vsan" 50 | DummyVMPrefixName = "vsphere-k8s" 51 | ActivePowerState = "poweredOn" 52 | DatacenterType = "Datacenter" 53 | ClusterComputeResourceType = "ClusterComputeResource" 54 | HostSystemType = "HostSystem" 55 | NameProperty = "name" 56 | ) 57 | 58 | // Test Constants 59 | const ( 60 | TestDefaultDatacenter = "DC0" 61 | TestDefaultDatastore = "LocalDS_0" 62 | TestDefaultNetwork = "VM Network" 63 | testNameNotFound = "enoent" 64 | ) 65 | -------------------------------------------------------------------------------- /azure/clients/vmssvmclient/interface.go: -------------------------------------------------------------------------------- 1 | // +build !providerless 2 | 3 | /* 4 | Copyright 2019 The Kubernetes Authors. 5 | 6 | Licensed under the Apache License, Version 2.0 (the "License"); 7 | you may not use this file except in compliance with the License. 8 | You may obtain a copy of the License at 9 | 10 | http://www.apache.org/licenses/LICENSE-2.0 11 | 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | */ 18 | 19 | package vmssvmclient 20 | 21 | import ( 22 | "context" 23 | 24 | "github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2019-07-01/compute" 25 | "k8s.io/legacy-cloud-providers/azure/retry" 26 | ) 27 | 28 | const ( 29 | // APIVersion is the API version for VMSS. 30 | APIVersion = "2019-07-01" 31 | ) 32 | 33 | // Interface is the client interface for VirtualMachineScaleSetVM. 34 | // Don't forget to run the following command to generate the mock client: 35 | // mockgen -source=$GOPATH/src/k8s.io/kubernetes/staging/src/k8s.io/legacy-cloud-providers/azure/clients/vmssvmclient/interface.go -package=mockvmssvmclient Interface > $GOPATH/src/k8s.io/kubernetes/staging/src/k8s.io/legacy-cloud-providers/azure/clients/vmssvmclient/mockvmssvmclient/interface.go 36 | type Interface interface { 37 | // Get gets a VirtualMachineScaleSetVM. 38 | Get(ctx context.Context, resourceGroupName string, VMScaleSetName string, instanceID string, expand compute.InstanceViewTypes) (compute.VirtualMachineScaleSetVM, *retry.Error) 39 | 40 | // List gets a list of VirtualMachineScaleSetVMs in the virtualMachineScaleSet. 41 | List(ctx context.Context, resourceGroupName string, virtualMachineScaleSetName string, expand string) ([]compute.VirtualMachineScaleSetVM, *retry.Error) 42 | 43 | // Update updates a VirtualMachineScaleSetVM. 44 | Update(ctx context.Context, resourceGroupName string, VMScaleSetName string, instanceID string, parameters compute.VirtualMachineScaleSetVM, source string) *retry.Error 45 | } 46 | -------------------------------------------------------------------------------- /vsphere/vsphere_util_test.go: -------------------------------------------------------------------------------- 1 | // +build !providerless 2 | 3 | /* 4 | Copyright 2019 The Kubernetes Authors. 5 | 6 | Licensed under the Apache License, Version 2.0 (the "License"); 7 | you may not use this file except in compliance with the License. 8 | You may obtain a copy of the License at 9 | 10 | http://www.apache.org/licenses/LICENSE-2.0 11 | 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | */ 18 | 19 | package vsphere 20 | 21 | import ( 22 | "context" 23 | "fmt" 24 | "testing" 25 | 26 | "k8s.io/legacy-cloud-providers/vsphere/vclib" 27 | 28 | "github.com/vmware/govmomi" 29 | "github.com/vmware/govmomi/simulator" 30 | ) 31 | 32 | func TestGetPathFromFileNotFound(t *testing.T) { 33 | ctx := context.Background() 34 | 35 | // vCenter model + initial set of objects (cluster, hosts, VMs, network, datastore, etc) 36 | model := simulator.VPX() 37 | 38 | defer model.Remove() 39 | err := model.Create() 40 | if err != nil { 41 | t.Fatal(err) 42 | } 43 | 44 | s := model.Service.NewServer() 45 | defer s.Close() 46 | 47 | c, err := govmomi.NewClient(ctx, s.URL, true) 48 | if err != nil { 49 | t.Fatal(err) 50 | } 51 | 52 | vc := &vclib.VSphereConnection{Client: c.Client} 53 | 54 | dc, err := vclib.GetDatacenter(ctx, vc, vclib.TestDefaultDatacenter) 55 | if err != nil { 56 | t.Errorf("failed to get datacenter: %v", err) 57 | } 58 | 59 | requestDiskPath := fmt.Sprintf("[%s] %s", vclib.TestDefaultDatastore, DummyDiskName) 60 | _, err = dc.GetVirtualDiskPage83Data(ctx, requestDiskPath) 61 | if err == nil { 62 | t.Error("expected error when calling GetVirtualDiskPage83Data") 63 | } 64 | 65 | _, err = getPathFromFileNotFound(err) 66 | if err != nil { 67 | t.Errorf("expected err to be nil but was %v", err) 68 | } 69 | 70 | _, err = getPathFromFileNotFound(nil) 71 | if err == nil { 72 | t.Errorf("expected err when calling getPathFromFileNotFound with nil err") 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /azure/clients/subnetclient/interface.go: -------------------------------------------------------------------------------- 1 | // +build !providerless 2 | 3 | /* 4 | Copyright 2020 The Kubernetes Authors. 5 | 6 | Licensed under the Apache License, Version 2.0 (the "License"); 7 | you may not use this file except in compliance with the License. 8 | You may obtain a copy of the License at 9 | 10 | http://www.apache.org/licenses/LICENSE-2.0 11 | 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | */ 18 | 19 | package subnetclient 20 | 21 | import ( 22 | "context" 23 | 24 | "github.com/Azure/azure-sdk-for-go/services/network/mgmt/2019-06-01/network" 25 | "k8s.io/legacy-cloud-providers/azure/retry" 26 | ) 27 | 28 | const ( 29 | // APIVersion is the API version for network. 30 | APIVersion = "2019-06-01" 31 | ) 32 | 33 | // Interface is the client interface for Subnet. 34 | // Don't forget to run the following command to generate the mock client: 35 | // mockgen -source=$GOPATH/src/k8s.io/kubernetes/staging/src/k8s.io/legacy-cloud-providers/azure/clients/subnetclient/interface.go -package=mocksubnetclient Interface > $GOPATH/src/k8s.io/kubernetes/staging/src/k8s.io/legacy-cloud-providers/azure/clients/subnetclient/mocksubnetclient/interface.go 36 | type Interface interface { 37 | // Get gets a Subnet. 38 | Get(ctx context.Context, resourceGroupName string, virtualNetworkName string, subnetName string, expand string) (result network.Subnet, rerr *retry.Error) 39 | 40 | // List gets a list of Subnet in the VNet. 41 | List(ctx context.Context, resourceGroupName string, virtualNetworkName string) (result []network.Subnet, rerr *retry.Error) 42 | 43 | // CreateOrUpdate creates or updates a Subnet. 44 | CreateOrUpdate(ctx context.Context, resourceGroupName string, virtualNetworkName string, subnetName string, subnetParameters network.Subnet) *retry.Error 45 | 46 | // Delete deletes a Subnet by name. 47 | Delete(ctx context.Context, resourceGroupName string, virtualNetworkName string, subnetName string) *retry.Error 48 | } 49 | -------------------------------------------------------------------------------- /azure/clients/loadbalancerclient/interface.go: -------------------------------------------------------------------------------- 1 | // +build !providerless 2 | 3 | /* 4 | Copyright 2020 The Kubernetes Authors. 5 | 6 | Licensed under the Apache License, Version 2.0 (the "License"); 7 | you may not use this file except in compliance with the License. 8 | You may obtain a copy of the License at 9 | 10 | http://www.apache.org/licenses/LICENSE-2.0 11 | 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | */ 18 | 19 | package loadbalancerclient 20 | 21 | import ( 22 | "context" 23 | 24 | "github.com/Azure/azure-sdk-for-go/services/network/mgmt/2019-06-01/network" 25 | "k8s.io/legacy-cloud-providers/azure/retry" 26 | ) 27 | 28 | const ( 29 | // APIVersion is the API version for network. 30 | APIVersion = "2019-06-01" 31 | ) 32 | 33 | // Interface is the client interface for LoadBalancer. 34 | // Don't forget to run the following command to generate the mock client: 35 | // mockgen -source=$GOPATH/src/k8s.io/kubernetes/staging/src/k8s.io/legacy-cloud-providers/azure/clients/loadbalancerclient/interface.go -package=mockloadbalancerclient Interface > $GOPATH/src/k8s.io/kubernetes/staging/src/k8s.io/legacy-cloud-providers/azure/clients/loadbalancerclient/mockloadbalancerclient/interface.go 36 | type Interface interface { 37 | // Get gets a LoadBalancer. 38 | Get(ctx context.Context, resourceGroupName string, loadBalancerName string, expand string) (result network.LoadBalancer, rerr *retry.Error) 39 | 40 | // List gets a list of LoadBalancer in the resource group. 41 | List(ctx context.Context, resourceGroupName string) (result []network.LoadBalancer, rerr *retry.Error) 42 | 43 | // CreateOrUpdate creates or updates a LoadBalancer. 44 | CreateOrUpdate(ctx context.Context, resourceGroupName string, loadBalancerName string, parameters network.LoadBalancer, etag string) *retry.Error 45 | 46 | // Delete deletes a LoadBalancer by name. 47 | Delete(ctx context.Context, resourceGroupName string, loadBalancerName string) *retry.Error 48 | } 49 | -------------------------------------------------------------------------------- /vsphere/vclib/fixtures/fixtures.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 The Kubernetes 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 fixtures 18 | 19 | import ( 20 | "os" 21 | "path/filepath" 22 | "runtime" 23 | "strings" 24 | ) 25 | 26 | var ( 27 | // CaCertPath is the filepath to a certificate that can be used as a CA 28 | // certificate. 29 | CaCertPath string 30 | // ServerCertPath is the filepath to a leaf certifiacte signed by the CA at 31 | // `CaCertPath`. 32 | ServerCertPath string 33 | // ServerKeyPath is the filepath to the private key for the ceritifiacte at 34 | // `ServerCertPath`. 35 | ServerKeyPath string 36 | // InvalidCertPath is the filepath to an invalid certificate. 37 | InvalidCertPath string 38 | ) 39 | 40 | func init() { 41 | _, thisFile, _, ok := runtime.Caller(0) 42 | if !ok { 43 | panic("Cannot get path to the fixtures") 44 | } 45 | 46 | fixturesDir := filepath.Dir(thisFile) 47 | 48 | cwd, err := os.Getwd() 49 | if err != nil { 50 | panic("Cannot get CWD: " + err.Error()) 51 | } 52 | 53 | // When tests run in a bazel sandbox `runtime.Caller()` 54 | // returns a relative path, when run with plain `go test` the path 55 | // returned is absolute. To make those fixtures work in both those cases, 56 | // we prepend the CWD iff the CWD is not yet part of the path to the fixtures. 57 | if !strings.HasPrefix(fixturesDir, cwd) { 58 | fixturesDir = filepath.Join(cwd, fixturesDir) 59 | } 60 | 61 | CaCertPath = filepath.Join(fixturesDir, "ca.pem") 62 | ServerCertPath = filepath.Join(fixturesDir, "server.pem") 63 | ServerKeyPath = filepath.Join(fixturesDir, "server.key") 64 | InvalidCertPath = filepath.Join(fixturesDir, "invalid.pem") 65 | } 66 | -------------------------------------------------------------------------------- /azure/azure_storageaccount_test.go: -------------------------------------------------------------------------------- 1 | // +build !providerless 2 | 3 | /* 4 | Copyright 2017 The Kubernetes Authors. 5 | 6 | Licensed under the Apache License, Version 2.0 (the "License"); 7 | you may not use this file except in compliance with the License. 8 | You may obtain a copy of the License at 9 | 10 | http://www.apache.org/licenses/LICENSE-2.0 11 | 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | */ 18 | 19 | package azure 20 | 21 | import ( 22 | "fmt" 23 | "testing" 24 | 25 | "github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2019-06-01/storage" 26 | ) 27 | 28 | func TestGetStorageAccessKeys(t *testing.T) { 29 | cloud := &Cloud{} 30 | fake := newFakeStorageAccountClient() 31 | cloud.StorageAccountClient = fake 32 | value := "foo bar" 33 | 34 | tests := []struct { 35 | results storage.AccountListKeysResult 36 | expectedKey string 37 | expectErr bool 38 | err error 39 | }{ 40 | {storage.AccountListKeysResult{}, "", true, nil}, 41 | { 42 | storage.AccountListKeysResult{ 43 | Keys: &[]storage.AccountKey{ 44 | {Value: &value}, 45 | }, 46 | }, 47 | "bar", 48 | false, 49 | nil, 50 | }, 51 | { 52 | storage.AccountListKeysResult{ 53 | Keys: &[]storage.AccountKey{ 54 | {}, 55 | {Value: &value}, 56 | }, 57 | }, 58 | "bar", 59 | false, 60 | nil, 61 | }, 62 | {storage.AccountListKeysResult{}, "", true, fmt.Errorf("test error")}, 63 | } 64 | 65 | for _, test := range tests { 66 | expectedKey := test.expectedKey 67 | fake.Keys = test.results 68 | fake.Err = test.err 69 | key, err := cloud.GetStorageAccesskey("acct", "rg") 70 | if test.expectErr && err == nil { 71 | t.Errorf("Unexpected non-error") 72 | continue 73 | } 74 | if !test.expectErr && err != nil { 75 | t.Errorf("Unexpected error: %v", err) 76 | continue 77 | } 78 | if key != expectedKey { 79 | t.Errorf("expected: %s, saw %s", expectedKey, key) 80 | } 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /azure/clients/securitygroupclient/interface.go: -------------------------------------------------------------------------------- 1 | // +build !providerless 2 | 3 | /* 4 | Copyright 2020 The Kubernetes Authors. 5 | 6 | Licensed under the Apache License, Version 2.0 (the "License"); 7 | you may not use this file except in compliance with the License. 8 | You may obtain a copy of the License at 9 | 10 | http://www.apache.org/licenses/LICENSE-2.0 11 | 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | */ 18 | 19 | package securitygroupclient 20 | 21 | import ( 22 | "context" 23 | 24 | "github.com/Azure/azure-sdk-for-go/services/network/mgmt/2019-06-01/network" 25 | "k8s.io/legacy-cloud-providers/azure/retry" 26 | ) 27 | 28 | const ( 29 | // APIVersion is the API version for network. 30 | APIVersion = "2019-06-01" 31 | ) 32 | 33 | // Interface is the client interface for SecurityGroups. 34 | // Don't forget to run the following command to generate the mock client: 35 | // mockgen -source=$GOPATH/src/k8s.io/kubernetes/staging/src/k8s.io/legacy-cloud-providers/azure/clients/securitygroupclient/interface.go -package=mocksecuritygroupclient Interface > $GOPATH/src/k8s.io/kubernetes/staging/src/k8s.io/legacy-cloud-providers/azure/clients/securitygroupclient/mocksecuritygroupclient/interface.go 36 | type Interface interface { 37 | // Get gets a SecurityGroup. 38 | Get(ctx context.Context, resourceGroupName string, networkSecurityGroupName string, expand string) (result network.SecurityGroup, rerr *retry.Error) 39 | 40 | // List gets a list of SecurityGroup in the resource group. 41 | List(ctx context.Context, resourceGroupName string) (result []network.SecurityGroup, rerr *retry.Error) 42 | 43 | // CreateOrUpdate creates or updates a SecurityGroup. 44 | CreateOrUpdate(ctx context.Context, resourceGroupName string, networkSecurityGroupName string, parameters network.SecurityGroup, etag string) *retry.Error 45 | 46 | // Delete deletes a SecurityGroup by name. 47 | Delete(ctx context.Context, resourceGroupName string, networkSecurityGroupName string) *retry.Error 48 | } 49 | -------------------------------------------------------------------------------- /vsphere/vclib/folder_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2016 The Kubernetes 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 vclib 18 | 19 | import ( 20 | "context" 21 | "path" 22 | "testing" 23 | 24 | "github.com/vmware/govmomi" 25 | "github.com/vmware/govmomi/simulator" 26 | ) 27 | 28 | func TestFolder(t *testing.T) { 29 | ctx := context.Background() 30 | 31 | model := simulator.VPX() 32 | // Child folder "F0" will be created under the root folder and datacenter folders, 33 | // and all resources are created within the "F0" child folders. 34 | model.Folder = 1 35 | 36 | defer model.Remove() 37 | err := model.Create() 38 | if err != nil { 39 | t.Fatal(err) 40 | } 41 | 42 | s := model.Service.NewServer() 43 | defer s.Close() 44 | 45 | c, err := govmomi.NewClient(ctx, s.URL, true) 46 | if err != nil { 47 | t.Fatal(err) 48 | } 49 | 50 | vc := &VSphereConnection{Client: c.Client} 51 | 52 | dc, err := GetDatacenter(ctx, vc, TestDefaultDatacenter) 53 | if err != nil { 54 | t.Error(err) 55 | } 56 | 57 | const folderName = "F0" 58 | vmFolder := path.Join("/", folderName, dc.Name(), "vm") 59 | 60 | tests := []struct { 61 | folderPath string 62 | expect int 63 | }{ 64 | {vmFolder, 0}, 65 | {path.Join(vmFolder, folderName), (model.Host + model.Cluster) * model.Machine}, 66 | } 67 | 68 | for i, test := range tests { 69 | folder, cerr := dc.GetFolderByPath(ctx, test.folderPath) 70 | if cerr != nil { 71 | t.Fatal(cerr) 72 | } 73 | 74 | vms, cerr := folder.GetVirtualMachines(ctx) 75 | if cerr != nil { 76 | t.Fatalf("%d: %s", i, cerr) 77 | } 78 | 79 | if len(vms) != test.expect { 80 | t.Errorf("%d: expected %d VMs, got: %d", i, test.expect, len(vms)) 81 | } 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /azure/clients/vmssclient/interface.go: -------------------------------------------------------------------------------- 1 | // +build !providerless 2 | 3 | /* 4 | Copyright 2019 The Kubernetes Authors. 5 | 6 | Licensed under the Apache License, Version 2.0 (the "License"); 7 | you may not use this file except in compliance with the License. 8 | You may obtain a copy of the License at 9 | 10 | http://www.apache.org/licenses/LICENSE-2.0 11 | 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | */ 18 | 19 | package vmssclient 20 | 21 | import ( 22 | "context" 23 | 24 | "github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2019-07-01/compute" 25 | "k8s.io/legacy-cloud-providers/azure/retry" 26 | ) 27 | 28 | const ( 29 | // APIVersion is the API version for VMSS. 30 | APIVersion = "2019-07-01" 31 | ) 32 | 33 | // Interface is the client interface for VirtualMachineScaleSet. 34 | // Don't forget to run the following command to generate the mock client: 35 | // mockgen -source=$GOPATH/src/k8s.io/kubernetes/staging/src/k8s.io/legacy-cloud-providers/azure/clients/vmssclient/interface.go -package=mockvmssclient Interface > $GOPATH/src/k8s.io/kubernetes/staging/src/k8s.io/legacy-cloud-providers/azure/clients/vmssclient/mockvmssclient/interface.go 36 | type Interface interface { 37 | // Get gets a VirtualMachineScaleSet. 38 | Get(ctx context.Context, resourceGroupName string, VMScaleSetName string) (result compute.VirtualMachineScaleSet, rerr *retry.Error) 39 | 40 | // List gets a list of VirtualMachineScaleSets in the resource group. 41 | List(ctx context.Context, resourceGroupName string) (result []compute.VirtualMachineScaleSet, rerr *retry.Error) 42 | 43 | // CreateOrUpdate creates or updates a VirtualMachineScaleSet. 44 | CreateOrUpdate(ctx context.Context, resourceGroupName string, VMScaleSetName string, parameters compute.VirtualMachineScaleSet) *retry.Error 45 | 46 | // DeleteInstances deletes the instances for a VirtualMachineScaleSet. 47 | DeleteInstances(ctx context.Context, resourceGroupName string, vmScaleSetName string, vmInstanceIDs compute.VirtualMachineScaleSetVMInstanceRequiredIDs) *retry.Error 48 | } 49 | -------------------------------------------------------------------------------- /azure/clients/vmclient/interface.go: -------------------------------------------------------------------------------- 1 | // +build !providerless 2 | 3 | /* 4 | Copyright 2020 The Kubernetes Authors. 5 | 6 | Licensed under the Apache License, Version 2.0 (the "License"); 7 | you may not use this file except in compliance with the License. 8 | You may obtain a copy of the License at 9 | 10 | http://www.apache.org/licenses/LICENSE-2.0 11 | 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | */ 18 | 19 | package vmclient 20 | 21 | import ( 22 | "context" 23 | 24 | "github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2019-07-01/compute" 25 | "k8s.io/legacy-cloud-providers/azure/retry" 26 | ) 27 | 28 | const ( 29 | // APIVersion is the API version for VirtualMachine. 30 | APIVersion = "2019-07-01" 31 | ) 32 | 33 | // Interface is the client interface for VirtualMachines. 34 | // Don't forget to run the following command to generate the mock client: 35 | // mockgen -source=$GOPATH/src/k8s.io/kubernetes/staging/src/k8s.io/legacy-cloud-providers/azure/clients/vmclient/interface.go -package=mockvmclient Interface > $GOPATH/src/k8s.io/kubernetes/staging/src/k8s.io/legacy-cloud-providers/azure/clients/vmclient/mockvmclient/interface.go 36 | type Interface interface { 37 | // Get gets a VirtualMachine. 38 | Get(ctx context.Context, resourceGroupName string, VMName string, expand compute.InstanceViewTypes) (compute.VirtualMachine, *retry.Error) 39 | 40 | // List gets a list of VirtualMachines in the resourceGroupName. 41 | List(ctx context.Context, resourceGroupName string) ([]compute.VirtualMachine, *retry.Error) 42 | 43 | // CreateOrUpdate creates or updates a VirtualMachine. 44 | CreateOrUpdate(ctx context.Context, resourceGroupName string, VMName string, parameters compute.VirtualMachine, source string) *retry.Error 45 | 46 | // Update updates a VirtualMachine. 47 | Update(ctx context.Context, resourceGroupName string, VMName string, parameters compute.VirtualMachineUpdate, source string) *retry.Error 48 | 49 | // Delete deletes a VirtualMachine. 50 | Delete(ctx context.Context, resourceGroupName string, VMName string) *retry.Error 51 | } 52 | -------------------------------------------------------------------------------- /vsphere/vclib/fixtures/createCerts.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Copyright 2018 The Kubernetes Authors. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | set -eu 18 | 19 | readonly VALID_DAYS='73000' 20 | readonly RSA_KEY_SIZE='4096' 21 | 22 | createKey() { 23 | openssl genrsa \ 24 | -out "$1" \ 25 | "$RSA_KEY_SIZE" 26 | } 27 | 28 | createCaCert() { 29 | openssl req \ 30 | -x509 \ 31 | -subj "$( getSubj 'someCA' )" \ 32 | -new \ 33 | -nodes \ 34 | -key "$2" \ 35 | -sha256 \ 36 | -days "$VALID_DAYS" \ 37 | -out "$1" 38 | } 39 | 40 | createCSR() { 41 | openssl req \ 42 | -new \ 43 | -sha256 \ 44 | -key "$2" \ 45 | -subj "$( getSubj 'localhost' )" \ 46 | -reqexts SAN \ 47 | -config <( getSANConfig ) \ 48 | -out "$1" 49 | } 50 | 51 | signCSR() { 52 | openssl x509 \ 53 | -req \ 54 | -in "$2" \ 55 | -CA "$3" \ 56 | -CAkey "$4" \ 57 | -CAcreateserial \ 58 | -days "$VALID_DAYS" \ 59 | -sha256 \ 60 | -extfile <( getSAN ) \ 61 | -out "$1" 62 | } 63 | 64 | getSubj() { 65 | local cn="${1:-someRandomCN}" 66 | echo "/C=US/ST=CA/O=Acme, Inc./CN=${cn}" 67 | } 68 | 69 | getSAN() { 70 | printf "subjectAltName=DNS:localhost,IP:127.0.0.1" 71 | } 72 | 73 | getSANConfig() { 74 | cat /etc/ssl/openssl.cnf 75 | printf '\n[SAN]\n' 76 | getSAN 77 | } 78 | 79 | main() { 80 | local caCertPath="./ca.pem" 81 | local caKeyPath="./ca.key" 82 | local serverCsrPath="./server.csr" 83 | local serverCertPath="./server.pem" 84 | local serverKeyPath="./server.key" 85 | 86 | createKey "$caKeyPath" 87 | createCaCert "$caCertPath" "$caKeyPath" 88 | createKey "$serverKeyPath" 89 | createCSR "$serverCsrPath" "$serverKeyPath" 90 | signCSR "$serverCertPath" "$serverCsrPath" "$caCertPath" "$caKeyPath" 91 | } 92 | 93 | main "$@" 94 | -------------------------------------------------------------------------------- /aws/aws_metrics.go: -------------------------------------------------------------------------------- 1 | // +build !providerless 2 | 3 | /* 4 | Copyright 2017 The Kubernetes Authors. 5 | 6 | Licensed under the Apache License, Version 2.0 (the "License"); 7 | you may not use this file except in compliance with the License. 8 | You may obtain a copy of the License at 9 | 10 | http://www.apache.org/licenses/LICENSE-2.0 11 | 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | */ 18 | 19 | package aws 20 | 21 | import ( 22 | "sync" 23 | 24 | "k8s.io/component-base/metrics" 25 | "k8s.io/component-base/metrics/legacyregistry" 26 | ) 27 | 28 | var ( 29 | awsAPIMetric = metrics.NewHistogramVec( 30 | &metrics.HistogramOpts{ 31 | Name: "cloudprovider_aws_api_request_duration_seconds", 32 | Help: "Latency of AWS API calls", 33 | StabilityLevel: metrics.ALPHA, 34 | }, 35 | []string{"request"}) 36 | 37 | awsAPIErrorMetric = metrics.NewCounterVec( 38 | &metrics.CounterOpts{ 39 | Name: "cloudprovider_aws_api_request_errors", 40 | Help: "AWS API errors", 41 | StabilityLevel: metrics.ALPHA, 42 | }, 43 | []string{"request"}) 44 | 45 | awsAPIThrottlesMetric = metrics.NewCounterVec( 46 | &metrics.CounterOpts{ 47 | Name: "cloudprovider_aws_api_throttled_requests_total", 48 | Help: "AWS API throttled requests", 49 | StabilityLevel: metrics.ALPHA, 50 | }, 51 | []string{"operation_name"}) 52 | ) 53 | 54 | func recordAWSMetric(actionName string, timeTaken float64, err error) { 55 | if err != nil { 56 | awsAPIErrorMetric.With(metrics.Labels{"request": actionName}).Inc() 57 | } else { 58 | awsAPIMetric.With(metrics.Labels{"request": actionName}).Observe(timeTaken) 59 | } 60 | } 61 | 62 | func recordAWSThrottlesMetric(operation string) { 63 | awsAPIThrottlesMetric.With(metrics.Labels{"operation_name": operation}).Inc() 64 | } 65 | 66 | var registerOnce sync.Once 67 | 68 | func registerMetrics() { 69 | registerOnce.Do(func() { 70 | legacyregistry.MustRegister(awsAPIMetric) 71 | legacyregistry.MustRegister(awsAPIErrorMetric) 72 | legacyregistry.MustRegister(awsAPIThrottlesMetric) 73 | }) 74 | } 75 | -------------------------------------------------------------------------------- /vsphere/vclib/datastore_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2016 The Kubernetes 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 vclib 18 | 19 | import ( 20 | "context" 21 | "testing" 22 | 23 | "github.com/vmware/govmomi" 24 | "github.com/vmware/govmomi/object" 25 | "github.com/vmware/govmomi/simulator" 26 | ) 27 | 28 | func TestDatastore(t *testing.T) { 29 | ctx := context.Background() 30 | 31 | // vCenter model + initial set of objects (cluster, hosts, VMs, network, datastore, etc) 32 | model := simulator.VPX() 33 | 34 | defer model.Remove() 35 | err := model.Create() 36 | if err != nil { 37 | t.Fatal(err) 38 | } 39 | 40 | s := model.Service.NewServer() 41 | defer s.Close() 42 | 43 | c, err := govmomi.NewClient(ctx, s.URL, true) 44 | if err != nil { 45 | t.Fatal(err) 46 | } 47 | 48 | vc := &VSphereConnection{Client: c.Client} 49 | 50 | dc, err := GetDatacenter(ctx, vc, TestDefaultDatacenter) 51 | if err != nil { 52 | t.Error(err) 53 | } 54 | 55 | all, err := dc.GetAllDatastores(ctx) 56 | if err != nil { 57 | t.Fatal(err) 58 | } 59 | 60 | for _, info := range all { 61 | ds := info.Datastore 62 | kind, cerr := ds.GetType(ctx) 63 | if cerr != nil { 64 | t.Error(err) 65 | } 66 | if kind == "" { 67 | t.Error("empty Datastore type") 68 | } 69 | 70 | dir := object.DatastorePath{ 71 | Datastore: info.Info.Name, 72 | Path: "kubevols", 73 | } 74 | 75 | // TODO: test Datastore.IsCompatibleWithStoragePolicy (vcsim needs PBM support) 76 | 77 | for _, fail := range []bool{false, true} { 78 | cerr = ds.CreateDirectory(ctx, dir.String(), false) 79 | if fail { 80 | if cerr != ErrFileAlreadyExist { 81 | t.Errorf("expected %s, got: %s", ErrFileAlreadyExist, cerr) 82 | } 83 | continue 84 | } 85 | 86 | if cerr != nil { 87 | t.Error(err) 88 | } 89 | } 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /azure/clients/storageaccountclient/interface.go: -------------------------------------------------------------------------------- 1 | // +build !providerless 2 | 3 | /* 4 | Copyright 2020 The Kubernetes Authors. 5 | 6 | Licensed under the Apache License, Version 2.0 (the "License"); 7 | you may not use this file except in compliance with the License. 8 | You may obtain a copy of the License at 9 | 10 | http://www.apache.org/licenses/LICENSE-2.0 11 | 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | */ 18 | 19 | package storageaccountclient 20 | 21 | import ( 22 | "context" 23 | 24 | "github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2019-06-01/storage" 25 | "k8s.io/legacy-cloud-providers/azure/retry" 26 | ) 27 | 28 | const ( 29 | // APIVersion is the API version for network. 30 | APIVersion = "2019-06-01" 31 | ) 32 | 33 | // Interface is the client interface for StorageAccounts. 34 | // Don't forget to run the following command to generate the mock client: 35 | // mockgen -source=$GOPATH/src/k8s.io/kubernetes/staging/src/k8s.io/legacy-cloud-providers/azure/clients/storageaccountclient/interface.go -package=mockstorageaccountclient Interface > $GOPATH/src/k8s.io/kubernetes/staging/src/k8s.io/legacy-cloud-providers/azure/clients/storageaccountclient/mockstorageaccountclient/interface.go 36 | type Interface interface { 37 | // Create creates a StorageAccount. 38 | Create(ctx context.Context, resourceGroupName string, accountName string, parameters storage.AccountCreateParameters) *retry.Error 39 | 40 | // Delete deletes a StorageAccount by name. 41 | Delete(ctx context.Context, resourceGroupName string, accountName string) *retry.Error 42 | 43 | // ListKeys get a list of storage account keys. 44 | ListKeys(ctx context.Context, resourceGroupName string, accountName string) (storage.AccountListKeysResult, *retry.Error) 45 | 46 | // ListByResourceGroup get a list storage accounts by resourceGroup. 47 | ListByResourceGroup(ctx context.Context, resourceGroupName string) ([]storage.Account, *retry.Error) 48 | 49 | // GetProperties gets properties of the StorageAccount. 50 | GetProperties(ctx context.Context, resourceGroupName string, accountName string) (result storage.Account, rerr *retry.Error) 51 | } 52 | -------------------------------------------------------------------------------- /azure/clients/vmsizeclient/mockvmsizeclient/interface.go: -------------------------------------------------------------------------------- 1 | // +build !providerless 2 | 3 | /* 4 | Copyright 2020 The Kubernetes Authors. 5 | 6 | Licensed under the Apache License, Version 2.0 (the "License"); 7 | you may not use this file except in compliance with the License. 8 | You may obtain a copy of the License at 9 | 10 | http://www.apache.org/licenses/LICENSE-2.0 11 | 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | */ 18 | 19 | package mockvmsizeclient 20 | 21 | import ( 22 | context "context" 23 | compute "github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2019-07-01/compute" 24 | gomock "github.com/golang/mock/gomock" 25 | retry "k8s.io/legacy-cloud-providers/azure/retry" 26 | reflect "reflect" 27 | ) 28 | 29 | // MockInterface is a mock of Interface interface 30 | type MockInterface struct { 31 | ctrl *gomock.Controller 32 | recorder *MockInterfaceMockRecorder 33 | } 34 | 35 | // MockInterfaceMockRecorder is the mock recorder for MockInterface 36 | type MockInterfaceMockRecorder struct { 37 | mock *MockInterface 38 | } 39 | 40 | // NewMockInterface creates a new mock instance 41 | func NewMockInterface(ctrl *gomock.Controller) *MockInterface { 42 | mock := &MockInterface{ctrl: ctrl} 43 | mock.recorder = &MockInterfaceMockRecorder{mock} 44 | return mock 45 | } 46 | 47 | // EXPECT returns an object that allows the caller to indicate expected use 48 | func (m *MockInterface) EXPECT() *MockInterfaceMockRecorder { 49 | return m.recorder 50 | } 51 | 52 | // List mocks base method 53 | func (m *MockInterface) List(ctx context.Context, location string) (compute.VirtualMachineSizeListResult, *retry.Error) { 54 | m.ctrl.T.Helper() 55 | ret := m.ctrl.Call(m, "List", ctx, location) 56 | ret0, _ := ret[0].(compute.VirtualMachineSizeListResult) 57 | ret1, _ := ret[1].(*retry.Error) 58 | return ret0, ret1 59 | } 60 | 61 | // List indicates an expected call of List 62 | func (mr *MockInterfaceMockRecorder) List(ctx, location interface{}) *gomock.Call { 63 | mr.mock.ctrl.T.Helper() 64 | return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "List", reflect.TypeOf((*MockInterface)(nil).List), ctx, location) 65 | } 66 | -------------------------------------------------------------------------------- /gce/gce_annotations_test.go: -------------------------------------------------------------------------------- 1 | // +build !providerless 2 | 3 | /* 4 | Copyright 2017 The Kubernetes Authors. 5 | 6 | Licensed under the Apache License, Version 2.0 (the "License"); 7 | you may not use this file except in compliance with the License. 8 | You may obtain a copy of the License at 9 | 10 | http://www.apache.org/licenses/LICENSE-2.0 11 | 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | */ 18 | 19 | package gce 20 | 21 | import ( 22 | "testing" 23 | 24 | "github.com/GoogleCloudPlatform/k8s-cloud-provider/pkg/cloud" 25 | "k8s.io/api/core/v1" 26 | metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 27 | 28 | "github.com/stretchr/testify/assert" 29 | ) 30 | 31 | func TestServiceNetworkTierAnnotationKey(t *testing.T) { 32 | createTestService := func() *v1.Service { 33 | return &v1.Service{ 34 | ObjectMeta: metav1.ObjectMeta{ 35 | UID: "randome-uid", 36 | Name: "test-svc", 37 | Namespace: "test-ns", 38 | }, 39 | } 40 | } 41 | 42 | for testName, testCase := range map[string]struct { 43 | annotations map[string]string 44 | expectedTier cloud.NetworkTier 45 | expectErr bool 46 | }{ 47 | "Use the default when the annotation does not exist": { 48 | annotations: nil, 49 | expectedTier: cloud.NetworkTierDefault, 50 | }, 51 | "Standard tier": { 52 | annotations: map[string]string{NetworkTierAnnotationKey: "Standard"}, 53 | expectedTier: cloud.NetworkTierStandard, 54 | }, 55 | "Premium tier": { 56 | annotations: map[string]string{NetworkTierAnnotationKey: "Premium"}, 57 | expectedTier: cloud.NetworkTierPremium, 58 | }, 59 | "Report an error on invalid network tier value": { 60 | annotations: map[string]string{NetworkTierAnnotationKey: "Unknown-tier"}, 61 | expectedTier: cloud.NetworkTierPremium, 62 | expectErr: true, 63 | }, 64 | } { 65 | t.Run(testName, func(t *testing.T) { 66 | svc := createTestService() 67 | svc.Annotations = testCase.annotations 68 | actualTier, err := GetServiceNetworkTier(svc) 69 | assert.Equal(t, testCase.expectedTier, actualTier) 70 | assert.Equal(t, testCase.expectErr, err != nil) 71 | }) 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /gce/gce_firewall.go: -------------------------------------------------------------------------------- 1 | // +build !providerless 2 | 3 | /* 4 | Copyright 2017 The Kubernetes Authors. 5 | 6 | Licensed under the Apache License, Version 2.0 (the "License"); 7 | you may not use this file except in compliance with the License. 8 | You may obtain a copy of the License at 9 | 10 | http://www.apache.org/licenses/LICENSE-2.0 11 | 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | */ 18 | 19 | package gce 20 | 21 | import ( 22 | compute "google.golang.org/api/compute/v1" 23 | 24 | "github.com/GoogleCloudPlatform/k8s-cloud-provider/pkg/cloud" 25 | "github.com/GoogleCloudPlatform/k8s-cloud-provider/pkg/cloud/meta" 26 | ) 27 | 28 | func newFirewallMetricContext(request string) *metricContext { 29 | return newGenericMetricContext("firewall", request, unusedMetricLabel, unusedMetricLabel, computeV1Version) 30 | } 31 | 32 | // GetFirewall returns the Firewall by name. 33 | func (g *Cloud) GetFirewall(name string) (*compute.Firewall, error) { 34 | ctx, cancel := cloud.ContextWithCallTimeout() 35 | defer cancel() 36 | 37 | mc := newFirewallMetricContext("get") 38 | v, err := g.c.Firewalls().Get(ctx, meta.GlobalKey(name)) 39 | return v, mc.Observe(err) 40 | } 41 | 42 | // CreateFirewall creates the passed firewall 43 | func (g *Cloud) CreateFirewall(f *compute.Firewall) error { 44 | ctx, cancel := cloud.ContextWithCallTimeout() 45 | defer cancel() 46 | 47 | mc := newFirewallMetricContext("create") 48 | return mc.Observe(g.c.Firewalls().Insert(ctx, meta.GlobalKey(f.Name), f)) 49 | } 50 | 51 | // DeleteFirewall deletes the given firewall rule. 52 | func (g *Cloud) DeleteFirewall(name string) error { 53 | ctx, cancel := cloud.ContextWithCallTimeout() 54 | defer cancel() 55 | 56 | mc := newFirewallMetricContext("delete") 57 | return mc.Observe(g.c.Firewalls().Delete(ctx, meta.GlobalKey(name))) 58 | } 59 | 60 | // UpdateFirewall applies the given firewall as an update to an existing service. 61 | func (g *Cloud) UpdateFirewall(f *compute.Firewall) error { 62 | ctx, cancel := cloud.ContextWithCallTimeout() 63 | defer cancel() 64 | 65 | mc := newFirewallMetricContext("update") 66 | return mc.Observe(g.c.Firewalls().Update(ctx, meta.GlobalKey(f.Name), f)) 67 | } 68 | -------------------------------------------------------------------------------- /azure/clients/interfaceclient/interface.go: -------------------------------------------------------------------------------- 1 | // +build !providerless 2 | 3 | /* 4 | Copyright 2020 The Kubernetes Authors. 5 | 6 | Licensed under the Apache License, Version 2.0 (the "License"); 7 | you may not use this file except in compliance with the License. 8 | You may obtain a copy of the License at 9 | 10 | http://www.apache.org/licenses/LICENSE-2.0 11 | 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | */ 18 | 19 | package interfaceclient 20 | 21 | import ( 22 | "context" 23 | 24 | "github.com/Azure/azure-sdk-for-go/services/network/mgmt/2019-06-01/network" 25 | "k8s.io/legacy-cloud-providers/azure/retry" 26 | ) 27 | 28 | const ( 29 | // APIVersion is the API version for network. 30 | APIVersion = "2019-06-01" 31 | 32 | // ComputeAPIVersion is the API version for compute. It is required to get VMSS network interface. 33 | ComputeAPIVersion = "2017-03-30" 34 | ) 35 | 36 | // Interface is the client interface for NetworkInterface. 37 | // Don't forget to run the following command to generate the mock client: 38 | // mockgen -source=$GOPATH/src/k8s.io/kubernetes/staging/src/k8s.io/legacy-cloud-providers/azure/clients/interfaceclient/interface.go -package=mockinterfaceclient Interface > $GOPATH/src/k8s.io/kubernetes/staging/src/k8s.io/legacy-cloud-providers/azure/clients/interfaceclient/mockinterfaceclient/interface.go 39 | type Interface interface { 40 | // Get gets a network.Interface. 41 | Get(ctx context.Context, resourceGroupName string, networkInterfaceName string, expand string) (result network.Interface, rerr *retry.Error) 42 | 43 | // GetVirtualMachineScaleSetNetworkInterface gets a network.Interface of VMSS VM. 44 | GetVirtualMachineScaleSetNetworkInterface(ctx context.Context, resourceGroupName string, virtualMachineScaleSetName string, virtualmachineIndex string, networkInterfaceName string, expand string) (result network.Interface, rerr *retry.Error) 45 | 46 | // CreateOrUpdate creates or updates a network.Interface. 47 | CreateOrUpdate(ctx context.Context, resourceGroupName string, networkInterfaceName string, parameters network.Interface) *retry.Error 48 | 49 | // Delete deletes a network interface by name. 50 | Delete(ctx context.Context, resourceGroupName string, networkInterfaceName string) *retry.Error 51 | } 52 | -------------------------------------------------------------------------------- /azure/clients/azure_client_config_test.go: -------------------------------------------------------------------------------- 1 | // +build !providerless 2 | 3 | /* 4 | Copyright 2019 The Kubernetes Authors. 5 | 6 | Licensed under the Apache License, Version 2.0 (the "License"); 7 | you may not use this file except in compliance with the License. 8 | You may obtain a copy of the License at 9 | 10 | http://www.apache.org/licenses/LICENSE-2.0 11 | 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | */ 18 | 19 | package clients 20 | 21 | import ( 22 | "testing" 23 | 24 | "github.com/stretchr/testify/assert" 25 | "k8s.io/client-go/util/flowcontrol" 26 | ) 27 | 28 | func TestWithRateLimiter(t *testing.T) { 29 | config := &ClientConfig{} 30 | assert.Nil(t, config.RateLimitConfig) 31 | c := config.WithRateLimiter(&RateLimitConfig{CloudProviderRateLimit: true}) 32 | assert.Equal(t, &RateLimitConfig{CloudProviderRateLimit: true}, c.RateLimitConfig) 33 | config.WithRateLimiter(nil) 34 | assert.Nil(t, config.RateLimitConfig) 35 | } 36 | 37 | func TestRateLimitEnabled(t *testing.T) { 38 | assert.Equal(t, false, RateLimitEnabled(nil)) 39 | config := &RateLimitConfig{} 40 | assert.Equal(t, false, RateLimitEnabled(config)) 41 | config.CloudProviderRateLimit = true 42 | assert.Equal(t, true, RateLimitEnabled(config)) 43 | } 44 | 45 | func TestNewRateLimiter(t *testing.T) { 46 | fakeRateLimiter := flowcontrol.NewFakeAlwaysRateLimiter() 47 | readLimiter, writeLimiter := NewRateLimiter(nil) 48 | assert.Equal(t, readLimiter, fakeRateLimiter) 49 | assert.Equal(t, writeLimiter, fakeRateLimiter) 50 | 51 | rateLimitConfig := &RateLimitConfig{ 52 | CloudProviderRateLimit: false, 53 | } 54 | readLimiter, writeLimiter = NewRateLimiter(rateLimitConfig) 55 | assert.Equal(t, readLimiter, fakeRateLimiter) 56 | assert.Equal(t, writeLimiter, fakeRateLimiter) 57 | 58 | rateLimitConfig = &RateLimitConfig{ 59 | CloudProviderRateLimit: true, 60 | CloudProviderRateLimitQPS: 3, 61 | CloudProviderRateLimitBucket: 10, 62 | CloudProviderRateLimitQPSWrite: 1, 63 | CloudProviderRateLimitBucketWrite: 3, 64 | } 65 | readLimiter, writeLimiter = NewRateLimiter(rateLimitConfig) 66 | assert.Equal(t, flowcontrol.NewTokenBucketRateLimiter(3, 10), readLimiter) 67 | assert.Equal(t, flowcontrol.NewTokenBucketRateLimiter(1, 3), writeLimiter) 68 | } 69 | -------------------------------------------------------------------------------- /aws/device_allocator_test.go: -------------------------------------------------------------------------------- 1 | // +build !providerless 2 | 3 | /* 4 | Copyright 2016 The Kubernetes Authors. 5 | 6 | Licensed under the Apache License, Version 2.0 (the "License"); 7 | you may not use this file except in compliance with the License. 8 | You may obtain a copy of the License at 9 | 10 | http://www.apache.org/licenses/LICENSE-2.0 11 | 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | */ 18 | 19 | package aws 20 | 21 | import "testing" 22 | 23 | func TestDeviceAllocator(t *testing.T) { 24 | tests := []struct { 25 | name string 26 | existingDevices ExistingDevices 27 | deviceMap map[mountDevice]int 28 | expectedOutput mountDevice 29 | }{ 30 | { 31 | "empty device list with wrap", 32 | ExistingDevices{}, 33 | generateUnsortedDeviceList(), 34 | "bd", // next to 'zz' is the first one, 'ba' 35 | }, 36 | } 37 | 38 | for _, test := range tests { 39 | allocator := NewDeviceAllocator().(*deviceAllocator) 40 | for k, v := range test.deviceMap { 41 | allocator.possibleDevices[k] = v 42 | } 43 | 44 | got, err := allocator.GetNext(test.existingDevices) 45 | if err != nil { 46 | t.Errorf("text %q: unexpected error: %v", test.name, err) 47 | } 48 | if got != test.expectedOutput { 49 | t.Errorf("text %q: expected %q, got %q", test.name, test.expectedOutput, got) 50 | } 51 | } 52 | } 53 | 54 | func generateUnsortedDeviceList() map[mountDevice]int { 55 | possibleDevices := make(map[mountDevice]int) 56 | for _, firstChar := range []rune{'b', 'c'} { 57 | for i := 'a'; i <= 'z'; i++ { 58 | dev := mountDevice([]rune{firstChar, i}) 59 | possibleDevices[dev] = 3 60 | } 61 | } 62 | possibleDevices["bd"] = 0 63 | return possibleDevices 64 | } 65 | 66 | func TestDeviceAllocatorError(t *testing.T) { 67 | allocator := NewDeviceAllocator().(*deviceAllocator) 68 | existingDevices := ExistingDevices{} 69 | 70 | // make all devices used 71 | var first, second byte 72 | for first = 'b'; first <= 'c'; first++ { 73 | for second = 'a'; second <= 'z'; second++ { 74 | device := [2]byte{first, second} 75 | existingDevices[mountDevice(device[:])] = "used" 76 | } 77 | } 78 | 79 | device, err := allocator.GetNext(existingDevices) 80 | if err == nil { 81 | t.Errorf("expected error, got device %q", device) 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /azure/azure_utils_test.go: -------------------------------------------------------------------------------- 1 | // +build !providerless 2 | 3 | /* 4 | Copyright 2019 The Kubernetes Authors. 5 | 6 | Licensed under the Apache License, Version 2.0 (the "License"); 7 | you may not use this file except in compliance with the License. 8 | You may obtain a copy of the License at 9 | 10 | http://www.apache.org/licenses/LICENSE-2.0 11 | 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | */ 18 | 19 | package azure 20 | 21 | import ( 22 | "testing" 23 | "time" 24 | ) 25 | 26 | func TestSimpleLockEntry(t *testing.T) { 27 | testLockMap := newLockMap() 28 | 29 | callbackChan1 := make(chan interface{}) 30 | go testLockMap.lockAndCallback(t, "entry1", callbackChan1) 31 | ensureCallbackHappens(t, callbackChan1) 32 | } 33 | 34 | func TestSimpleLockUnlockEntry(t *testing.T) { 35 | testLockMap := newLockMap() 36 | 37 | callbackChan1 := make(chan interface{}) 38 | go testLockMap.lockAndCallback(t, "entry1", callbackChan1) 39 | ensureCallbackHappens(t, callbackChan1) 40 | testLockMap.UnlockEntry("entry1") 41 | } 42 | 43 | func TestConcurrentLockEntry(t *testing.T) { 44 | testLockMap := newLockMap() 45 | 46 | callbackChan1 := make(chan interface{}) 47 | callbackChan2 := make(chan interface{}) 48 | 49 | go testLockMap.lockAndCallback(t, "entry1", callbackChan1) 50 | ensureCallbackHappens(t, callbackChan1) 51 | 52 | go testLockMap.lockAndCallback(t, "entry1", callbackChan2) 53 | ensureNoCallback(t, callbackChan2) 54 | 55 | testLockMap.UnlockEntry("entry1") 56 | ensureCallbackHappens(t, callbackChan2) 57 | testLockMap.UnlockEntry("entry1") 58 | } 59 | 60 | func (lm *lockMap) lockAndCallback(t *testing.T, entry string, callbackChan chan<- interface{}) { 61 | lm.LockEntry(entry) 62 | callbackChan <- true 63 | } 64 | 65 | var callbackTimeout = 2 * time.Second 66 | 67 | func ensureCallbackHappens(t *testing.T, callbackChan <-chan interface{}) bool { 68 | select { 69 | case <-callbackChan: 70 | return true 71 | case <-time.After(callbackTimeout): 72 | t.Fatalf("timed out waiting for callback") 73 | return false 74 | } 75 | } 76 | 77 | func ensureNoCallback(t *testing.T, callbackChan <-chan interface{}) bool { 78 | select { 79 | case <-callbackChan: 80 | t.Fatalf("unexpected callback") 81 | return false 82 | case <-time.After(callbackTimeout): 83 | return true 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | // This is a generated file. Do not edit directly. 2 | 3 | module k8s.io/legacy-cloud-providers 4 | 5 | go 1.13 6 | 7 | require ( 8 | cloud.google.com/go v0.38.0 9 | github.com/Azure/azure-sdk-for-go v35.0.0+incompatible 10 | github.com/Azure/go-autorest/autorest v0.9.0 11 | github.com/Azure/go-autorest/autorest/adal v0.5.0 12 | github.com/Azure/go-autorest/autorest/mocks v0.2.0 13 | github.com/Azure/go-autorest/autorest/to v0.2.0 14 | github.com/Azure/go-autorest/autorest/validation v0.1.0 // indirect 15 | github.com/GoogleCloudPlatform/k8s-cloud-provider v0.0.0-20190822182118-27a4ced34534 16 | github.com/aws/aws-sdk-go v1.28.2 17 | github.com/dnaeon/go-vcr v1.0.1 // indirect 18 | github.com/golang/mock v1.3.1 19 | github.com/gophercloud/gophercloud v0.1.0 20 | github.com/mitchellh/mapstructure v1.1.2 21 | github.com/rubiojr/go-vhd v0.0.0-20160810183302-0bfd3b39853c 22 | github.com/satori/go.uuid v1.2.0 // indirect 23 | github.com/stretchr/testify v1.4.0 24 | github.com/vmware/govmomi v0.20.3 25 | golang.org/x/crypto v0.0.0-20190820162420-60c769a6c586 26 | golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45 27 | google.golang.org/api v0.6.1-0.20190607001116-5213b8090861 28 | gopkg.in/gcfg.v1 v1.2.0 29 | gopkg.in/warnings.v0 v0.1.1 // indirect 30 | k8s.io/api v0.0.0-20200214081624-026463abc787 31 | k8s.io/apimachinery v0.0.0-20200214081019-7490b3ed6e92 32 | k8s.io/apiserver v0.0.0-20200216060338-73eccd1273c2 33 | k8s.io/client-go v0.0.0-20200216054614-a1d715839a20 34 | k8s.io/cloud-provider v0.0.0-20200214094126-93cd2cc615fd 35 | k8s.io/component-base v0.0.0-20200214083501-52da27f0465b 36 | k8s.io/csi-translation-lib v0.0.0-20200214094501-9a406d6c0575 37 | k8s.io/klog v1.0.0 38 | k8s.io/utils v0.0.0-20200117235808-5f6fbceb4c31 39 | sigs.k8s.io/yaml v1.2.0 40 | ) 41 | 42 | replace ( 43 | golang.org/x/sys => golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a // pinned to release-branch.go1.13 44 | golang.org/x/tools => golang.org/x/tools v0.0.0-20190821162956-65e3620a7ae7 // pinned to release-branch.go1.13 45 | k8s.io/api => k8s.io/api v0.0.0-20200214081624-026463abc787 46 | k8s.io/apimachinery => k8s.io/apimachinery v0.0.0-20200214081019-2373d029717c 47 | k8s.io/apiserver => k8s.io/apiserver v0.0.0-20200216060338-73eccd1273c2 48 | k8s.io/client-go => k8s.io/client-go v0.0.0-20200216054614-a1d715839a20 49 | k8s.io/cloud-provider => k8s.io/cloud-provider v0.0.0-20200214094126-93cd2cc615fd 50 | k8s.io/component-base => k8s.io/component-base v0.0.0-20200214083501-52da27f0465b 51 | k8s.io/csi-translation-lib => k8s.io/csi-translation-lib v0.0.0-20200214094501-9a406d6c0575 52 | ) 53 | -------------------------------------------------------------------------------- /azure/azure_storage.go: -------------------------------------------------------------------------------- 1 | // +build !providerless 2 | 3 | /* 4 | Copyright 2016 The Kubernetes Authors. 5 | 6 | Licensed under the Apache License, Version 2.0 (the "License"); 7 | you may not use this file except in compliance with the License. 8 | You may obtain a copy of the License at 9 | 10 | http://www.apache.org/licenses/LICENSE-2.0 11 | 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | */ 18 | 19 | package azure 20 | 21 | import ( 22 | "fmt" 23 | 24 | "github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2019-06-01/storage" 25 | 26 | "k8s.io/klog" 27 | ) 28 | 29 | const ( 30 | defaultStorageAccountType = string(storage.StandardLRS) 31 | defaultStorageAccountKind = storage.StorageV2 32 | fileShareAccountNamePrefix = "f" 33 | sharedDiskAccountNamePrefix = "ds" 34 | dedicatedDiskAccountNamePrefix = "dd" 35 | ) 36 | 37 | // CreateFileShare creates a file share, using a matching storage account type, account kind, etc. 38 | // storage account will be created if specified account is not found 39 | func (az *Cloud) CreateFileShare(shareName, accountName, accountType, accountKind, resourceGroup, location string, requestGiB int) (string, string, error) { 40 | if resourceGroup == "" { 41 | resourceGroup = az.resourceGroup 42 | } 43 | 44 | account, key, err := az.EnsureStorageAccount(accountName, accountType, accountKind, resourceGroup, location, fileShareAccountNamePrefix) 45 | if err != nil { 46 | return "", "", fmt.Errorf("could not get storage key for storage account %s: %v", accountName, err) 47 | } 48 | 49 | if err := az.createFileShare(account, key, shareName, requestGiB); err != nil { 50 | return "", "", fmt.Errorf("failed to create share %s in account %s: %v", shareName, account, err) 51 | } 52 | klog.V(4).Infof("created share %s in account %s", shareName, account) 53 | return account, key, nil 54 | } 55 | 56 | // DeleteFileShare deletes a file share using storage account name and key 57 | func (az *Cloud) DeleteFileShare(accountName, accountKey, shareName string) error { 58 | if err := az.deleteFileShare(accountName, accountKey, shareName); err != nil { 59 | return err 60 | } 61 | klog.V(4).Infof("share %s deleted", shareName) 62 | return nil 63 | } 64 | 65 | // ResizeFileShare resizes a file share 66 | func (az *Cloud) ResizeFileShare(accountName, accountKey, name string, sizeGiB int) error { 67 | return az.resizeFileShare(accountName, accountKey, name, sizeGiB) 68 | } 69 | -------------------------------------------------------------------------------- /gce/support.go: -------------------------------------------------------------------------------- 1 | // +build !providerless 2 | 3 | /* 4 | Copyright 2017 The Kubernetes Authors. 5 | 6 | Licensed under the Apache License, Version 2.0 (the "License"); 7 | you may not use this file except in compliance with the License. 8 | You may obtain a copy of the License at 9 | 10 | http://www.apache.org/licenses/LICENSE-2.0 11 | 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | */ 18 | 19 | package gce 20 | 21 | import ( 22 | "context" 23 | 24 | "github.com/GoogleCloudPlatform/k8s-cloud-provider/pkg/cloud" 25 | "github.com/GoogleCloudPlatform/k8s-cloud-provider/pkg/cloud/meta" 26 | ) 27 | 28 | // gceProjectRouter sends requests to the appropriate project ID. 29 | type gceProjectRouter struct { 30 | gce *Cloud 31 | } 32 | 33 | // ProjectID returns the project ID to be used for the given operation. 34 | func (r *gceProjectRouter) ProjectID(ctx context.Context, version meta.Version, service string) string { 35 | switch service { 36 | case "Firewalls", "Routes": 37 | return r.gce.NetworkProjectID() 38 | default: 39 | return r.gce.projectID 40 | } 41 | } 42 | 43 | // gceRateLimiter implements cloud.RateLimiter. 44 | type gceRateLimiter struct { 45 | gce *Cloud 46 | } 47 | 48 | // Accept blocks until the operation can be performed. 49 | // 50 | // TODO: the current cloud provider policy doesn't seem to be correct as it 51 | // only rate limits the polling operations, but not the /submission/ of 52 | // operations. 53 | func (l *gceRateLimiter) Accept(ctx context.Context, key *cloud.RateLimitKey) error { 54 | if key.Operation == "Get" && key.Service == "Operations" { 55 | // Wait a minimum amount of time regardless of rate limiter. 56 | rl := &cloud.MinimumRateLimiter{ 57 | // Convert flowcontrol.RateLimiter into cloud.RateLimiter 58 | RateLimiter: &cloud.AcceptRateLimiter{ 59 | Acceptor: l.gce.operationPollRateLimiter, 60 | }, 61 | Minimum: operationPollInterval, 62 | } 63 | return rl.Accept(ctx, key) 64 | } 65 | return nil 66 | } 67 | 68 | // CreateGCECloudWithCloud is a helper function to create an instance of Cloud with the 69 | // given Cloud interface implementation. Typical usage is to use cloud.NewMockGCE to get a 70 | // handle to a mock Cloud instance and then use that for testing. 71 | func CreateGCECloudWithCloud(config *CloudConfig, c cloud.Cloud) (*Cloud, error) { 72 | gceCloud, err := CreateGCECloud(config) 73 | if err == nil { 74 | gceCloud.c = c 75 | } 76 | return gceCloud, err 77 | } 78 | -------------------------------------------------------------------------------- /gce/gce_cert.go: -------------------------------------------------------------------------------- 1 | // +build !providerless 2 | 3 | /* 4 | Copyright 2017 The Kubernetes Authors. 5 | 6 | Licensed under the Apache License, Version 2.0 (the "License"); 7 | you may not use this file except in compliance with the License. 8 | You may obtain a copy of the License at 9 | 10 | http://www.apache.org/licenses/LICENSE-2.0 11 | 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | */ 18 | 19 | package gce 20 | 21 | import ( 22 | compute "google.golang.org/api/compute/v1" 23 | 24 | "github.com/GoogleCloudPlatform/k8s-cloud-provider/pkg/cloud" 25 | "github.com/GoogleCloudPlatform/k8s-cloud-provider/pkg/cloud/filter" 26 | "github.com/GoogleCloudPlatform/k8s-cloud-provider/pkg/cloud/meta" 27 | ) 28 | 29 | func newCertMetricContext(request string) *metricContext { 30 | return newGenericMetricContext("cert", request, unusedMetricLabel, unusedMetricLabel, computeV1Version) 31 | } 32 | 33 | // GetSslCertificate returns the SslCertificate by name. 34 | func (g *Cloud) GetSslCertificate(name string) (*compute.SslCertificate, error) { 35 | ctx, cancel := cloud.ContextWithCallTimeout() 36 | defer cancel() 37 | 38 | mc := newCertMetricContext("get") 39 | v, err := g.c.SslCertificates().Get(ctx, meta.GlobalKey(name)) 40 | return v, mc.Observe(err) 41 | } 42 | 43 | // CreateSslCertificate creates and returns a SslCertificate. 44 | func (g *Cloud) CreateSslCertificate(sslCerts *compute.SslCertificate) (*compute.SslCertificate, error) { 45 | ctx, cancel := cloud.ContextWithCallTimeout() 46 | defer cancel() 47 | 48 | mc := newCertMetricContext("create") 49 | err := g.c.SslCertificates().Insert(ctx, meta.GlobalKey(sslCerts.Name), sslCerts) 50 | if err != nil { 51 | return nil, mc.Observe(err) 52 | } 53 | return g.GetSslCertificate(sslCerts.Name) 54 | } 55 | 56 | // DeleteSslCertificate deletes the SslCertificate by name. 57 | func (g *Cloud) DeleteSslCertificate(name string) error { 58 | ctx, cancel := cloud.ContextWithCallTimeout() 59 | defer cancel() 60 | 61 | mc := newCertMetricContext("delete") 62 | return mc.Observe(g.c.SslCertificates().Delete(ctx, meta.GlobalKey(name))) 63 | } 64 | 65 | // ListSslCertificates lists all SslCertificates in the project. 66 | func (g *Cloud) ListSslCertificates() ([]*compute.SslCertificate, error) { 67 | ctx, cancel := cloud.ContextWithCallTimeout() 68 | defer cancel() 69 | 70 | mc := newCertMetricContext("list") 71 | v, err := g.c.SslCertificates().List(ctx, filter.None) 72 | return v, mc.Observe(err) 73 | } 74 | -------------------------------------------------------------------------------- /gce/gce_interfaces.go: -------------------------------------------------------------------------------- 1 | // +build !providerless 2 | 3 | /* 4 | Copyright 2017 The Kubernetes Authors. 5 | 6 | Licensed under the Apache License, Version 2.0 (the "License"); 7 | you may not use this file except in compliance with the License. 8 | You may obtain a copy of the License at 9 | 10 | http://www.apache.org/licenses/LICENSE-2.0 11 | 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | */ 18 | 19 | package gce 20 | 21 | import ( 22 | computealpha "google.golang.org/api/compute/v0.alpha" 23 | computebeta "google.golang.org/api/compute/v0.beta" 24 | compute "google.golang.org/api/compute/v1" 25 | ) 26 | 27 | // These interfaces are added for testability. 28 | 29 | // CloudAddressService is an interface for managing addresses 30 | type CloudAddressService interface { 31 | ReserveRegionAddress(address *compute.Address, region string) error 32 | GetRegionAddress(name string, region string) (*compute.Address, error) 33 | GetRegionAddressByIP(region, ipAddress string) (*compute.Address, error) 34 | DeleteRegionAddress(name, region string) error 35 | // TODO: Mock Global endpoints 36 | 37 | // Alpha API. 38 | GetAlphaRegionAddress(name, region string) (*computealpha.Address, error) 39 | ReserveAlphaRegionAddress(addr *computealpha.Address, region string) error 40 | 41 | // Beta API 42 | ReserveBetaRegionAddress(address *computebeta.Address, region string) error 43 | GetBetaRegionAddress(name string, region string) (*computebeta.Address, error) 44 | GetBetaRegionAddressByIP(region, ipAddress string) (*computebeta.Address, error) 45 | 46 | // TODO(#51665): Remove this once the Network Tiers becomes Alpha in GCP. 47 | getNetworkTierFromAddress(name, region string) (string, error) 48 | } 49 | 50 | // CloudForwardingRuleService is an interface for managing forwarding rules. 51 | // TODO: Expand the interface to include more methods. 52 | type CloudForwardingRuleService interface { 53 | GetRegionForwardingRule(name, region string) (*compute.ForwardingRule, error) 54 | CreateRegionForwardingRule(rule *compute.ForwardingRule, region string) error 55 | DeleteRegionForwardingRule(name, region string) error 56 | 57 | // Alpha API. 58 | GetAlphaRegionForwardingRule(name, region string) (*computealpha.ForwardingRule, error) 59 | CreateAlphaRegionForwardingRule(rule *computealpha.ForwardingRule, region string) error 60 | 61 | // Needed for the Alpha "Network Tiers" feature. 62 | getNetworkTierFromForwardingRule(name, region string) (string, error) 63 | } 64 | -------------------------------------------------------------------------------- /azure/clients/publicipclient/interface.go: -------------------------------------------------------------------------------- 1 | // +build !providerless 2 | 3 | /* 4 | Copyright 2020 The Kubernetes Authors. 5 | 6 | Licensed under the Apache License, Version 2.0 (the "License"); 7 | you may not use this file except in compliance with the License. 8 | You may obtain a copy of the License at 9 | 10 | http://www.apache.org/licenses/LICENSE-2.0 11 | 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | */ 18 | 19 | package publicipclient 20 | 21 | import ( 22 | "context" 23 | 24 | "github.com/Azure/azure-sdk-for-go/services/network/mgmt/2019-06-01/network" 25 | "k8s.io/legacy-cloud-providers/azure/retry" 26 | ) 27 | 28 | const ( 29 | // APIVersion is the API version for network. 30 | APIVersion = "2019-06-01" 31 | 32 | // ComputeAPIVersion is the API version for compute. It is required to get VMSS public IP. 33 | ComputeAPIVersion = "2017-03-30" 34 | ) 35 | 36 | // Interface is the client interface for PublicIPAddress. 37 | // Don't forget to run the following command to generate the mock client: 38 | // mockgen -source=$GOPATH/src/k8s.io/kubernetes/staging/src/k8s.io/legacy-cloud-providers/azure/clients/publicipclient/interface.go -package=mockpublicipclient Interface > $GOPATH/src/k8s.io/kubernetes/staging/src/k8s.io/legacy-cloud-providers/azure/clients/publicipclient/mockpublicipclient/interface.go 39 | type Interface interface { 40 | // Get gets a PublicIPAddress. 41 | Get(ctx context.Context, resourceGroupName string, publicIPAddressName string, expand string) (result network.PublicIPAddress, rerr *retry.Error) 42 | 43 | // GetVirtualMachineScaleSetPublicIPAddress gets a PublicIPAddress for VMSS VM. 44 | GetVirtualMachineScaleSetPublicIPAddress(ctx context.Context, resourceGroupName string, virtualMachineScaleSetName string, virtualmachineIndex string, networkInterfaceName string, IPConfigurationName string, publicIPAddressName string, expand string) (result network.PublicIPAddress, rerr *retry.Error) 45 | 46 | // List gets a list of PublicIPAddress in the resource group. 47 | List(ctx context.Context, resourceGroupName string) (result []network.PublicIPAddress, rerr *retry.Error) 48 | 49 | // CreateOrUpdate creates or updates a PublicIPAddress. 50 | CreateOrUpdate(ctx context.Context, resourceGroupName string, publicIPAddressName string, parameters network.PublicIPAddress) *retry.Error 51 | 52 | // Delete deletes a PublicIPAddress by name. 53 | Delete(ctx context.Context, resourceGroupName string, publicIPAddressName string) *retry.Error 54 | } 55 | -------------------------------------------------------------------------------- /gce/gce_urlmap.go: -------------------------------------------------------------------------------- 1 | // +build !providerless 2 | 3 | /* 4 | Copyright 2017 The Kubernetes Authors. 5 | 6 | Licensed under the Apache License, Version 2.0 (the "License"); 7 | you may not use this file except in compliance with the License. 8 | You may obtain a copy of the License at 9 | 10 | http://www.apache.org/licenses/LICENSE-2.0 11 | 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | */ 18 | 19 | package gce 20 | 21 | import ( 22 | compute "google.golang.org/api/compute/v1" 23 | 24 | "github.com/GoogleCloudPlatform/k8s-cloud-provider/pkg/cloud" 25 | "github.com/GoogleCloudPlatform/k8s-cloud-provider/pkg/cloud/filter" 26 | "github.com/GoogleCloudPlatform/k8s-cloud-provider/pkg/cloud/meta" 27 | ) 28 | 29 | func newURLMapMetricContext(request string) *metricContext { 30 | return newGenericMetricContext("urlmap", request, unusedMetricLabel, unusedMetricLabel, computeV1Version) 31 | } 32 | 33 | // GetURLMap returns the UrlMap by name. 34 | func (g *Cloud) GetURLMap(name string) (*compute.UrlMap, error) { 35 | ctx, cancel := cloud.ContextWithCallTimeout() 36 | defer cancel() 37 | 38 | mc := newURLMapMetricContext("get") 39 | v, err := g.c.UrlMaps().Get(ctx, meta.GlobalKey(name)) 40 | return v, mc.Observe(err) 41 | } 42 | 43 | // CreateURLMap creates a url map 44 | func (g *Cloud) CreateURLMap(urlMap *compute.UrlMap) error { 45 | ctx, cancel := cloud.ContextWithCallTimeout() 46 | defer cancel() 47 | 48 | mc := newURLMapMetricContext("create") 49 | return mc.Observe(g.c.UrlMaps().Insert(ctx, meta.GlobalKey(urlMap.Name), urlMap)) 50 | } 51 | 52 | // UpdateURLMap applies the given UrlMap as an update 53 | func (g *Cloud) UpdateURLMap(urlMap *compute.UrlMap) error { 54 | ctx, cancel := cloud.ContextWithCallTimeout() 55 | defer cancel() 56 | 57 | mc := newURLMapMetricContext("update") 58 | return mc.Observe(g.c.UrlMaps().Update(ctx, meta.GlobalKey(urlMap.Name), urlMap)) 59 | } 60 | 61 | // DeleteURLMap deletes a url map by name. 62 | func (g *Cloud) DeleteURLMap(name string) error { 63 | ctx, cancel := cloud.ContextWithCallTimeout() 64 | defer cancel() 65 | 66 | mc := newURLMapMetricContext("delete") 67 | return mc.Observe(g.c.UrlMaps().Delete(ctx, meta.GlobalKey(name))) 68 | } 69 | 70 | // ListURLMaps lists all UrlMaps in the project. 71 | func (g *Cloud) ListURLMaps() ([]*compute.UrlMap, error) { 72 | ctx, cancel := cloud.ContextWithCallTimeout() 73 | defer cancel() 74 | 75 | mc := newURLMapMetricContext("list") 76 | v, err := g.c.UrlMaps().List(ctx, filter.None) 77 | return v, mc.Observe(err) 78 | } 79 | -------------------------------------------------------------------------------- /gce/gce_fake.go: -------------------------------------------------------------------------------- 1 | // +build !providerless 2 | 3 | /* 4 | Copyright 2018 The Kubernetes Authors. 5 | 6 | Licensed under the Apache License, Version 2.0 (the "License"); 7 | you may not use this file except in compliance with the License. 8 | You may obtain a copy of the License at 9 | 10 | http://www.apache.org/licenses/LICENSE-2.0 11 | 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | */ 18 | 19 | package gce 20 | 21 | import ( 22 | "context" 23 | 24 | "github.com/GoogleCloudPlatform/k8s-cloud-provider/pkg/cloud" 25 | compute "google.golang.org/api/compute/v1" 26 | option "google.golang.org/api/option" 27 | "k8s.io/client-go/tools/cache" 28 | ) 29 | 30 | // TestClusterValues holds the config values for the fake/test gce cloud object. 31 | type TestClusterValues struct { 32 | ProjectID string 33 | Region string 34 | ZoneName string 35 | SecondaryZoneName string 36 | ClusterID string 37 | ClusterName string 38 | OnXPN bool 39 | } 40 | 41 | // DefaultTestClusterValues Creates a reasonable set of default cluster values 42 | // for generating a new test fake GCE cloud instance. 43 | func DefaultTestClusterValues() TestClusterValues { 44 | return TestClusterValues{ 45 | ProjectID: "test-project", 46 | Region: "us-central1", 47 | ZoneName: "us-central1-b", 48 | SecondaryZoneName: "us-central1-c", 49 | ClusterID: "test-cluster-id", 50 | ClusterName: "Test Cluster Name", 51 | } 52 | } 53 | 54 | // Stubs ClusterID so that ClusterID.getOrInitialize() does not require calling 55 | // gce.Initialize() 56 | func fakeClusterID(clusterID string) ClusterID { 57 | return ClusterID{ 58 | clusterID: &clusterID, 59 | store: cache.NewStore(func(obj interface{}) (string, error) { 60 | return "", nil 61 | }), 62 | } 63 | } 64 | 65 | // NewFakeGCECloud constructs a fake GCE Cloud from the cluster values. 66 | func NewFakeGCECloud(vals TestClusterValues) *Cloud { 67 | service, err := compute.NewService(context.Background(), option.WithoutAuthentication()) 68 | if err != nil { 69 | panic(err) 70 | } 71 | gce := &Cloud{ 72 | region: vals.Region, 73 | service: service, 74 | managedZones: []string{vals.ZoneName}, 75 | projectID: vals.ProjectID, 76 | networkProjectID: vals.ProjectID, 77 | ClusterID: fakeClusterID(vals.ClusterID), 78 | onXPN: vals.OnXPN, 79 | } 80 | c := cloud.NewMockGCE(&gceProjectRouter{gce}) 81 | gce.c = c 82 | return gce 83 | } 84 | 85 | // UpdateFakeGCECloud updates the fake GCE cloud with the specified values. Currently only the onXPN value is updated. 86 | func UpdateFakeGCECloud(g *Cloud, vals TestClusterValues) { 87 | g.onXPN = vals.OnXPN 88 | } 89 | -------------------------------------------------------------------------------- /azure/clients/routeclient/azure_routeclient_test.go: -------------------------------------------------------------------------------- 1 | // +build !providerless 2 | 3 | /* 4 | Copyright 2020 The Kubernetes Authors. 5 | 6 | Licensed under the Apache License, Version 2.0 (the "License"); 7 | you may not use this file except in compliance with the License. 8 | You may obtain a copy of the License at 9 | 10 | http://www.apache.org/licenses/LICENSE-2.0 11 | 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | */ 18 | 19 | package routeclient 20 | 21 | import ( 22 | "bytes" 23 | "context" 24 | "fmt" 25 | "io/ioutil" 26 | "net/http" 27 | "testing" 28 | 29 | "github.com/Azure/azure-sdk-for-go/services/network/mgmt/2019-06-01/network" 30 | "github.com/Azure/go-autorest/autorest/to" 31 | "github.com/golang/mock/gomock" 32 | "github.com/stretchr/testify/assert" 33 | 34 | azclients "k8s.io/legacy-cloud-providers/azure/clients" 35 | "k8s.io/legacy-cloud-providers/azure/clients/armclient" 36 | "k8s.io/legacy-cloud-providers/azure/clients/armclient/mockarmclient" 37 | ) 38 | 39 | func TestCreateOrUpdate(t *testing.T) { 40 | ctrl := gomock.NewController(t) 41 | defer ctrl.Finish() 42 | 43 | r := getTestRoute("r1") 44 | armClient := mockarmclient.NewMockInterface(ctrl) 45 | response := &http.Response{ 46 | StatusCode: http.StatusOK, 47 | Body: ioutil.NopCloser(bytes.NewReader([]byte(""))), 48 | } 49 | armClient.EXPECT().PutResourceWithDecorators(gomock.Any(), to.String(r.ID), r, gomock.Any()).Return(response, nil).Times(1) 50 | armClient.EXPECT().CloseResponse(gomock.Any(), gomock.Any()).Times(1) 51 | 52 | rtClient := getTestRouteClient(armClient) 53 | rerr := rtClient.CreateOrUpdate(context.TODO(), "rg", "rt", "r1", r, "") 54 | assert.Nil(t, rerr) 55 | } 56 | 57 | func TestDelete(t *testing.T) { 58 | ctrl := gomock.NewController(t) 59 | defer ctrl.Finish() 60 | 61 | r := getTestRoute("r1") 62 | armClient := mockarmclient.NewMockInterface(ctrl) 63 | armClient.EXPECT().DeleteResource(gomock.Any(), to.String(r.ID), "").Return(nil).Times(1) 64 | 65 | rtClient := getTestRouteClient(armClient) 66 | rerr := rtClient.Delete(context.TODO(), "rg", "rt", "r1") 67 | assert.Nil(t, rerr) 68 | } 69 | 70 | func getTestRoute(name string) network.Route { 71 | return network.Route{ 72 | ID: to.StringPtr(fmt.Sprintf("/subscriptions/subscriptionID/resourceGroups/rg/providers/Microsoft.Network/routeTables/rt/routes/%s", name)), 73 | Name: to.StringPtr(name), 74 | } 75 | } 76 | 77 | func getTestRouteClient(armClient armclient.Interface) *Client { 78 | rateLimiterReader, rateLimiterWriter := azclients.NewRateLimiter(&azclients.RateLimitConfig{}) 79 | return &Client{ 80 | armClient: armClient, 81 | subscriptionID: "subscriptionID", 82 | rateLimiterReader: rateLimiterReader, 83 | rateLimiterWriter: rateLimiterWriter, 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /gce/gce_targetpool.go: -------------------------------------------------------------------------------- 1 | // +build !providerless 2 | 3 | /* 4 | Copyright 2017 The Kubernetes Authors. 5 | 6 | Licensed under the Apache License, Version 2.0 (the "License"); 7 | you may not use this file except in compliance with the License. 8 | You may obtain a copy of the License at 9 | 10 | http://www.apache.org/licenses/LICENSE-2.0 11 | 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | */ 18 | 19 | package gce 20 | 21 | import ( 22 | compute "google.golang.org/api/compute/v1" 23 | 24 | "github.com/GoogleCloudPlatform/k8s-cloud-provider/pkg/cloud" 25 | "github.com/GoogleCloudPlatform/k8s-cloud-provider/pkg/cloud/meta" 26 | ) 27 | 28 | func newTargetPoolMetricContext(request, region string) *metricContext { 29 | return newGenericMetricContext("targetpool", request, region, unusedMetricLabel, computeV1Version) 30 | } 31 | 32 | // GetTargetPool returns the TargetPool by name. 33 | func (g *Cloud) GetTargetPool(name, region string) (*compute.TargetPool, error) { 34 | ctx, cancel := cloud.ContextWithCallTimeout() 35 | defer cancel() 36 | 37 | mc := newTargetPoolMetricContext("get", region) 38 | v, err := g.c.TargetPools().Get(ctx, meta.RegionalKey(name, region)) 39 | return v, mc.Observe(err) 40 | } 41 | 42 | // CreateTargetPool creates the passed TargetPool 43 | func (g *Cloud) CreateTargetPool(tp *compute.TargetPool, region string) error { 44 | ctx, cancel := cloud.ContextWithCallTimeout() 45 | defer cancel() 46 | 47 | mc := newTargetPoolMetricContext("create", region) 48 | return mc.Observe(g.c.TargetPools().Insert(ctx, meta.RegionalKey(tp.Name, region), tp)) 49 | } 50 | 51 | // DeleteTargetPool deletes TargetPool by name. 52 | func (g *Cloud) DeleteTargetPool(name, region string) error { 53 | ctx, cancel := cloud.ContextWithCallTimeout() 54 | defer cancel() 55 | 56 | mc := newTargetPoolMetricContext("delete", region) 57 | return mc.Observe(g.c.TargetPools().Delete(ctx, meta.RegionalKey(name, region))) 58 | } 59 | 60 | // AddInstancesToTargetPool adds instances by link to the TargetPool 61 | func (g *Cloud) AddInstancesToTargetPool(name, region string, instanceRefs []*compute.InstanceReference) error { 62 | ctx, cancel := cloud.ContextWithCallTimeout() 63 | defer cancel() 64 | 65 | req := &compute.TargetPoolsAddInstanceRequest{ 66 | Instances: instanceRefs, 67 | } 68 | mc := newTargetPoolMetricContext("add_instances", region) 69 | return mc.Observe(g.c.TargetPools().AddInstance(ctx, meta.RegionalKey(name, region), req)) 70 | } 71 | 72 | // RemoveInstancesFromTargetPool removes instances by link to the TargetPool 73 | func (g *Cloud) RemoveInstancesFromTargetPool(name, region string, instanceRefs []*compute.InstanceReference) error { 74 | ctx, cancel := cloud.ContextWithCallTimeout() 75 | defer cancel() 76 | 77 | req := &compute.TargetPoolsRemoveInstanceRequest{ 78 | Instances: instanceRefs, 79 | } 80 | mc := newTargetPoolMetricContext("remove_instances", region) 81 | return mc.Observe(g.c.TargetPools().RemoveInstance(ctx, meta.RegionalKey(name, region), req)) 82 | } 83 | -------------------------------------------------------------------------------- /azure/azure_config.go: -------------------------------------------------------------------------------- 1 | // +build !providerless 2 | 3 | /* 4 | Copyright 2019 The Kubernetes Authors. 5 | 6 | Licensed under the Apache License, Version 2.0 (the "License"); 7 | you may not use this file except in compliance with the License. 8 | You may obtain a copy of the License at 9 | 10 | http://www.apache.org/licenses/LICENSE-2.0 11 | 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | */ 18 | 19 | package azure 20 | 21 | import ( 22 | "context" 23 | "fmt" 24 | 25 | metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 26 | "k8s.io/klog" 27 | "sigs.k8s.io/yaml" 28 | ) 29 | 30 | const ( 31 | cloudConfigNamespace = "kube-system" 32 | cloudConfigKey = "cloud-config" 33 | cloudConfigSecretName = "azure-cloud-provider" 34 | ) 35 | 36 | // The config type for Azure cloud provider secret. Supported values are: 37 | // * file : The values are read from local cloud-config file. 38 | // * secret : The values from secret would override all configures from local cloud-config file. 39 | // * merge : The values from secret would override only configurations that are explicitly set in the secret. This is the default value. 40 | type cloudConfigType string 41 | 42 | const ( 43 | cloudConfigTypeFile cloudConfigType = "file" 44 | cloudConfigTypeSecret cloudConfigType = "secret" 45 | cloudConfigTypeMerge cloudConfigType = "merge" 46 | ) 47 | 48 | // InitializeCloudFromSecret initializes Azure cloud provider from Kubernetes secret. 49 | func (az *Cloud) InitializeCloudFromSecret() { 50 | config, err := az.getConfigFromSecret() 51 | if err != nil { 52 | klog.Warningf("Failed to get cloud-config from secret: %v, skip initializing from secret", err) 53 | return 54 | } 55 | 56 | if config == nil { 57 | // Skip re-initialization if the config is not override. 58 | return 59 | } 60 | 61 | if err := az.InitializeCloudFromConfig(config, true); err != nil { 62 | klog.Errorf("Failed to initialize Azure cloud provider: %v", err) 63 | } 64 | } 65 | 66 | func (az *Cloud) getConfigFromSecret() (*Config, error) { 67 | // Read config from file and no override, return nil. 68 | if az.Config.CloudConfigType == cloudConfigTypeFile { 69 | return nil, nil 70 | } 71 | 72 | secret, err := az.kubeClient.CoreV1().Secrets(cloudConfigNamespace).Get(context.TODO(), cloudConfigSecretName, metav1.GetOptions{}) 73 | if err != nil { 74 | return nil, fmt.Errorf("failed to get secret %s: %v", cloudConfigSecretName, err) 75 | } 76 | 77 | cloudConfigData, ok := secret.Data[cloudConfigKey] 78 | if !ok { 79 | return nil, fmt.Errorf("cloud-config is not set in the secret (%s)", cloudConfigSecretName) 80 | } 81 | 82 | config := Config{} 83 | if az.Config.CloudConfigType == "" || az.Config.CloudConfigType == cloudConfigTypeMerge { 84 | // Merge cloud config, set default value to existing config. 85 | config = az.Config 86 | } 87 | 88 | err = yaml.Unmarshal(cloudConfigData, &config) 89 | if err != nil { 90 | return nil, fmt.Errorf("failed to parse Azure cloud-config: %v", err) 91 | } 92 | 93 | return &config, nil 94 | } 95 | -------------------------------------------------------------------------------- /vsphere/vclib/diskmanagers/virtualdisk.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2016 The Kubernetes 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 diskmanagers 18 | 19 | import ( 20 | "context" 21 | "fmt" 22 | 23 | "k8s.io/klog" 24 | "k8s.io/legacy-cloud-providers/vsphere/vclib" 25 | ) 26 | 27 | // VirtualDisk is for the Disk Management 28 | type VirtualDisk struct { 29 | DiskPath string 30 | VolumeOptions *vclib.VolumeOptions 31 | VMOptions *vclib.VMOptions 32 | } 33 | 34 | // VirtualDisk Operations Const 35 | const ( 36 | VirtualDiskCreateOperation = "Create" 37 | VirtualDiskDeleteOperation = "Delete" 38 | ) 39 | 40 | // VirtualDiskProvider defines interfaces for creating disk 41 | type VirtualDiskProvider interface { 42 | Create(ctx context.Context, datastore *vclib.Datastore) (string, error) 43 | Delete(ctx context.Context, datacenter *vclib.Datacenter) error 44 | } 45 | 46 | // getDiskManager returns vmDiskManager or vdmDiskManager based on given volumeoptions 47 | func getDiskManager(disk *VirtualDisk, diskOperation string) VirtualDiskProvider { 48 | var diskProvider VirtualDiskProvider 49 | switch diskOperation { 50 | case VirtualDiskDeleteOperation: 51 | diskProvider = virtualDiskManager{disk.DiskPath, disk.VolumeOptions} 52 | case VirtualDiskCreateOperation: 53 | if disk.VolumeOptions.StoragePolicyName != "" || disk.VolumeOptions.VSANStorageProfileData != "" || disk.VolumeOptions.StoragePolicyID != "" { 54 | diskProvider = vmDiskManager{disk.DiskPath, disk.VolumeOptions, disk.VMOptions} 55 | } else { 56 | diskProvider = virtualDiskManager{disk.DiskPath, disk.VolumeOptions} 57 | } 58 | } 59 | return diskProvider 60 | } 61 | 62 | // Create gets appropriate disk manager and calls respective create method 63 | func (virtualDisk *VirtualDisk) Create(ctx context.Context, datastore *vclib.Datastore) (string, error) { 64 | if virtualDisk.VolumeOptions.DiskFormat == "" { 65 | virtualDisk.VolumeOptions.DiskFormat = vclib.ThinDiskType 66 | } 67 | if !virtualDisk.VolumeOptions.VerifyVolumeOptions() { 68 | klog.Error("VolumeOptions verification failed. volumeOptions: ", virtualDisk.VolumeOptions) 69 | return "", vclib.ErrInvalidVolumeOptions 70 | } 71 | if virtualDisk.VolumeOptions.StoragePolicyID != "" && virtualDisk.VolumeOptions.StoragePolicyName != "" { 72 | return "", fmt.Errorf("Storage Policy ID and Storage Policy Name both set, Please set only one parameter") 73 | } 74 | return getDiskManager(virtualDisk, VirtualDiskCreateOperation).Create(ctx, datastore) 75 | } 76 | 77 | // Delete gets appropriate disk manager and calls respective delete method 78 | func (virtualDisk *VirtualDisk) Delete(ctx context.Context, datacenter *vclib.Datacenter) error { 79 | return getDiskManager(virtualDisk, VirtualDiskDeleteOperation).Delete(ctx, datacenter) 80 | } 81 | -------------------------------------------------------------------------------- /azure/clients/routetableclient/mockroutetableclient/interface.go: -------------------------------------------------------------------------------- 1 | // +build !providerless 2 | 3 | /* 4 | Copyright 2020 The Kubernetes Authors. 5 | 6 | Licensed under the Apache License, Version 2.0 (the "License"); 7 | you may not use this file except in compliance with the License. 8 | You may obtain a copy of the License at 9 | 10 | http://www.apache.org/licenses/LICENSE-2.0 11 | 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | */ 18 | 19 | package mockroutetableclient 20 | 21 | import ( 22 | context "context" 23 | reflect "reflect" 24 | 25 | network "github.com/Azure/azure-sdk-for-go/services/network/mgmt/2019-06-01/network" 26 | gomock "github.com/golang/mock/gomock" 27 | retry "k8s.io/legacy-cloud-providers/azure/retry" 28 | ) 29 | 30 | // MockInterface is a mock of Interface interface 31 | type MockInterface struct { 32 | ctrl *gomock.Controller 33 | recorder *MockInterfaceMockRecorder 34 | } 35 | 36 | // MockInterfaceMockRecorder is the mock recorder for MockInterface 37 | type MockInterfaceMockRecorder struct { 38 | mock *MockInterface 39 | } 40 | 41 | // NewMockInterface creates a new mock instance 42 | func NewMockInterface(ctrl *gomock.Controller) *MockInterface { 43 | mock := &MockInterface{ctrl: ctrl} 44 | mock.recorder = &MockInterfaceMockRecorder{mock} 45 | return mock 46 | } 47 | 48 | // EXPECT returns an object that allows the caller to indicate expected use 49 | func (m *MockInterface) EXPECT() *MockInterfaceMockRecorder { 50 | return m.recorder 51 | } 52 | 53 | // Get mocks base method 54 | func (m *MockInterface) Get(ctx context.Context, resourceGroupName, routeTableName, expand string) (network.RouteTable, *retry.Error) { 55 | m.ctrl.T.Helper() 56 | ret := m.ctrl.Call(m, "Get", ctx, resourceGroupName, routeTableName, expand) 57 | ret0, _ := ret[0].(network.RouteTable) 58 | ret1, _ := ret[1].(*retry.Error) 59 | return ret0, ret1 60 | } 61 | 62 | // Get indicates an expected call of Get 63 | func (mr *MockInterfaceMockRecorder) Get(ctx, resourceGroupName, routeTableName, expand interface{}) *gomock.Call { 64 | mr.mock.ctrl.T.Helper() 65 | return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Get", reflect.TypeOf((*MockInterface)(nil).Get), ctx, resourceGroupName, routeTableName, expand) 66 | } 67 | 68 | // CreateOrUpdate mocks base method 69 | func (m *MockInterface) CreateOrUpdate(ctx context.Context, resourceGroupName, routeTableName string, parameters network.RouteTable, etag string) *retry.Error { 70 | m.ctrl.T.Helper() 71 | ret := m.ctrl.Call(m, "CreateOrUpdate", ctx, resourceGroupName, routeTableName, parameters, etag) 72 | ret0, _ := ret[0].(*retry.Error) 73 | return ret0 74 | } 75 | 76 | // CreateOrUpdate indicates an expected call of CreateOrUpdate 77 | func (mr *MockInterfaceMockRecorder) CreateOrUpdate(ctx, resourceGroupName, routeTableName, parameters, etag interface{}) *gomock.Call { 78 | mr.mock.ctrl.T.Helper() 79 | return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CreateOrUpdate", reflect.TypeOf((*MockInterface)(nil).CreateOrUpdate), ctx, resourceGroupName, routeTableName, parameters, etag) 80 | } 81 | -------------------------------------------------------------------------------- /azure/clients/routeclient/mockrouteclient/interface.go: -------------------------------------------------------------------------------- 1 | // +build !providerless 2 | 3 | /* 4 | Copyright 2020 The Kubernetes Authors. 5 | 6 | Licensed under the Apache License, Version 2.0 (the "License"); 7 | you may not use this file except in compliance with the License. 8 | You may obtain a copy of the License at 9 | 10 | http://www.apache.org/licenses/LICENSE-2.0 11 | 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | */ 18 | 19 | package mockrouteclient 20 | 21 | import ( 22 | context "context" 23 | reflect "reflect" 24 | 25 | network "github.com/Azure/azure-sdk-for-go/services/network/mgmt/2019-06-01/network" 26 | gomock "github.com/golang/mock/gomock" 27 | retry "k8s.io/legacy-cloud-providers/azure/retry" 28 | ) 29 | 30 | // MockInterface is a mock of Interface interface 31 | type MockInterface struct { 32 | ctrl *gomock.Controller 33 | recorder *MockInterfaceMockRecorder 34 | } 35 | 36 | // MockInterfaceMockRecorder is the mock recorder for MockInterface 37 | type MockInterfaceMockRecorder struct { 38 | mock *MockInterface 39 | } 40 | 41 | // NewMockInterface creates a new mock instance 42 | func NewMockInterface(ctrl *gomock.Controller) *MockInterface { 43 | mock := &MockInterface{ctrl: ctrl} 44 | mock.recorder = &MockInterfaceMockRecorder{mock} 45 | return mock 46 | } 47 | 48 | // EXPECT returns an object that allows the caller to indicate expected use 49 | func (m *MockInterface) EXPECT() *MockInterfaceMockRecorder { 50 | return m.recorder 51 | } 52 | 53 | // CreateOrUpdate mocks base method 54 | func (m *MockInterface) CreateOrUpdate(ctx context.Context, resourceGroupName, routeTableName, routeName string, routeParameters network.Route, etag string) *retry.Error { 55 | m.ctrl.T.Helper() 56 | ret := m.ctrl.Call(m, "CreateOrUpdate", ctx, resourceGroupName, routeTableName, routeName, routeParameters, etag) 57 | ret0, _ := ret[0].(*retry.Error) 58 | return ret0 59 | } 60 | 61 | // CreateOrUpdate indicates an expected call of CreateOrUpdate 62 | func (mr *MockInterfaceMockRecorder) CreateOrUpdate(ctx, resourceGroupName, routeTableName, routeName, routeParameters, etag interface{}) *gomock.Call { 63 | mr.mock.ctrl.T.Helper() 64 | return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CreateOrUpdate", reflect.TypeOf((*MockInterface)(nil).CreateOrUpdate), ctx, resourceGroupName, routeTableName, routeName, routeParameters, etag) 65 | } 66 | 67 | // Delete mocks base method 68 | func (m *MockInterface) Delete(ctx context.Context, resourceGroupName, routeTableName, routeName string) *retry.Error { 69 | m.ctrl.T.Helper() 70 | ret := m.ctrl.Call(m, "Delete", ctx, resourceGroupName, routeTableName, routeName) 71 | ret0, _ := ret[0].(*retry.Error) 72 | return ret0 73 | } 74 | 75 | // Delete indicates an expected call of Delete 76 | func (mr *MockInterfaceMockRecorder) Delete(ctx, resourceGroupName, routeTableName, routeName interface{}) *gomock.Call { 77 | mr.mock.ctrl.T.Helper() 78 | return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Delete", reflect.TypeOf((*MockInterface)(nil).Delete), ctx, resourceGroupName, routeTableName, routeName) 79 | } 80 | -------------------------------------------------------------------------------- /gce/gce_healthchecks_test.go: -------------------------------------------------------------------------------- 1 | // +build !providerless 2 | 3 | /* 4 | Copyright 2017 The Kubernetes Authors. 5 | 6 | Licensed under the Apache License, Version 2.0 (the "License"); 7 | you may not use this file except in compliance with the License. 8 | You may obtain a copy of the License at 9 | 10 | http://www.apache.org/licenses/LICENSE-2.0 11 | 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | */ 18 | 19 | package gce 20 | 21 | import ( 22 | "testing" 23 | 24 | "k8s.io/api/core/v1" 25 | ) 26 | 27 | func TestIsAtLeastMinNodesHealthCheckVersion(t *testing.T) { 28 | testCases := []struct { 29 | version string 30 | expect bool 31 | }{ 32 | {"v1.7.3", true}, 33 | {"v1.7.2", true}, 34 | {"v1.7.2-alpha.2.597+276d289b90d322", true}, 35 | {"v1.6.0-beta.3.472+831q821c907t31a", false}, 36 | {"v1.5.2", false}, 37 | } 38 | 39 | for _, tc := range testCases { 40 | if res := isAtLeastMinNodesHealthCheckVersion(tc.version); res != tc.expect { 41 | t.Errorf("%v: want %v, got %v", tc.version, tc.expect, res) 42 | } 43 | } 44 | } 45 | 46 | func TestSupportsNodesHealthCheck(t *testing.T) { 47 | testCases := []struct { 48 | desc string 49 | nodes []*v1.Node 50 | expect bool 51 | }{ 52 | { 53 | "All nodes support nodes health check", 54 | []*v1.Node{ 55 | { 56 | Status: v1.NodeStatus{ 57 | NodeInfo: v1.NodeSystemInfo{ 58 | KubeProxyVersion: "v1.7.2", 59 | }, 60 | }, 61 | }, 62 | { 63 | Status: v1.NodeStatus{ 64 | NodeInfo: v1.NodeSystemInfo{ 65 | KubeProxyVersion: "v1.7.2-alpha.2.597+276d289b90d322", 66 | }, 67 | }, 68 | }, 69 | }, 70 | true, 71 | }, 72 | { 73 | "All nodes don't support nodes health check", 74 | []*v1.Node{ 75 | { 76 | Status: v1.NodeStatus{ 77 | NodeInfo: v1.NodeSystemInfo{ 78 | KubeProxyVersion: "v1.6.0-beta.3.472+831q821c907t31a", 79 | }, 80 | }, 81 | }, 82 | { 83 | Status: v1.NodeStatus{ 84 | NodeInfo: v1.NodeSystemInfo{ 85 | KubeProxyVersion: "v1.5.2", 86 | }, 87 | }, 88 | }, 89 | }, 90 | false, 91 | }, 92 | { 93 | "One node doesn't support nodes health check", 94 | []*v1.Node{ 95 | { 96 | Status: v1.NodeStatus{ 97 | NodeInfo: v1.NodeSystemInfo{ 98 | KubeProxyVersion: "v1.7.3", 99 | }, 100 | }, 101 | }, 102 | { 103 | Status: v1.NodeStatus{ 104 | NodeInfo: v1.NodeSystemInfo{ 105 | KubeProxyVersion: "v1.7.2-alpha.2.597+276d289b90d322", 106 | }, 107 | }, 108 | }, 109 | { 110 | Status: v1.NodeStatus{ 111 | NodeInfo: v1.NodeSystemInfo{ 112 | KubeProxyVersion: "v1.5.2", 113 | }, 114 | }, 115 | }, 116 | }, 117 | false, 118 | }, 119 | } 120 | 121 | for _, tc := range testCases { 122 | if res := supportsNodesHealthCheck(tc.nodes); res != tc.expect { 123 | t.Errorf("%v: want %v, got %v", tc.desc, tc.expect, res) 124 | } 125 | } 126 | } 127 | -------------------------------------------------------------------------------- /gce/gce_zones.go: -------------------------------------------------------------------------------- 1 | // +build !providerless 2 | 3 | /* 4 | Copyright 2017 The Kubernetes Authors. 5 | 6 | Licensed under the Apache License, Version 2.0 (the "License"); 7 | you may not use this file except in compliance with the License. 8 | You may obtain a copy of the License at 9 | 10 | http://www.apache.org/licenses/LICENSE-2.0 11 | 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | */ 18 | 19 | package gce 20 | 21 | import ( 22 | "context" 23 | "strings" 24 | 25 | compute "google.golang.org/api/compute/v1" 26 | 27 | "github.com/GoogleCloudPlatform/k8s-cloud-provider/pkg/cloud" 28 | "github.com/GoogleCloudPlatform/k8s-cloud-provider/pkg/cloud/filter" 29 | "k8s.io/apimachinery/pkg/types" 30 | cloudprovider "k8s.io/cloud-provider" 31 | ) 32 | 33 | func newZonesMetricContext(request, region string) *metricContext { 34 | return newGenericMetricContext("zones", request, region, unusedMetricLabel, computeV1Version) 35 | } 36 | 37 | // GetZone creates a cloudprovider.Zone of the current zone and region 38 | func (g *Cloud) GetZone(ctx context.Context) (cloudprovider.Zone, error) { 39 | return cloudprovider.Zone{ 40 | FailureDomain: g.localZone, 41 | Region: g.region, 42 | }, nil 43 | } 44 | 45 | // GetZoneByProviderID implements Zones.GetZoneByProviderID 46 | // This is particularly useful in external cloud providers where the kubelet 47 | // does not initialize node data. 48 | func (g *Cloud) GetZoneByProviderID(ctx context.Context, providerID string) (cloudprovider.Zone, error) { 49 | _, zone, _, err := splitProviderID(providerID) 50 | if err != nil { 51 | return cloudprovider.Zone{}, err 52 | } 53 | region, err := GetGCERegion(zone) 54 | if err != nil { 55 | return cloudprovider.Zone{}, err 56 | } 57 | return cloudprovider.Zone{FailureDomain: zone, Region: region}, nil 58 | } 59 | 60 | // GetZoneByNodeName implements Zones.GetZoneByNodeName 61 | // This is particularly useful in external cloud providers where the kubelet 62 | // does not initialize node data. 63 | func (g *Cloud) GetZoneByNodeName(ctx context.Context, nodeName types.NodeName) (cloudprovider.Zone, error) { 64 | instanceName := mapNodeNameToInstanceName(nodeName) 65 | instance, err := g.getInstanceByName(instanceName) 66 | if err != nil { 67 | return cloudprovider.Zone{}, err 68 | } 69 | region, err := GetGCERegion(instance.Zone) 70 | if err != nil { 71 | return cloudprovider.Zone{}, err 72 | } 73 | return cloudprovider.Zone{FailureDomain: instance.Zone, Region: region}, nil 74 | } 75 | 76 | // ListZonesInRegion returns all zones in a GCP region 77 | func (g *Cloud) ListZonesInRegion(region string) ([]*compute.Zone, error) { 78 | ctx, cancel := cloud.ContextWithCallTimeout() 79 | defer cancel() 80 | 81 | mc := newZonesMetricContext("list", region) 82 | list, err := g.c.Zones().List(ctx, filter.Regexp("region", g.getRegionLink(region))) 83 | if err != nil { 84 | return nil, mc.Observe(err) 85 | } 86 | return list, mc.Observe(err) 87 | } 88 | 89 | func (g *Cloud) getRegionLink(region string) string { 90 | return g.service.BasePath + strings.Join([]string{g.projectID, "regions", region}, "/") 91 | } 92 | -------------------------------------------------------------------------------- /gce/metrics.go: -------------------------------------------------------------------------------- 1 | // +build !providerless 2 | 3 | /* 4 | Copyright 2014 The Kubernetes Authors. 5 | 6 | Licensed under the Apache License, Version 2.0 (the "License"); 7 | you may not use this file except in compliance with the License. 8 | You may obtain a copy of the License at 9 | 10 | http://www.apache.org/licenses/LICENSE-2.0 11 | 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | */ 18 | 19 | package gce 20 | 21 | import ( 22 | "time" 23 | 24 | "k8s.io/component-base/metrics" 25 | "k8s.io/component-base/metrics/legacyregistry" 26 | ) 27 | 28 | const ( 29 | // Version strings for recording metrics. 30 | computeV1Version = "v1" 31 | computeAlphaVersion = "alpha" 32 | computeBetaVersion = "beta" 33 | ) 34 | 35 | type apiCallMetrics struct { 36 | latency *metrics.HistogramVec 37 | errors *metrics.CounterVec 38 | } 39 | 40 | var ( 41 | metricLabels = []string{ 42 | "request", // API function that is begin invoked. 43 | "region", // region (optional). 44 | "zone", // zone (optional). 45 | "version", // API version. 46 | } 47 | 48 | apiMetrics = registerAPIMetrics(metricLabels...) 49 | ) 50 | 51 | type metricContext struct { 52 | start time.Time 53 | // The cardinalities of attributes and metricLabels (defined above) must 54 | // match, or prometheus will panic. 55 | attributes []string 56 | } 57 | 58 | // Value for an unused label in the metric dimension. 59 | const unusedMetricLabel = "" 60 | 61 | // Observe the result of a API call. 62 | func (mc *metricContext) Observe(err error) error { 63 | apiMetrics.latency.WithLabelValues(mc.attributes...).Observe( 64 | time.Since(mc.start).Seconds()) 65 | if err != nil { 66 | apiMetrics.errors.WithLabelValues(mc.attributes...).Inc() 67 | } 68 | 69 | return err 70 | } 71 | 72 | func newGenericMetricContext(prefix, request, region, zone, version string) *metricContext { 73 | if len(zone) == 0 { 74 | zone = unusedMetricLabel 75 | } 76 | if len(region) == 0 { 77 | region = unusedMetricLabel 78 | } 79 | return &metricContext{ 80 | start: time.Now(), 81 | attributes: []string{prefix + "_" + request, region, zone, version}, 82 | } 83 | } 84 | 85 | // registerApiMetrics adds metrics definitions for a category of API calls. 86 | func registerAPIMetrics(attributes ...string) *apiCallMetrics { 87 | metrics := &apiCallMetrics{ 88 | latency: metrics.NewHistogramVec( 89 | &metrics.HistogramOpts{ 90 | Name: "cloudprovider_gce_api_request_duration_seconds", 91 | Help: "Latency of a GCE API call", 92 | StabilityLevel: metrics.ALPHA, 93 | }, 94 | attributes, 95 | ), 96 | errors: metrics.NewCounterVec( 97 | &metrics.CounterOpts{ 98 | Name: "cloudprovider_gce_api_request_errors", 99 | Help: "Number of errors for an API call", 100 | StabilityLevel: metrics.ALPHA, 101 | }, 102 | attributes, 103 | ), 104 | } 105 | 106 | legacyregistry.MustRegister(metrics.latency) 107 | legacyregistry.MustRegister(metrics.errors) 108 | 109 | return metrics 110 | } 111 | -------------------------------------------------------------------------------- /vsphere/vclib/fixtures/ca.key: -------------------------------------------------------------------------------- 1 | -----BEGIN RSA PRIVATE KEY----- 2 | MIIJJwIBAAKCAgEA4CKLwCPwMUIVaGhvZxLmXEzDflILVaGCZRRBbfYucfysylT/ 3 | JKPMlKs3ORNVW1cdiW1z/ZUlAlN+eqq40WSVQJqLUeXltsfZwemdFmf3SAWIu9v9 4 | wI5mhLQJMh2XPKNILCBhrET/ANLVPbObJUFvGavpR9XVXTXsLUvuCR+oSpDvQYyn 5 | WKJ5dAwqKaFx3GCEFAm0dNnSzliQrzKFOE0DUMxFQH5Lt2EYLHrya+K4ZtYbX5nK 6 | X++T9R5pZs0npqmTQS/rIffv2hT89tKdqPz/MCt5xwmjsAO2uri5O+WaLUIkf8Bd 7 | fmVAusE/5v2p3x3MH0rUXaNPg7FqLj1cnbcwHqqt3PmVl9VZINkPbnHHiua21GNq 8 | DAZ/G/vP8/hlXwIeE8d6YPsSPm4NEH0Ku+yk0TEL6QkGFMYYpyCw1BNYGXd+zvf1 9 | xjZtGrcViHhesxuv71nGdJbNSi7zwkYXydSKCNnjJ+Oqyip5uUC+DmydqcJTQLcZ 10 | W5ObNfeB8PLz6UuVidMffh8evE13L60cS5wZyZWherMqB+I/uREt05gikCtlJVOo 11 | shuLS0QjbK/INYCSFBJjt0xrwTbw13SQsEhktQYdqTHaDBWi6uh+pcY9msF1jZJ+ 12 | GAEPYcLzK3o2/kE6g09TZ3QDeP9bEDTllL+mIs4JGiWGNC/eGjGfyyAnfmECAwEA 13 | AQKCAf88aRNBtm4G2MjsWzmrjmyIdCg84+AqNF3w4ITCHphmILRx1HbwaTW63GsF 14 | 9zAKbnCHmfipYImZFugAKAOobHPN9dmXOV+w5CzNFyo/38XGo7c26xR50efP3Lad 15 | y1v3/Ap32kJ5LB+PGURgXQh0Ai7vvGYj9n6LoP0HOG/wBZhWgLn78O0p9qDFpoG2 16 | tsz5mQoAXJ1G4W7wLu7QSc2eXyOFo4kG2QOPaZwaYQj2CyWokgzOt6TUNr6qUogW 17 | LTWCtjH6X/AAN9Nt9Do6TIoyAf7F/PHVs8NqrZWSvjcu7bOgfzNXO4H3j1LjAzM2 18 | Dyi5+k4KISEcG+hSln8H94H/AGD3Yea44sDnIZoOtKTB+O7V+jyU7qwtX9QaEu04 19 | CslnZOun0/PR/C9mI7QaGu1YJcxdIw9Nlj07+iAzI4ZjuO+qHeUM7SNvH/MVbglA 20 | 2ZDkp7J3VlJgFObvHdINZMWNO1FIg/pc7TcXNsUkNAwnCwLh6//5/cZF+BtGlc4A 21 | SGkhYKX3dRp8qLjNKxux3VHROoDByJDEUcnn0fEAm9aMbV+PofpghJtQqnKbsMn8 22 | iF29v+9+JBIHFxAwhCIv9atF82VHt/sGPcsRqohttRWJDaUMBM3N8rvciiigcYzh 23 | c/o4kH0YNoFSs4+evhYQDxk8yIGsgyuGfnW5QaLUIPa2AxblAoIBAQDyfoJr3UFq 24 | LfkTkYHjAo4eua1vzlM3/8aFFnuQhMeoFvw4aA26x1DsUUozIRXTWWbnFH6GY8T3 25 | B46jgWcO4UaMqbxQxTpHSDQFSVn/budugxGU70WQ9LcjSobk9uCXgk2MmRn9tA/6 26 | +ergswSEuPxyNzgDF60BTrS5V2Akh6eF/sYZWnMKazZ3kdw1V5Y/IxfNH1yo6GRz 27 | PTPVyyX6kU3+DNQSplgcsKYFhyoT2HPIRaxR1fTIw9E5w1rQWanYz/A0I3SDECsc 28 | qJDy1rzC+0Tye2XLcWzHu5l1ng8GPLQJfjEtMTKXMIHjpLFC1P4hXNrlxTOnALSS 29 | 95bwzvDqfxULAoIBAQDsnkUVOvoXrE9xRI2EyWi1K08i5YSwy3rtV+uJP2Zyy4uB 30 | r3TfzxFnYdXWykzHJGqHd6N5M6vCmbcLMS0G9z5QpDhrIF5vk26P9isvZ3k7rkWG 31 | jgwif3kBcPQXlCDgwwnVmGsBf/A+2z3HOfNPK3Iy3VamFvYD52wgL8+N0puZ42aU 32 | aH759JjLGcaVZWzWNdIcpS1OsBucGXCj3IeHmLjhJFbVebIHJ4rCs7gj51H8R8uk 33 | fksxsgfPdRRpYq7NkDOzVDPb/KtTf5C4ZDogRaxj765DMnn6LhBFQVuDWEDJgjlF 34 | Aolt8ynskf3xd19nlX99QAzXnql6LLClwps6G8XDAoIBADzhslDufevwmuZk091w 35 | 2MmyCG9Xt+EJYIgtetxv2cjD7JMk3L2WKSULy7tGhTpI6eL+bD3FcsAqr48xf/Rm 36 | btYGD3ef7N/Uqurg3a2Z5JUEZzejUy3vosNDhNabfQvM9TdlgPcHbDOw511+1JWV 37 | 9Bug7XkpSpBXeFxIKaVCQbcMniPjZ5qoDEa84jKqSNiVMPaY9ySZJA8iwI7esCxW 38 | quQryFreVKTvXN9qbhAJehhAFeF9/DUjpLYB7Bz/RftfSYltlWUKfCh30dyGOWIi 39 | v865WHdZhNwop4C2LEN+nhz8B9C212LKFPJYeQC0hRFPRM4HUs6NCMkVTFotOqNF 40 | QL0CggEAGXBysPOkS8NEz0K1jF8zGLdNTM0sVO2ri7T2J81fMFxd5VV91Uon7tt/ 41 | 6BXb51Us9t+P/cnmX4ezPErPMn6GfpkJT8stHAXXzzaCMhiH2jjEVNEU0Oivk84X 42 | ECnm1wNhHUvDxWeB5uAfZjn+xLZBEuLlG/o//O92modJY1APVp4yOyZ48FqxyrQ8 43 | u3cqGmWy701674jTjxbVG2jsUVHEHsCPbWgmEcrYilJUK9gE4oC9jjPd1bv0RwOp 44 | bCMl9Afa5x7YbIBf0xxV7N0puqqC/EOakrLslk85hJigRCDK5l9P1PGO4PlRupN/ 45 | n+Rbp4FVMZwfRVdTlUUUwN2JXtf5jQKCAQEAqSMv1mkLS3qnmW1E/qAYrEmMlHZo 46 | 253wuwsO0XS7xCxcEumIvjYCvhnHPYIO2rqsscmk42gYe/OUfteMb71BJ+HnlyOo 47 | 9oDbZg8W2DSUzTUy0yT/JMcNTwVCPeVj+bZ/LzDP5jKmZ7vXZkLGQCgU6ENVmsCg 48 | b8nKz0xc7o8jERaSGY+h3LthXF0wAZJ3NdbnJjFbL8hYpwTrD6xd/yg3M5grrCLe 49 | iBKfdpCIN6VrqI9VymoPZryb1OVEiClt0LHWTIXQPcH2J/CrMeWoGhRBW3yTAECf 50 | HPhYMZddW2y6uOFjRcUCu2HG35ogEYlDd0kjH1HhPC2xXcFQBmOyPpEeDQ== 51 | -----END RSA PRIVATE KEY----- 52 | -------------------------------------------------------------------------------- /vsphere/vclib/fixtures/server.key: -------------------------------------------------------------------------------- 1 | -----BEGIN RSA PRIVATE KEY----- 2 | MIIJKAIBAAKCAgEAlZJORzCjbzF1SaCXFHyitudlE+q3Z5bGhS2TpXG6d6Laoqtw 3 | No4UC3i+TnMndtrP2pNkV/ZYivsp1fHz92FqFAT+XpYcG8pLm4iL0k0UufOWdLPT 4 | X87HCJjKZ4r7fmzstyjqK4sv9I3ye1jKi0VE1BLrF1KVvEE/1PXCug68EBP/aF06 5 | +uvcr6o8hbMYzgdKSzhRYm9C3kGcawNofqAD/Kk/zn+pMk4Bloy4UgtXFXgj2bEn 6 | mVE+tRWyLv2+TONlmLnXaBW3/MvZtKC3mIs2KG+6aBNuY8PdWzWvMtp30r/ibgnH 7 | zuMKtvXJ5XRhTaST4QYXNbGwb1bIV1ylnX8zdXPEQkuYTQDctaYQCe0RXt1I9Fp3 8 | gVQRxyTM+0IetbsU0k9VvBwQ07mgU8Rik3DxVnfbuJY/wREnERTkgv6ojtRwiszr 9 | GIY5x36peRs30CqRMv3uJtqC/FU6nCQbHxwssQyB/umN6L7bcpsQFDydeK95hvRQ 10 | y6tb2v/vMcw7MMo5kSFUHjoL5Zc4DObwiqs+p7F7S0WIJMBzJOcjmgCMzgZ7Jmc7 11 | bMmrm43GLzOaVLIjuPVVpOp7YgJ/lqRf7K3hZXrMdaXkCm01aL8L59d+3Vfdjp3H 12 | HvmYpCh8bc+Kjs/nR9Rc+2JKK/H13LH3W5Cr8Fnc/FP6TgbvvNwsQV01gG8CAwEA 13 | AQKCAgBLBQn8DPo8YDsqxcBhRy45vQ/mkHiTHX3O+JAwkD1tmiI9Ku3qfxKwukwB 14 | fyKRK6jLQdg3gljgxJ80Ltol/xc8mVCYUoQgsDOB/FfdEEpQBkw1lqhzSnxr5G7I 15 | xl3kCHAmYgAp/PL9n2C620sj1YdzM1X06bgupy+D+gxEU/WhvtYBG5nklv6moSUg 16 | DjdnxyJNXh7710Bbx97Tke8Ma+f0B1P4l/FeSN/lCgm9JPD11L9uhbuN28EvBIXN 17 | qfmUCQ5BLx1KmHIi+n/kaCQN/+0XFQsS/oQEyA2znNaWFBu7egDxHji4nQoXwGoW 18 | i2vujJibafmkNc5/2bA8mTx8JXvCLhU2L9j2ZumpKOda0g+pfMauesL+9rvZdqwW 19 | gjdjndOHZlg3qm40hGCDBVmmV3mdnvXrk1BbuB4Y0N7qGo3PyYtJHGwJILaNQVGR 20 | Sj75uTatxJwFXsqSaJaErV3Q90IiyXX4AOFGnWHOs29GEwtnDbCvT/rzqutTYSXD 21 | Yv0XFDznzJelhZTH7FbaW3FW3YGEG1ER/0MtKpsAH4i7H9q3KKK8yrzUsgUkGwXt 22 | xtoLckh91xilPIGbzARdELTEdHrjlFL+qaz3PIqEQScWz3WBu2JcIzGbp6PQfMZ+ 23 | FZXarEb/ADZuX0+WoKFYR5jzwMoQfF/fxe2Ib/37ETNw4BgfSQKCAQEAxOw64XgO 24 | nUVJslzGK/H5fqTVpD1rfRmvVAiSDLAuWpClbpDZXqEPuoPPYsiccuUWu9VkJE1F 25 | 6MZEexGx1jFkN08QUHD1Bobzu6ThaBc2PrWHRjFGKM60d0AkhOiL4N04FGwVeCN6 26 | xzIJFk1E4VOOo1+lzeAWRvi1lwuWTgQi+m25nwBJtmYdBLGeS+DXy80Fi6deECei 27 | ipDzJ4rxJsZ61uqBeYC4CfuHW9m5rCzJWPMMMFrPdl3OxEyZzKng4Co5EYc5i/QH 28 | piXD6IJayKcTPRK3tBJZp2YCIIdtQLcjAwmDEDowQtelHkbTihXMGRarf3VcOEoN 29 | ozMRgcLEEynuKwKCAQEAwnF5ZkkJEL/1MCOZ6PZfSKl35ZMIz/4Umk8hOMAQGhCT 30 | cnxlDUfGSBu4OihdBbIuBSBsYDjgcev8uyiIPDVy0FIkBKRGfgrNCLDh19aHljvE 31 | bUc3akvbft0mro86AvSd/Rpc7sj841bru37RDUm6AJOtIvb6DWUpMOZgMm0WMmSI 32 | kNs/UT+7rqg+AZPP8lumnJIFnRK38xOehQAaS1FHWGP//38py8yo8eXpMsoCWMch 33 | c+kZD2jsAYV+SWjjkZjcrv/52+asd4AotRXIShV8E8xItQeq6vLHKOaIe0tC2Y44 34 | ONAKiu4dgABt1voy8I5J63MwgeNmgAUS+KsgUclYzQKCAQEAlt/3bPAzIkQH5uQ1 35 | 4U2PvnxEQ4XbaQnYzyWR4K7LlQ/l8ASCxoHYLyr2JdVWKKFk/ZzNERMzUNk3dqNk 36 | AZvuEII/GaKx2MJk04vMN5gxM3KZpinyeymEEynN0RbqtOpJITx+ZoGofB3V4IRr 37 | FciTLJEH0+iwqMe9OXDjQ/rfYcfXw/7QezNZYFNF2RT3wWnfqdQduXrkig3sfotx 38 | oCfJzgf2E0WPu/Y/CxyRqVzXF5N/7zxkX2gYF0YpQCmX5afz+X4FlTju81lT9DyL 39 | mdiIYO6KWSkGD7+UOaAJEOA/rwAGrtQmTdAy7jONt+pjaYV4+DrO4UG7mSJzc1vq 40 | JlSl6QKCAQARqwPv8mT7e6XI2QNMMs7XqGZ3mtOrKpguqVAIexM7exQazAjWmxX+ 41 | SV6FElPZh6Y82wRd/e0PDPVrADTY27ZyDXSuY0rwewTEbGYpGZo6YXXoxBbZ9sic 42 | D3ZLWEJaMGYGsJWPMP4hni1PXSebwH5BPSn3Sl/QRcfnZJeLHXRt4cqy9uka9eKU 43 | 7T6tIAQ+LmvGQFJ4QlIqqTa3ORoqi9kiw/tn+OMQXKlhSZXWApsR/A4jHSQkzVDc 44 | loeyHfDHsw8ia6oFfEFhnmiUg8UuTiN3HRHiOS8jqCnGoqP2KBGL+StMpkK++wH9 45 | NozEgvmL+DHpTg8zTjlrGortw4btR5FlAoIBABVni+EsGA5K/PM1gIct2pDm+6Kq 46 | UCYScTwIjftuwKLk/KqermG9QJLiJouKO3ZSz7iCelu87Dx1cKeXrc2LQ1pnQzCB 47 | JnI6BCT+zRnQFXjLokJXD2hIS2hXhqV6/9FRXLKKMYePcDxWt/etLNGmpLnhDfb3 48 | sMOH/9pnaGmtk36Ce03Hh7E1C6io/MKfTq+KKUV1UGwO1BdNQCiclkYzAUqn1O+Y 49 | c8BaeGKc2c6as8DKrPTGGQGmzo/ZUxQVfVFl2g7+HXISWBBcui/G5gtnU1afZqbW 50 | mTmDoqs4510vhlkhN9XZ0DyhewDIqNNGEY2vS1x2fJz1XC2Eve4KpSyUsiE= 51 | -----END RSA PRIVATE KEY----- 52 | -------------------------------------------------------------------------------- /azure/clients/vmsizeclient/azure_vmsizeclient_test.go: -------------------------------------------------------------------------------- 1 | // +build !providerless 2 | 3 | /* 4 | Copyright 2020 The Kubernetes Authors. 5 | 6 | Licensed under the Apache License, Version 2.0 (the "License"); 7 | you may not use this file except in compliance with the License. 8 | You may obtain a copy of the License at 9 | 10 | http://www.apache.org/licenses/LICENSE-2.0 11 | 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | */ 18 | 19 | package vmsizeclient 20 | 21 | import ( 22 | "bytes" 23 | "context" 24 | "io/ioutil" 25 | "net/http" 26 | "testing" 27 | 28 | "github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2019-07-01/compute" 29 | "github.com/Azure/go-autorest/autorest" 30 | "github.com/golang/mock/gomock" 31 | "github.com/stretchr/testify/assert" 32 | 33 | azclients "k8s.io/legacy-cloud-providers/azure/clients" 34 | "k8s.io/legacy-cloud-providers/azure/clients/armclient" 35 | "k8s.io/legacy-cloud-providers/azure/clients/armclient/mockarmclient" 36 | ) 37 | 38 | func TestListNotFound(t *testing.T) { 39 | ctrl := gomock.NewController(t) 40 | defer ctrl.Finish() 41 | 42 | resourceID := "/subscriptions/subscriptionID/providers/Microsoft.Compute/locations/eastus/vmSizes" 43 | response := &http.Response{ 44 | StatusCode: http.StatusNotFound, 45 | Body: ioutil.NopCloser(bytes.NewReader([]byte("{}"))), 46 | } 47 | armClient := mockarmclient.NewMockInterface(ctrl) 48 | armClient.EXPECT().GetResource(gomock.Any(), resourceID, "").Return(response, nil).Times(1) 49 | armClient.EXPECT().CloseResponse(gomock.Any(), gomock.Any()).Times(1) 50 | 51 | vmsizeClient := getTestVMSizeClient(armClient) 52 | expected := compute.VirtualMachineSizeListResult{Response: autorest.Response{}} 53 | result, rerr := vmsizeClient.List(context.TODO(), "eastus") 54 | assert.Equal(t, expected, result) 55 | assert.NotNil(t, rerr) 56 | assert.Equal(t, http.StatusNotFound, rerr.HTTPStatusCode) 57 | } 58 | 59 | func TestListInternalError(t *testing.T) { 60 | ctrl := gomock.NewController(t) 61 | defer ctrl.Finish() 62 | 63 | resourceID := "/subscriptions/subscriptionID/providers/Microsoft.Compute/locations/eastus/vmSizes" 64 | response := &http.Response{ 65 | StatusCode: http.StatusInternalServerError, 66 | Body: ioutil.NopCloser(bytes.NewReader([]byte("{}"))), 67 | } 68 | armClient := mockarmclient.NewMockInterface(ctrl) 69 | armClient.EXPECT().GetResource(gomock.Any(), resourceID, "").Return(response, nil).Times(1) 70 | armClient.EXPECT().CloseResponse(gomock.Any(), gomock.Any()).Times(1) 71 | 72 | vmsizeClient := getTestVMSizeClient(armClient) 73 | expected := compute.VirtualMachineSizeListResult{Response: autorest.Response{}} 74 | result, rerr := vmsizeClient.List(context.TODO(), "eastus") 75 | assert.Equal(t, expected, result) 76 | assert.NotNil(t, rerr) 77 | assert.Equal(t, http.StatusInternalServerError, rerr.HTTPStatusCode) 78 | } 79 | 80 | func getTestVMSizeClient(armClient armclient.Interface) *Client { 81 | rateLimiterReader, rateLimiterWriter := azclients.NewRateLimiter(&azclients.RateLimitConfig{}) 82 | return &Client{ 83 | armClient: armClient, 84 | subscriptionID: "subscriptionID", 85 | rateLimiterReader: rateLimiterReader, 86 | rateLimiterWriter: rateLimiterWriter, 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /aws/aws_instancegroups.go: -------------------------------------------------------------------------------- 1 | // +build !providerless 2 | 3 | /* 4 | Copyright 2014 The Kubernetes Authors. 5 | 6 | Licensed under the Apache License, Version 2.0 (the "License"); 7 | you may not use this file except in compliance with the License. 8 | You may obtain a copy of the License at 9 | 10 | http://www.apache.org/licenses/LICENSE-2.0 11 | 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | */ 18 | 19 | package aws 20 | 21 | import ( 22 | "fmt" 23 | 24 | "github.com/aws/aws-sdk-go/aws" 25 | "github.com/aws/aws-sdk-go/service/autoscaling" 26 | "k8s.io/klog" 27 | ) 28 | 29 | // AWSCloud implements InstanceGroups 30 | var _ InstanceGroups = &Cloud{} 31 | 32 | // ResizeInstanceGroup sets the size of the specificed instancegroup Exported 33 | // so it can be used by the e2e tests, which don't want to instantiate a full 34 | // cloudprovider. 35 | func ResizeInstanceGroup(asg ASG, instanceGroupName string, size int) error { 36 | request := &autoscaling.UpdateAutoScalingGroupInput{ 37 | AutoScalingGroupName: aws.String(instanceGroupName), 38 | MinSize: aws.Int64(int64(size)), 39 | MaxSize: aws.Int64(int64(size)), 40 | } 41 | if _, err := asg.UpdateAutoScalingGroup(request); err != nil { 42 | return fmt.Errorf("error resizing AWS autoscaling group: %q", err) 43 | } 44 | return nil 45 | } 46 | 47 | // ResizeInstanceGroup implements InstanceGroups.ResizeInstanceGroup 48 | // Set the size to the fixed size 49 | func (c *Cloud) ResizeInstanceGroup(instanceGroupName string, size int) error { 50 | return ResizeInstanceGroup(c.asg, instanceGroupName, size) 51 | } 52 | 53 | // DescribeInstanceGroup gets info about the specified instancegroup 54 | // Exported so it can be used by the e2e tests, 55 | // which don't want to instantiate a full cloudprovider. 56 | func DescribeInstanceGroup(asg ASG, instanceGroupName string) (InstanceGroupInfo, error) { 57 | request := &autoscaling.DescribeAutoScalingGroupsInput{ 58 | AutoScalingGroupNames: []*string{aws.String(instanceGroupName)}, 59 | } 60 | response, err := asg.DescribeAutoScalingGroups(request) 61 | if err != nil { 62 | return nil, fmt.Errorf("error listing AWS autoscaling group (%s): %q", instanceGroupName, err) 63 | } 64 | 65 | if len(response.AutoScalingGroups) == 0 { 66 | return nil, nil 67 | } 68 | if len(response.AutoScalingGroups) > 1 { 69 | klog.Warning("AWS returned multiple autoscaling groups with name ", instanceGroupName) 70 | } 71 | group := response.AutoScalingGroups[0] 72 | return &awsInstanceGroup{group: group}, nil 73 | } 74 | 75 | // DescribeInstanceGroup implements InstanceGroups.DescribeInstanceGroup 76 | // Queries the cloud provider for information about the specified instance group 77 | func (c *Cloud) DescribeInstanceGroup(instanceGroupName string) (InstanceGroupInfo, error) { 78 | return DescribeInstanceGroup(c.asg, instanceGroupName) 79 | } 80 | 81 | // awsInstanceGroup implements InstanceGroupInfo 82 | var _ InstanceGroupInfo = &awsInstanceGroup{} 83 | 84 | type awsInstanceGroup struct { 85 | group *autoscaling.Group 86 | } 87 | 88 | // Implement InstanceGroupInfo.CurrentSize 89 | // The number of instances currently running under control of this group 90 | func (g *awsInstanceGroup) CurrentSize() (int, error) { 91 | return len(g.group.Instances), nil 92 | } 93 | -------------------------------------------------------------------------------- /openstack/metadata_test.go: -------------------------------------------------------------------------------- 1 | // +build !providerless 2 | 3 | /* 4 | Copyright 2016 The Kubernetes Authors. 5 | 6 | Licensed under the Apache License, Version 2.0 (the "License"); 7 | you may not use this file except in compliance with the License. 8 | You may obtain a copy of the License at 9 | 10 | http://www.apache.org/licenses/LICENSE-2.0 11 | 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | */ 18 | 19 | package openstack 20 | 21 | import ( 22 | "strings" 23 | "testing" 24 | ) 25 | 26 | var FakeMetadata = Metadata{ 27 | UUID: "83679162-1378-4288-a2d4-70e13ec132aa", 28 | Name: "test", 29 | AvailabilityZone: "nova", 30 | } 31 | 32 | func SetMetadataFixture(value *Metadata) { 33 | metadataCache = value 34 | } 35 | 36 | func ClearMetadata() { 37 | metadataCache = nil 38 | } 39 | 40 | func TestParseMetadata(t *testing.T) { 41 | _, err := parseMetadata(strings.NewReader("bogus")) 42 | if err == nil { 43 | t.Errorf("Should fail when bad data is provided: %s", err) 44 | } 45 | 46 | data := strings.NewReader(` 47 | { 48 | "availability_zone": "nova", 49 | "files": [ 50 | { 51 | "content_path": "/content/0000", 52 | "path": "/etc/network/interfaces" 53 | }, 54 | { 55 | "content_path": "/content/0001", 56 | "path": "known_hosts" 57 | } 58 | ], 59 | "hostname": "test.novalocal", 60 | "launch_index": 0, 61 | "name": "test", 62 | "meta": { 63 | "role": "webservers", 64 | "essential": "false" 65 | }, 66 | "public_keys": { 67 | "mykey": "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQDBqUfVvCSez0/Wfpd8dLLgZXV9GtXQ7hnMN+Z0OWQUyebVEHey1CXuin0uY1cAJMhUq8j98SiW+cU0sU4J3x5l2+xi1bodDm1BtFWVeLIOQINpfV1n8fKjHB+ynPpe1F6tMDvrFGUlJs44t30BrujMXBe8Rq44cCk6wqyjATA3rQ== Generated by Nova\n" 68 | }, 69 | "uuid": "83679162-1378-4288-a2d4-70e13ec132aa", 70 | "devices": [ 71 | { 72 | "bus": "scsi", 73 | "serial": "6df1888b-f373-41cf-b960-3786e60a28ef", 74 | "tags": ["fake_tag"], 75 | "type": "disk", 76 | "address": "0:0:0:0" 77 | } 78 | ] 79 | } 80 | `) 81 | md, err := parseMetadata(data) 82 | if err != nil { 83 | t.Fatalf("Should succeed when provided with valid data: %s", err) 84 | } 85 | 86 | if md.Name != "test" { 87 | t.Errorf("incorrect name: %s", md.Name) 88 | } 89 | 90 | if md.UUID != "83679162-1378-4288-a2d4-70e13ec132aa" { 91 | t.Errorf("incorrect uuid: %s", md.UUID) 92 | } 93 | 94 | if md.AvailabilityZone != "nova" { 95 | t.Errorf("incorrect az: %s", md.AvailabilityZone) 96 | } 97 | 98 | if len(md.Devices) != 1 { 99 | t.Errorf("expecting to find 1 device, found %d", len(md.Devices)) 100 | } 101 | 102 | if md.Devices[0].Bus != "scsi" { 103 | t.Errorf("incorrect disk bus: %s", md.Devices[0].Bus) 104 | } 105 | 106 | if md.Devices[0].Address != "0:0:0:0" { 107 | t.Errorf("incorrect disk address: %s", md.Devices[0].Address) 108 | } 109 | 110 | if md.Devices[0].Type != "disk" { 111 | t.Errorf("incorrect device type: %s", md.Devices[0].Type) 112 | } 113 | 114 | if md.Devices[0].Serial != "6df1888b-f373-41cf-b960-3786e60a28ef" { 115 | t.Errorf("incorrect device serial: %s", md.Devices[0].Serial) 116 | } 117 | } 118 | -------------------------------------------------------------------------------- /vsphere/vclib/virtualmachine_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2016 The Kubernetes 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 vclib 18 | 19 | import ( 20 | "context" 21 | "testing" 22 | 23 | "github.com/vmware/govmomi" 24 | "github.com/vmware/govmomi/simulator" 25 | ) 26 | 27 | func TestVirtualMachine(t *testing.T) { 28 | ctx := context.Background() 29 | 30 | model := simulator.VPX() 31 | 32 | defer model.Remove() 33 | err := model.Create() 34 | if err != nil { 35 | t.Fatal(err) 36 | } 37 | 38 | s := model.Service.NewServer() 39 | defer s.Close() 40 | 41 | c, err := govmomi.NewClient(ctx, s.URL, true) 42 | if err != nil { 43 | t.Fatal(err) 44 | } 45 | 46 | vc := &VSphereConnection{Client: c.Client} 47 | 48 | dc, err := GetDatacenter(ctx, vc, TestDefaultDatacenter) 49 | if err != nil { 50 | t.Error(err) 51 | } 52 | 53 | folders, err := dc.Folders(ctx) 54 | if err != nil { 55 | t.Fatal(err) 56 | } 57 | 58 | folder, err := dc.GetFolderByPath(ctx, folders.VmFolder.InventoryPath) 59 | if err != nil { 60 | t.Fatal(err) 61 | } 62 | 63 | vms, err := folder.GetVirtualMachines(ctx) 64 | if err != nil { 65 | t.Fatal(err) 66 | } 67 | 68 | if len(vms) == 0 { 69 | t.Fatal("no VMs") 70 | } 71 | 72 | for _, vm := range vms { 73 | all, err := vm.GetAllAccessibleDatastores(ctx) 74 | if err != nil { 75 | t.Error(err) 76 | } 77 | if len(all) == 0 { 78 | t.Error("no accessible datastores") 79 | } 80 | 81 | _, err = vm.GetResourcePool(ctx) 82 | if err != nil { 83 | t.Error(err) 84 | } 85 | 86 | diskPath, err := vm.GetVirtualDiskPath(ctx) 87 | if err != nil { 88 | t.Error(err) 89 | } 90 | 91 | options := &VolumeOptions{SCSIControllerType: PVSCSIControllerType} 92 | 93 | for _, expect := range []bool{true, false} { 94 | attached, err := vm.IsDiskAttached(ctx, diskPath) 95 | if err != nil { 96 | t.Error(err) 97 | } 98 | 99 | if attached != expect { 100 | t.Errorf("attached=%t, expected=%t", attached, expect) 101 | } 102 | 103 | uuid, err := vm.AttachDisk(ctx, diskPath, options) 104 | if err != nil { 105 | t.Error(err) 106 | } 107 | if uuid == "" { 108 | t.Error("missing uuid") 109 | } 110 | 111 | err = vm.DetachDisk(ctx, diskPath) 112 | if err != nil { 113 | t.Error(err) 114 | } 115 | } 116 | 117 | for _, expect := range []bool{true, false} { 118 | active, err := vm.IsActive(ctx) 119 | if err != nil { 120 | t.Error(err) 121 | } 122 | 123 | if active != expect { 124 | t.Errorf("active=%t, expected=%t", active, expect) 125 | } 126 | 127 | if expect { 128 | // Expecting to hit the error path since the VM is still powered on 129 | err = vm.DeleteVM(ctx) 130 | if err == nil { 131 | t.Error("expected error") 132 | } 133 | _, _ = vm.PowerOff(ctx) 134 | continue 135 | } 136 | 137 | // Should be able to delete now that VM power is off 138 | err = vm.DeleteVM(ctx) 139 | if err != nil { 140 | t.Error(err) 141 | } 142 | } 143 | } 144 | } 145 | -------------------------------------------------------------------------------- /azure/clients/azure_client_config.go: -------------------------------------------------------------------------------- 1 | // +build !providerless 2 | 3 | /* 4 | Copyright 2019 The Kubernetes Authors. 5 | 6 | Licensed under the Apache License, Version 2.0 (the "License"); 7 | you may not use this file except in compliance with the License. 8 | You may obtain a copy of the License at 9 | 10 | http://www.apache.org/licenses/LICENSE-2.0 11 | 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | */ 18 | 19 | package clients 20 | 21 | import ( 22 | "github.com/Azure/go-autorest/autorest/adal" 23 | "k8s.io/client-go/util/flowcontrol" 24 | "k8s.io/legacy-cloud-providers/azure/retry" 25 | ) 26 | 27 | // ClientConfig contains all essential information to create an Azure client. 28 | type ClientConfig struct { 29 | Location string 30 | SubscriptionID string 31 | ResourceManagerEndpoint string 32 | ServicePrincipalToken *adal.ServicePrincipalToken 33 | RateLimitConfig *RateLimitConfig 34 | Backoff *retry.Backoff 35 | 36 | // Depracated configures (retry.Backoff is preferred). 37 | // Those configurations would be removed after all Azure clients are moved to new implementations. 38 | CloudProviderBackoffRetries int 39 | CloudProviderBackoffDuration int 40 | ShouldOmitCloudProviderBackoff bool 41 | } 42 | 43 | // WithRateLimiter returns a new ClientConfig with rateLimitConfig set. 44 | func (cfg *ClientConfig) WithRateLimiter(rl *RateLimitConfig) *ClientConfig { 45 | newClientConfig := *cfg 46 | newClientConfig.RateLimitConfig = rl 47 | return &newClientConfig 48 | } 49 | 50 | // RateLimitConfig indicates the rate limit config options. 51 | type RateLimitConfig struct { 52 | // Enable rate limiting 53 | CloudProviderRateLimit bool `json:"cloudProviderRateLimit,omitempty" yaml:"cloudProviderRateLimit,omitempty"` 54 | // Rate limit QPS (Read) 55 | CloudProviderRateLimitQPS float32 `json:"cloudProviderRateLimitQPS,omitempty" yaml:"cloudProviderRateLimitQPS,omitempty"` 56 | // Rate limit Bucket Size 57 | CloudProviderRateLimitBucket int `json:"cloudProviderRateLimitBucket,omitempty" yaml:"cloudProviderRateLimitBucket,omitempty"` 58 | // Rate limit QPS (Write) 59 | CloudProviderRateLimitQPSWrite float32 `json:"cloudProviderRateLimitQPSWrite,omitempty" yaml:"cloudProviderRateLimitQPSWrite,omitempty"` 60 | // Rate limit Bucket Size 61 | CloudProviderRateLimitBucketWrite int `json:"cloudProviderRateLimitBucketWrite,omitempty" yaml:"cloudProviderRateLimitBucketWrite,omitempty"` 62 | } 63 | 64 | // RateLimitEnabled returns true if CloudProviderRateLimit is set to true. 65 | func RateLimitEnabled(config *RateLimitConfig) bool { 66 | return config != nil && config.CloudProviderRateLimit 67 | } 68 | 69 | // NewRateLimiter creates new read and write flowcontrol.RateLimiter from RateLimitConfig. 70 | func NewRateLimiter(config *RateLimitConfig) (flowcontrol.RateLimiter, flowcontrol.RateLimiter) { 71 | readLimiter := flowcontrol.NewFakeAlwaysRateLimiter() 72 | writeLimiter := flowcontrol.NewFakeAlwaysRateLimiter() 73 | 74 | if config != nil && config.CloudProviderRateLimit { 75 | readLimiter = flowcontrol.NewTokenBucketRateLimiter( 76 | config.CloudProviderRateLimitQPS, 77 | config.CloudProviderRateLimitBucket) 78 | 79 | writeLimiter = flowcontrol.NewTokenBucketRateLimiter( 80 | config.CloudProviderRateLimitQPSWrite, 81 | config.CloudProviderRateLimitBucketWrite) 82 | } 83 | 84 | return readLimiter, writeLimiter 85 | } 86 | -------------------------------------------------------------------------------- /gce/gce_clusters.go: -------------------------------------------------------------------------------- 1 | // +build !providerless 2 | 3 | /* 4 | Copyright 2017 The Kubernetes Authors. 5 | 6 | Licensed under the Apache License, Version 2.0 (the "License"); 7 | you may not use this file except in compliance with the License. 8 | You may obtain a copy of the License at 9 | 10 | http://www.apache.org/licenses/LICENSE-2.0 11 | 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | */ 18 | 19 | package gce 20 | 21 | import ( 22 | "context" 23 | "fmt" 24 | 25 | "google.golang.org/api/container/v1" 26 | "k8s.io/klog" 27 | ) 28 | 29 | func newClustersMetricContext(request, zone string) *metricContext { 30 | return newGenericMetricContext("clusters", request, unusedMetricLabel, zone, computeV1Version) 31 | } 32 | 33 | // ListClusters will return a list of cluster names for the associated project 34 | func (g *Cloud) ListClusters(ctx context.Context) ([]string, error) { 35 | allClusters := []string{} 36 | 37 | for _, zone := range g.managedZones { 38 | clusters, err := g.listClustersInZone(zone) 39 | if err != nil { 40 | return nil, err 41 | } 42 | // TODO: Scoping? Do we need to qualify the cluster name? 43 | allClusters = append(allClusters, clusters...) 44 | } 45 | 46 | return allClusters, nil 47 | } 48 | 49 | // GetManagedClusters will return the cluster objects associated to this project 50 | func (g *Cloud) GetManagedClusters(ctx context.Context) ([]*container.Cluster, error) { 51 | managedClusters := []*container.Cluster{} 52 | 53 | if g.regional { 54 | var err error 55 | managedClusters, err = g.getClustersInLocation(g.region) 56 | if err != nil { 57 | return nil, err 58 | } 59 | } else if len(g.managedZones) >= 1 { 60 | for _, zone := range g.managedZones { 61 | clusters, err := g.getClustersInLocation(zone) 62 | if err != nil { 63 | return nil, err 64 | } 65 | managedClusters = append(managedClusters, clusters...) 66 | } 67 | } else { 68 | return nil, fmt.Errorf("no zones associated with this cluster(%s)", g.ProjectID()) 69 | } 70 | 71 | return managedClusters, nil 72 | } 73 | 74 | // Master returned the dns address of the master 75 | func (g *Cloud) Master(ctx context.Context, clusterName string) (string, error) { 76 | return "k8s-" + clusterName + "-master.internal", nil 77 | } 78 | 79 | func (g *Cloud) listClustersInZone(zone string) ([]string, error) { 80 | clusters, err := g.getClustersInLocation(zone) 81 | if err != nil { 82 | return nil, err 83 | } 84 | 85 | result := []string{} 86 | for _, cluster := range clusters { 87 | result = append(result, cluster.Name) 88 | } 89 | return result, nil 90 | } 91 | 92 | func (g *Cloud) getClustersInLocation(zoneOrRegion string) ([]*container.Cluster, error) { 93 | // TODO: Issue/68913 migrate metric to list_location instead of list_zone. 94 | mc := newClustersMetricContext("list_zone", zoneOrRegion) 95 | // TODO: use PageToken to list all not just the first 500 96 | location := getLocationName(g.projectID, zoneOrRegion) 97 | list, err := g.containerService.Projects.Locations.Clusters.List(location).Do() 98 | if err != nil { 99 | return nil, mc.Observe(err) 100 | } 101 | if list.Header.Get("nextPageToken") != "" { 102 | klog.Errorf("Failed to get all clusters for request, received next page token %s", list.Header.Get("nextPageToken")) 103 | } 104 | 105 | return list.Clusters, mc.Observe(nil) 106 | } 107 | -------------------------------------------------------------------------------- /azure/clients/diskclient/mockdiskclient/interface.go: -------------------------------------------------------------------------------- 1 | // +build !providerless 2 | 3 | /* 4 | Copyright 2020 The Kubernetes Authors. 5 | 6 | Licensed under the Apache License, Version 2.0 (the "License"); 7 | you may not use this file except in compliance with the License. 8 | You may obtain a copy of the License at 9 | 10 | http://www.apache.org/licenses/LICENSE-2.0 11 | 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | */ 18 | 19 | package mockdiskclient 20 | 21 | import ( 22 | context "context" 23 | reflect "reflect" 24 | 25 | compute "github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2019-07-01/compute" 26 | gomock "github.com/golang/mock/gomock" 27 | retry "k8s.io/legacy-cloud-providers/azure/retry" 28 | ) 29 | 30 | // MockInterface is a mock of Interface interface 31 | type MockInterface struct { 32 | ctrl *gomock.Controller 33 | recorder *MockInterfaceMockRecorder 34 | } 35 | 36 | // MockInterfaceMockRecorder is the mock recorder for MockInterface 37 | type MockInterfaceMockRecorder struct { 38 | mock *MockInterface 39 | } 40 | 41 | // NewMockInterface creates a new mock instance 42 | func NewMockInterface(ctrl *gomock.Controller) *MockInterface { 43 | mock := &MockInterface{ctrl: ctrl} 44 | mock.recorder = &MockInterfaceMockRecorder{mock} 45 | return mock 46 | } 47 | 48 | // EXPECT returns an object that allows the caller to indicate expected use 49 | func (m *MockInterface) EXPECT() *MockInterfaceMockRecorder { 50 | return m.recorder 51 | } 52 | 53 | // Get mocks base method 54 | func (m *MockInterface) Get(ctx context.Context, resourceGroupName, diskName string) (compute.Disk, *retry.Error) { 55 | m.ctrl.T.Helper() 56 | ret := m.ctrl.Call(m, "Get", ctx, resourceGroupName, diskName) 57 | ret0, _ := ret[0].(compute.Disk) 58 | ret1, _ := ret[1].(*retry.Error) 59 | return ret0, ret1 60 | } 61 | 62 | // Get indicates an expected call of Get 63 | func (mr *MockInterfaceMockRecorder) Get(ctx, resourceGroupName, diskName interface{}) *gomock.Call { 64 | mr.mock.ctrl.T.Helper() 65 | return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Get", reflect.TypeOf((*MockInterface)(nil).Get), ctx, resourceGroupName, diskName) 66 | } 67 | 68 | // CreateOrUpdate mocks base method 69 | func (m *MockInterface) CreateOrUpdate(ctx context.Context, resourceGroupName, diskName string, diskParameter compute.Disk) *retry.Error { 70 | m.ctrl.T.Helper() 71 | ret := m.ctrl.Call(m, "CreateOrUpdate", ctx, resourceGroupName, diskName, diskParameter) 72 | ret0, _ := ret[0].(*retry.Error) 73 | return ret0 74 | } 75 | 76 | // CreateOrUpdate indicates an expected call of CreateOrUpdate 77 | func (mr *MockInterfaceMockRecorder) CreateOrUpdate(ctx, resourceGroupName, diskName, diskParameter interface{}) *gomock.Call { 78 | mr.mock.ctrl.T.Helper() 79 | return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CreateOrUpdate", reflect.TypeOf((*MockInterface)(nil).CreateOrUpdate), ctx, resourceGroupName, diskName, diskParameter) 80 | } 81 | 82 | // Delete mocks base method 83 | func (m *MockInterface) Delete(ctx context.Context, resourceGroupName, diskName string) *retry.Error { 84 | m.ctrl.T.Helper() 85 | ret := m.ctrl.Call(m, "Delete", ctx, resourceGroupName, diskName) 86 | ret0, _ := ret[0].(*retry.Error) 87 | return ret0 88 | } 89 | 90 | // Delete indicates an expected call of Delete 91 | func (mr *MockInterfaceMockRecorder) Delete(ctx, resourceGroupName, diskName interface{}) *gomock.Call { 92 | mr.mock.ctrl.T.Helper() 93 | return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Delete", reflect.TypeOf((*MockInterface)(nil).Delete), ctx, resourceGroupName, diskName) 94 | } 95 | -------------------------------------------------------------------------------- /openstack/openstack_routes_test.go: -------------------------------------------------------------------------------- 1 | // +build !providerless 2 | 3 | /* 4 | Copyright 2016 The Kubernetes Authors. 5 | 6 | Licensed under the Apache License, Version 2.0 (the "License"); 7 | you may not use this file except in compliance with the License. 8 | You may obtain a copy of the License at 9 | 10 | http://www.apache.org/licenses/LICENSE-2.0 11 | 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | */ 18 | 19 | package openstack 20 | 21 | import ( 22 | "context" 23 | "net" 24 | "testing" 25 | 26 | "github.com/gophercloud/gophercloud/openstack/compute/v2/servers" 27 | "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/layer3/routers" 28 | "k8s.io/apimachinery/pkg/types" 29 | cloudprovider "k8s.io/cloud-provider" 30 | ) 31 | 32 | func TestRoutes(t *testing.T) { 33 | const clusterName = "ignored" 34 | 35 | cfg, ok := configFromEnv() 36 | if !ok { 37 | t.Skipf("No config found in environment") 38 | } 39 | 40 | os, err := newOpenStack(cfg) 41 | if err != nil { 42 | t.Fatalf("Failed to construct/authenticate OpenStack: %s", err) 43 | } 44 | 45 | vms := getServers(os) 46 | _, err = os.InstanceID() 47 | if err != nil || len(vms) == 0 { 48 | t.Skipf("Please run this test in an OpenStack vm or create at least one VM in OpenStack before you run this test.") 49 | } 50 | 51 | // We know we have at least one vm. 52 | servername := vms[0].Name 53 | 54 | // Pick the first router and server to try a test with 55 | os.routeOpts.RouterID = getRouters(os)[0].ID 56 | 57 | r, ok := os.Routes() 58 | if !ok { 59 | t.Skip("Routes() returned false - perhaps your stack does not support Neutron extraroute extension?") 60 | } 61 | 62 | newroute := cloudprovider.Route{ 63 | DestinationCIDR: "10.164.2.0/24", 64 | TargetNode: types.NodeName(servername), 65 | } 66 | err = r.CreateRoute(context.TODO(), clusterName, "myhint", &newroute) 67 | if err != nil { 68 | t.Fatalf("CreateRoute error: %v", err) 69 | } 70 | 71 | routelist, err := r.ListRoutes(context.TODO(), clusterName) 72 | if err != nil { 73 | t.Fatalf("ListRoutes() error: %v", err) 74 | } 75 | for _, route := range routelist { 76 | _, cidr, err := net.ParseCIDR(route.DestinationCIDR) 77 | if err != nil { 78 | t.Logf("Ignoring route %s, unparsable CIDR: %v", route.Name, err) 79 | continue 80 | } 81 | t.Logf("%s via %s", cidr, route.TargetNode) 82 | } 83 | 84 | err = r.DeleteRoute(context.TODO(), clusterName, &newroute) 85 | if err != nil { 86 | t.Fatalf("DeleteRoute error: %v", err) 87 | } 88 | } 89 | 90 | func getServers(os *OpenStack) []servers.Server { 91 | c, err := os.NewComputeV2() 92 | if err != nil { 93 | panic(err) 94 | } 95 | allPages, err := servers.List(c, servers.ListOpts{}).AllPages() 96 | if err != nil { 97 | panic(err) 98 | } 99 | allServers, err := servers.ExtractServers(allPages) 100 | if err != nil { 101 | panic(err) 102 | } 103 | if len(allServers) == 0 { 104 | panic("No servers to test with") 105 | } 106 | return allServers 107 | } 108 | 109 | func getRouters(os *OpenStack) []routers.Router { 110 | listOpts := routers.ListOpts{} 111 | n, err := os.NewNetworkV2() 112 | if err != nil { 113 | panic(err) 114 | } 115 | allPages, err := routers.List(n, listOpts).AllPages() 116 | if err != nil { 117 | panic(err) 118 | } 119 | allRouters, err := routers.ExtractRouters(allPages) 120 | if err != nil { 121 | panic(err) 122 | } 123 | if len(allRouters) == 0 { 124 | panic("No routers to test with") 125 | } 126 | return allRouters 127 | } 128 | -------------------------------------------------------------------------------- /openstack/openstack_client.go: -------------------------------------------------------------------------------- 1 | // +build !providerless 2 | 3 | /* 4 | Copyright 2017 The Kubernetes Authors. 5 | 6 | Licensed under the Apache License, Version 2.0 (the "License"); 7 | you may not use this file except in compliance with the License. 8 | You may obtain a copy of the License at 9 | 10 | http://www.apache.org/licenses/LICENSE-2.0 11 | 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | */ 18 | 19 | package openstack 20 | 21 | import ( 22 | "fmt" 23 | 24 | "github.com/gophercloud/gophercloud" 25 | "github.com/gophercloud/gophercloud/openstack" 26 | ) 27 | 28 | // NewNetworkV2 creates a ServiceClient that may be used with the neutron v2 API 29 | func (os *OpenStack) NewNetworkV2() (*gophercloud.ServiceClient, error) { 30 | network, err := openstack.NewNetworkV2(os.provider, gophercloud.EndpointOpts{ 31 | Region: os.region, 32 | }) 33 | if err != nil { 34 | return nil, fmt.Errorf("failed to find network v2 endpoint for region %s: %v", os.region, err) 35 | } 36 | return network, nil 37 | } 38 | 39 | // NewComputeV2 creates a ServiceClient that may be used with the nova v2 API 40 | func (os *OpenStack) NewComputeV2() (*gophercloud.ServiceClient, error) { 41 | compute, err := openstack.NewComputeV2(os.provider, gophercloud.EndpointOpts{ 42 | Region: os.region, 43 | }) 44 | if err != nil { 45 | return nil, fmt.Errorf("failed to find compute v2 endpoint for region %s: %v", os.region, err) 46 | } 47 | return compute, nil 48 | } 49 | 50 | // NewBlockStorageV1 creates a ServiceClient that may be used with the Cinder v1 API 51 | func (os *OpenStack) NewBlockStorageV1() (*gophercloud.ServiceClient, error) { 52 | storage, err := openstack.NewBlockStorageV1(os.provider, gophercloud.EndpointOpts{ 53 | Region: os.region, 54 | }) 55 | if err != nil { 56 | return nil, fmt.Errorf("unable to initialize cinder v1 client for region %s: %v", os.region, err) 57 | } 58 | return storage, nil 59 | } 60 | 61 | // NewBlockStorageV2 creates a ServiceClient that may be used with the Cinder v2 API 62 | func (os *OpenStack) NewBlockStorageV2() (*gophercloud.ServiceClient, error) { 63 | storage, err := openstack.NewBlockStorageV2(os.provider, gophercloud.EndpointOpts{ 64 | Region: os.region, 65 | }) 66 | if err != nil { 67 | return nil, fmt.Errorf("unable to initialize cinder v2 client for region %s: %v", os.region, err) 68 | } 69 | return storage, nil 70 | } 71 | 72 | // NewBlockStorageV3 creates a ServiceClient that may be used with the Cinder v3 API 73 | func (os *OpenStack) NewBlockStorageV3() (*gophercloud.ServiceClient, error) { 74 | storage, err := openstack.NewBlockStorageV3(os.provider, gophercloud.EndpointOpts{ 75 | Region: os.region, 76 | }) 77 | if err != nil { 78 | return nil, fmt.Errorf("unable to initialize cinder v3 client for region %s: %v", os.region, err) 79 | } 80 | return storage, nil 81 | } 82 | 83 | // NewLoadBalancerV2 creates a ServiceClient that may be used with the Neutron LBaaS v2 API 84 | func (os *OpenStack) NewLoadBalancerV2() (*gophercloud.ServiceClient, error) { 85 | var lb *gophercloud.ServiceClient 86 | var err error 87 | if os.lbOpts.UseOctavia { 88 | lb, err = openstack.NewLoadBalancerV2(os.provider, gophercloud.EndpointOpts{ 89 | Region: os.region, 90 | }) 91 | } else { 92 | lb, err = openstack.NewNetworkV2(os.provider, gophercloud.EndpointOpts{ 93 | Region: os.region, 94 | }) 95 | } 96 | if err != nil { 97 | return nil, fmt.Errorf("failed to find load-balancer v2 endpoint for region %s: %v", os.region, err) 98 | } 99 | return lb, nil 100 | } 101 | --------------------------------------------------------------------------------