mirror of https://github.com/kubernetes/kops.git
Initial kubetest2 structure for e2e testing
This creates a new go module for the e2e code and the kubetest2 skeleton. Most of the kubetest2 code was copied from sigs.k8s.io/kubetest2/kubetest2-gke. Currently only building (`make gcs-publish-ci`) is in place. I used test-infra/scenarios/kubernetes_e2e.py as reference, removing env and make variables that are no longer needed. Instructions: ``` cd tests/e2e go install sigs.k8s.io/kubetest2 go install ./kubetest2-kops kubetest2 kops -v 9 --build --stage-location=gs://foobar/ --kops-root=../../ # runs make gcs-publish-ci and exits ```
This commit is contained in:
parent
174ba0e323
commit
f0295a3cb7
|
|
@ -0,0 +1,10 @@
|
||||||
|
module k8s.io/kops/tests/e2e
|
||||||
|
|
||||||
|
go 1.15
|
||||||
|
|
||||||
|
require (
|
||||||
|
github.com/octago/sflags v0.2.0
|
||||||
|
github.com/spf13/pflag v1.0.5
|
||||||
|
k8s.io/klog/v2 v2.3.0
|
||||||
|
sigs.k8s.io/kubetest2 v0.0.0-20200930205053-4e57931be178
|
||||||
|
)
|
||||||
File diff suppressed because it is too large
Load Diff
|
|
@ -0,0 +1,42 @@
|
||||||
|
/*
|
||||||
|
Copyright 2020 The Kubernetes Authors.
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package builder
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"sigs.k8s.io/kubetest2/pkg/exec"
|
||||||
|
)
|
||||||
|
|
||||||
|
type BuildOptions struct {
|
||||||
|
KopsRoot string `flag:"-"`
|
||||||
|
StageLocation string `flag:"-"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Build will build the kops artifacts and publish them to the stage location
|
||||||
|
func (b *BuildOptions) Build() error {
|
||||||
|
cmd := exec.Command("make", "gcs-publish-ci")
|
||||||
|
cmd.SetEnv(
|
||||||
|
fmt.Sprintf("HOME=%v", os.Getenv("HOME")),
|
||||||
|
fmt.Sprintf("PATH=%v", os.Getenv("PATH")),
|
||||||
|
fmt.Sprintf("GCS_LOCATION=%v", b.StageLocation),
|
||||||
|
)
|
||||||
|
cmd.SetDir(b.KopsRoot)
|
||||||
|
exec.InheritOutput(cmd)
|
||||||
|
return cmd.Run()
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,53 @@
|
||||||
|
/*
|
||||||
|
Copyright 2020 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 deployer
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"os"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (d *deployer) Build() error {
|
||||||
|
if err := d.init(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err := d.BuildOptions.Build(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *deployer) verifyBuildFlags() error {
|
||||||
|
if d.KopsRoot == "" {
|
||||||
|
return errors.New("required kops-root when building from source")
|
||||||
|
}
|
||||||
|
if !strings.HasPrefix(d.StageLocation, "gs://") {
|
||||||
|
return errors.New("stage-location must be a gs:// path")
|
||||||
|
}
|
||||||
|
fi, err := os.Stat(d.KopsRoot)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if !fi.Mode().IsDir() {
|
||||||
|
return errors.New("kops-root must be a directory")
|
||||||
|
}
|
||||||
|
|
||||||
|
d.BuildOptions.KopsRoot = d.KopsRoot
|
||||||
|
d.BuildOptions.StageLocation = d.StageLocation
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,35 @@
|
||||||
|
/*
|
||||||
|
Copyright 2020 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 deployer
|
||||||
|
|
||||||
|
import "fmt"
|
||||||
|
|
||||||
|
func (d *deployer) init() error {
|
||||||
|
var err error
|
||||||
|
d.doInit.Do(func() { err = d.initialize() })
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// initialize should only be called by init(), behind a sync.Once
|
||||||
|
func (d *deployer) initialize() error {
|
||||||
|
if d.commonOptions.ShouldBuild() {
|
||||||
|
if err := d.verifyBuildFlags(); err != nil {
|
||||||
|
return fmt.Errorf("init failed to check build flags: %s", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,100 @@
|
||||||
|
/*
|
||||||
|
Copyright 2019 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 deployer implements the kubetest2 Kops deployer
|
||||||
|
package deployer
|
||||||
|
|
||||||
|
import (
|
||||||
|
"flag"
|
||||||
|
"sync"
|
||||||
|
|
||||||
|
"github.com/octago/sflags/gen/gpflag"
|
||||||
|
"github.com/spf13/pflag"
|
||||||
|
"k8s.io/klog/v2"
|
||||||
|
"k8s.io/kops/tests/e2e/kubetest2-kops/builder"
|
||||||
|
|
||||||
|
"sigs.k8s.io/kubetest2/pkg/types"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Name is the name of the deployer
|
||||||
|
const Name = "kops"
|
||||||
|
|
||||||
|
type deployer struct {
|
||||||
|
// generic parts
|
||||||
|
commonOptions types.Options
|
||||||
|
// doInit helps to make sure the initialization is performed only once
|
||||||
|
doInit sync.Once
|
||||||
|
|
||||||
|
KopsRoot string `flag:"kops-root" desc:"Path to root of the kops repo. Used with --build."`
|
||||||
|
StageLocation string `flag:"stage-location" desc:"Storage location for kops artifacts. Only gs:// paths are supported."`
|
||||||
|
BuildOptions *builder.BuildOptions
|
||||||
|
}
|
||||||
|
|
||||||
|
// assert that New implements types.NewDeployer
|
||||||
|
var _ types.NewDeployer = New
|
||||||
|
|
||||||
|
// assert that deployer implements types.Deployer
|
||||||
|
var _ types.Deployer = &deployer{}
|
||||||
|
|
||||||
|
func (d *deployer) Provider() string {
|
||||||
|
return Name
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *deployer) Up() error {
|
||||||
|
klog.Warning("Up is not implemented")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *deployer) IsUp() (bool, error) {
|
||||||
|
klog.Warning("IsUp is not implemented")
|
||||||
|
return true, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *deployer) Down() error {
|
||||||
|
klog.Warning("Down is not implemented")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *deployer) DumpClusterLogs() error {
|
||||||
|
klog.Warning("DumpClusterLogs is not implemented")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// New implements deployer.New for kops
|
||||||
|
func New(opts types.Options) (types.Deployer, *pflag.FlagSet) {
|
||||||
|
// create a deployer object and set fields that are not flag controlled
|
||||||
|
d := &deployer{
|
||||||
|
commonOptions: opts,
|
||||||
|
BuildOptions: &builder.BuildOptions{},
|
||||||
|
}
|
||||||
|
|
||||||
|
// register flags
|
||||||
|
fs := bindFlags(d)
|
||||||
|
|
||||||
|
// register flags for klog
|
||||||
|
klog.InitFlags(nil)
|
||||||
|
fs.AddGoFlagSet(flag.CommandLine)
|
||||||
|
return d, fs
|
||||||
|
}
|
||||||
|
|
||||||
|
func bindFlags(d *deployer) *pflag.FlagSet {
|
||||||
|
flags, err := gpflag.Parse(d)
|
||||||
|
if err != nil {
|
||||||
|
klog.Fatalf("unable to generate flags from deployer")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return flags
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,27 @@
|
||||||
|
/*
|
||||||
|
Copyright 2019 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 main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"sigs.k8s.io/kubetest2/pkg/app"
|
||||||
|
|
||||||
|
"k8s.io/kops/tests/e2e/kubetest2-kops/deployer"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
app.Main(deployer.Name, deployer.New)
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue