Skip to content

Commit

Permalink
Merge pull request #10575 from srikiz/DO-Add-E2E-Tests
Browse files Browse the repository at this point in the history
[DigitalOcean] add e2e tests
  • Loading branch information
k8s-ci-robot authored Jan 14, 2021
2 parents 00a92c1 + 6eda2a4 commit d441149
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 0 deletions.
1 change: 1 addition & 0 deletions tests/e2e/kubetest2-kops/deployer/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ func (d *deployer) verifyKopsFlags() error {
switch d.CloudProvider {
case "aws":
case "gce":
case "digitalocean":
default:
return errors.New("unsupported --cloud-provider value")
}
Expand Down
10 changes: 10 additions & 0 deletions tests/e2e/kubetest2-kops/deployer/up.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (

"k8s.io/klog/v2"
"k8s.io/kops/tests/e2e/kubetest2-kops/aws"
"k8s.io/kops/tests/e2e/kubetest2-kops/do"
"k8s.io/kops/tests/e2e/kubetest2-kops/gce"
"k8s.io/kops/tests/e2e/kubetest2-kops/util"
"sigs.k8s.io/kubetest2/pkg/exec"
Expand Down Expand Up @@ -114,6 +115,15 @@ func (d *deployer) createCluster(zones []string, adminAccess string) error {
args = append(args, "--master-size", "e2-standard-2")
}

if d.CloudProvider == "digitalocean" {
zones, err := do.RandomZones(1)
if err != nil {
return err
}
args = append(args, "--zones", strings.Join(zones, ","))
args = append(args, "--master-size", "s-8vcpu-16gb")
}

klog.Info(strings.Join(args, " "))
cmd := exec.Command(args[0], args[1:]...)
cmd.SetEnv(d.env()...)
Expand Down
53 changes: 53 additions & 0 deletions tests/e2e/kubetest2-kops/do/zones.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
Copyright 2021 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package do

import (
"errors"
"math/rand"
)

var allZones = []string{
"nyc1",
"nyc2",
"nyc3",
"sfo1",
"sfo2",
"tor1",
}

// ErrNoEligibleRegion indicates the requested number of zones is not available in any region
var ErrNoEligibleRegion = errors.New("No eligible DO region found with enough zones")

// ErrMoreThanOneZone indicates the requested number of zones was more than one
var ErrMoreThanOneZone = errors.New("More than 1 zone is chosen. DO only works with 1 zone")

// RandomZones returns a random set of availability zones within a region
func RandomZones(count int) ([]string, error) {

if count > 1 {
return nil, ErrMoreThanOneZone
}

n := rand.Int() % len(allZones)
chosenZone := allZones[n]

chosenZones := make([]string, 0)
chosenZones = append(chosenZones, chosenZone)

return chosenZones, nil
}

0 comments on commit d441149

Please sign in to comment.