azure.go 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*
  2. Copyright 2018 The Kubernetes Authors.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package azure
  14. import (
  15. "errors"
  16. "fmt"
  17. "os"
  18. "github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2019-07-01/compute"
  19. v1 "k8s.io/api/core/v1"
  20. "k8s.io/apimachinery/pkg/util/uuid"
  21. "k8s.io/kubernetes/test/e2e/framework"
  22. "k8s.io/legacy-cloud-providers/azure"
  23. )
  24. func init() {
  25. framework.RegisterProvider("azure", newProvider)
  26. }
  27. func newProvider() (framework.ProviderInterface, error) {
  28. if framework.TestContext.CloudConfig.ConfigFile == "" {
  29. return nil, fmt.Errorf("config-file must be specified for Azure")
  30. }
  31. config, err := os.Open(framework.TestContext.CloudConfig.ConfigFile)
  32. if err != nil {
  33. framework.Logf("Couldn't open cloud provider configuration %s: %#v",
  34. framework.TestContext.CloudConfig.ConfigFile, err)
  35. }
  36. defer config.Close()
  37. azureCloud, err := azure.NewCloud(config)
  38. return &Provider{
  39. azureCloud: azureCloud.(*azure.Cloud),
  40. }, err
  41. }
  42. //Provider is a structure to handle Azure clouds for e2e testing
  43. type Provider struct {
  44. framework.NullProvider
  45. azureCloud *azure.Cloud
  46. }
  47. // DeleteNode deletes a node which is specified as the argument
  48. func (p *Provider) DeleteNode(node *v1.Node) error {
  49. return errors.New("not implemented yet")
  50. }
  51. // CreatePD creates a persistent volume
  52. func (p *Provider) CreatePD(zone string) (string, error) {
  53. pdName := fmt.Sprintf("%s-%s", framework.TestContext.Prefix, string(uuid.NewUUID()))
  54. volumeOptions := &azure.ManagedDiskOptions{
  55. DiskName: pdName,
  56. StorageAccountType: compute.StandardLRS,
  57. ResourceGroup: "",
  58. PVCName: pdName,
  59. SizeGB: 1,
  60. Tags: nil,
  61. AvailabilityZone: zone,
  62. DiskIOPSReadWrite: "",
  63. DiskMBpsReadWrite: "",
  64. }
  65. return p.azureCloud.CreateManagedDisk(volumeOptions)
  66. }
  67. // DeletePD deletes a persistent volume
  68. func (p *Provider) DeletePD(pdName string) error {
  69. if err := p.azureCloud.DeleteManagedDisk(pdName); err != nil {
  70. framework.Logf("failed to delete Azure volume %q: %v", pdName, err)
  71. return err
  72. }
  73. return nil
  74. }
  75. // EnableAndDisableInternalLB returns functions for both enabling and disabling internal Load Balancer
  76. func (p *Provider) EnableAndDisableInternalLB() (enable, disable func(svc *v1.Service)) {
  77. enable = func(svc *v1.Service) {
  78. svc.ObjectMeta.Annotations = map[string]string{azure.ServiceAnnotationLoadBalancerInternal: "true"}
  79. }
  80. disable = func(svc *v1.Service) {
  81. svc.ObjectMeta.Annotations = map[string]string{azure.ServiceAnnotationLoadBalancerInternal: "false"}
  82. }
  83. return
  84. }