Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix golint failures of test/e2e/apps #76132

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion hack/.golint_failures
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,6 @@ staging/src/k8s.io/sample-apiserver/pkg/registry/wardle/flunder
staging/src/k8s.io/sample-controller/pkg/apis/samplecontroller
staging/src/k8s.io/sample-controller/pkg/apis/samplecontroller/v1alpha1
test/e2e
test/e2e/apps
test/e2e/auth
test/e2e/autoscaling
test/e2e/chaosmonkey
Expand Down
197 changes: 98 additions & 99 deletions test/e2e/apps/cronjob.go

Large diffs are not rendered by default.

45 changes: 24 additions & 21 deletions test/e2e/apps/daemon_restart.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ import (
testutils "k8s.io/kubernetes/test/utils"
imageutils "k8s.io/kubernetes/test/utils/image"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/onsi/ginkgo"
"github.com/onsi/gomega"
)

// This test primarily checks 2 things:
Expand All @@ -52,27 +52,30 @@ const (
restartTimeout = 10 * time.Minute
numPods = 10
sshPort = 22
ADD = "ADD"
DEL = "DEL"
UPDATE = "UPDATE"
// ADD represents the ADD event
ADD = "ADD"
// DEL represents the DEL event
DEL = "DEL"
// UPDATE represents the UPDATE event
UPDATE = "UPDATE"
)

// restartDaemonConfig is a config to restart a running daemon on a node, and wait till
// RestartDaemonConfig is a config to restart a running daemon on a node, and wait till
// it comes back up. It uses ssh to send a SIGTERM to the daemon.
type restartDaemonConfig struct {
type RestartDaemonConfig struct {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

private struct with private methods should be fine.
what was the linter error here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your feedback @neolit123
Because public method NewRestartConfig returns an instance of private restartDaemonConfig.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the linter error: @neolit123

daemon_restart.go:71:110: exported func NewRestartConfig returns unexported type *apps.restartDaemonConfig, which can be annoying to use

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for the info.
the change seems OK.

nodeName string
daemonName string
healthzPort int
pollInterval time.Duration
pollTimeout time.Duration
}

// NewRestartConfig creates a restartDaemonConfig for the given node and daemon.
func NewRestartConfig(nodeName, daemonName string, healthzPort int, pollInterval, pollTimeout time.Duration) *restartDaemonConfig {
// NewRestartConfig creates a RestartDaemonConfig for the given node and daemon.
func NewRestartConfig(nodeName, daemonName string, healthzPort int, pollInterval, pollTimeout time.Duration) *RestartDaemonConfig {
if !framework.ProviderIs("gce") {
framework.Logf("WARNING: SSH through the restart config might not work on %s", framework.TestContext.Provider)
}
return &restartDaemonConfig{
return &RestartDaemonConfig{
nodeName: nodeName,
daemonName: daemonName,
healthzPort: healthzPort,
Expand All @@ -81,12 +84,12 @@ func NewRestartConfig(nodeName, daemonName string, healthzPort int, pollInterval
}
}

func (r *restartDaemonConfig) String() string {
func (r *RestartDaemonConfig) String() string {
return fmt.Sprintf("Daemon %v on node %v", r.daemonName, r.nodeName)
}

// waitUp polls healthz of the daemon till it returns "ok" or the polling hits the pollTimeout
func (r *restartDaemonConfig) waitUp() {
func (r *RestartDaemonConfig) waitUp() {
framework.Logf("Checking if %v is up by polling for a 200 on its /healthz endpoint", r)
healthzCheck := fmt.Sprintf(
"curl -s -o /dev/null -I -w \"%%{http_code}\" http://localhost:%v/healthz", r.healthzPort)
Expand All @@ -110,14 +113,14 @@ func (r *restartDaemonConfig) waitUp() {
}

// kill sends a SIGTERM to the daemon
func (r *restartDaemonConfig) kill() {
func (r *RestartDaemonConfig) kill() {
framework.Logf("Killing %v", r)
_, err := framework.NodeExec(r.nodeName, fmt.Sprintf("pgrep %v | xargs -I {} sudo kill {}", r.daemonName))
Expect(err).NotTo(HaveOccurred())
gomega.Expect(err).NotTo(gomega.HaveOccurred())
}

// Restart checks if the daemon is up, kills it, and waits till it comes back up
func (r *restartDaemonConfig) restart() {
func (r *RestartDaemonConfig) restart() {
r.waitUp()
r.kill()
r.waitUp()
Expand Down Expand Up @@ -191,7 +194,7 @@ var _ = SIGDescribe("DaemonRestart [Disruptive]", func() {
var stopCh chan struct{}
var tracker *podTracker

BeforeEach(func() {
ginkgo.BeforeEach(func() {
// These tests require SSH
framework.SkipUnlessProviderIs(framework.ProvidersWithSSH...)
ns = f.Namespace.Name
Expand All @@ -206,7 +209,7 @@ var _ = SIGDescribe("DaemonRestart [Disruptive]", func() {
Replicas: numPods,
CreatedPods: &[]*v1.Pod{},
}
Expect(framework.RunRC(config)).NotTo(HaveOccurred())
gomega.Expect(framework.RunRC(config)).NotTo(gomega.HaveOccurred())
replacePods(*config.CreatedPods, existingPods)

stopCh = make(chan struct{})
Expand Down Expand Up @@ -240,11 +243,11 @@ var _ = SIGDescribe("DaemonRestart [Disruptive]", func() {
go controller.Run(stopCh)
})

AfterEach(func() {
ginkgo.AfterEach(func() {
close(stopCh)
})

It("Controller Manager should not create/delete replicas across restart", func() {
ginkgo.It("Controller Manager should not create/delete replicas across restart", func() {

// Requires master ssh access.
framework.SkipUnlessProviderIs("gce", "aws")
Expand Down Expand Up @@ -275,7 +278,7 @@ var _ = SIGDescribe("DaemonRestart [Disruptive]", func() {
}
})

It("Scheduler should continue assigning pods to nodes across restart", func() {
ginkgo.It("Scheduler should continue assigning pods to nodes across restart", func() {

// Requires master ssh access.
framework.SkipUnlessProviderIs("gce", "aws")
Expand All @@ -293,7 +296,7 @@ var _ = SIGDescribe("DaemonRestart [Disruptive]", func() {
framework.ExpectNoError(framework.ScaleRC(f.ClientSet, f.ScalesGetter, ns, rcName, numPods+5, true))
})

It("Kubelet should not restart containers across restart", func() {
ginkgo.It("Kubelet should not restart containers across restart", func() {

nodeIPs, err := framework.GetNodePublicIps(f.ClientSet)
framework.ExpectNoError(err)
Expand Down