-
Notifications
You must be signed in to change notification settings - Fork 38.6k
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
E2e tests for federated daemonset #35067
Merged
k8s-github-robot
merged 2 commits into
kubernetes:master
from
mwielgus:daemonset-fed-e2e
Nov 6, 2016
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,192 @@ | ||
/* | ||
Copyright 2016 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 e2e | ||
|
||
import ( | ||
"fmt" | ||
"time" | ||
|
||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
fedclientset "k8s.io/kubernetes/federation/client/clientset_generated/federation_release_1_5" | ||
"k8s.io/kubernetes/federation/pkg/federation-controller/util" | ||
"k8s.io/kubernetes/pkg/api/errors" | ||
"k8s.io/kubernetes/pkg/api/v1" | ||
"k8s.io/kubernetes/pkg/apis/extensions/v1beta1" | ||
kubeclientset "k8s.io/kubernetes/pkg/client/clientset_generated/release_1_5" | ||
"k8s.io/kubernetes/pkg/util/wait" | ||
"k8s.io/kubernetes/test/e2e/framework" | ||
) | ||
|
||
const ( | ||
FederatedDaemonSetName = "federated-daemonset" | ||
FederatedDaemonSetTimeout = 60 * time.Second | ||
FederatedDaemonSetMaxRetries = 3 | ||
) | ||
|
||
// Create/delete daemonset api objects | ||
var _ = framework.KubeDescribe("Federation daemonsets [Feature:Federation12]", func() { | ||
var clusters map[string]*cluster // All clusters, keyed by cluster name | ||
|
||
f := framework.NewDefaultFederatedFramework("federated-daemonset") | ||
|
||
Describe("DaemonSet objects", func() { | ||
|
||
BeforeEach(func() { | ||
framework.SkipUnlessFederated(f.ClientSet) | ||
clusters = map[string]*cluster{} | ||
registerClusters(clusters, UserAgentName, "", f) | ||
}) | ||
|
||
AfterEach(func() { | ||
framework.SkipUnlessFederated(f.ClientSet) | ||
unregisterClusters(clusters, f) | ||
}) | ||
|
||
It("should be created and deleted successfully", func() { | ||
framework.SkipUnlessFederated(f.ClientSet) | ||
nsName := f.FederationNamespace.Name | ||
daemonset := createDaemonSetOrFail(f.FederationClientset_1_5, nsName) | ||
defer func() { // Cleanup | ||
By(fmt.Sprintf("Deleting daemonset %q in namespace %q", daemonset.Name, nsName)) | ||
err := f.FederationClientset_1_5.Extensions().DaemonSets(nsName).Delete(daemonset.Name, &v1.DeleteOptions{}) | ||
framework.ExpectNoError(err, "Error deleting daemonset %q in namespace %q", daemonset.Name, nsName) | ||
}() | ||
// wait for daemonset shards being created | ||
waitForDaemonSetShardsOrFail(nsName, daemonset, clusters) | ||
daemonset = updateDaemonSetOrFail(f.FederationClientset_1_5, nsName) | ||
waitForDaemonSetShardsUpdatedOrFail(nsName, daemonset, clusters) | ||
}) | ||
}) | ||
}) | ||
|
||
func createDaemonSetOrFail(clientset *fedclientset.Clientset, namespace string) *v1beta1.DaemonSet { | ||
if clientset == nil || len(namespace) == 0 { | ||
Fail(fmt.Sprintf("Internal error: invalid parameters passed to createDaemonSetOrFail: clientset: %v, namespace: %v", clientset, namespace)) | ||
} | ||
|
||
daemonset := &v1beta1.DaemonSet{ | ||
ObjectMeta: v1.ObjectMeta{ | ||
Name: FederatedDaemonSetName, | ||
Namespace: namespace, | ||
}, | ||
Spec: v1beta1.DaemonSetSpec{ | ||
Template: v1.PodTemplateSpec{ | ||
ObjectMeta: v1.ObjectMeta{ | ||
Labels: map[string]string{"aaa": "bbb"}, | ||
}, | ||
Spec: v1.PodSpec{ | ||
Containers: []v1.Container{ | ||
{ | ||
Name: "container1", | ||
Image: "gcr.io/google_containers/serve_hostname:v1.4", | ||
Ports: []v1.ContainerPort{{ContainerPort: 9376}}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
By(fmt.Sprintf("Creating daemonset %q in namespace %q", daemonset.Name, namespace)) | ||
_, err := clientset.Extensions().DaemonSets(namespace).Create(daemonset) | ||
framework.ExpectNoError(err, "Failed to create daemonset %s", daemonset.Name) | ||
By(fmt.Sprintf("Successfully created federated daemonset %q in namespace %q", FederatedDaemonSetName, namespace)) | ||
return daemonset | ||
} | ||
|
||
func updateDaemonSetOrFail(clientset *fedclientset.Clientset, namespace string) *v1beta1.DaemonSet { | ||
if clientset == nil || len(namespace) == 0 { | ||
Fail(fmt.Sprintf("Internal error: invalid parameters passed to updateDaemonSetOrFail: clientset: %v, namespace: %v", clientset, namespace)) | ||
} | ||
|
||
var newDaemonSet *v1beta1.DaemonSet | ||
for retryCount := 0; retryCount < FederatedDaemonSetMaxRetries; retryCount++ { | ||
daemonset, err := clientset.Extensions().DaemonSets(namespace).Get(FederatedDaemonSetName) | ||
if err != nil { | ||
framework.Failf("failed to get daemonset %q: %v", FederatedDaemonSetName, err) | ||
} | ||
|
||
// Update one of the data in the daemonset. | ||
daemonset.Annotations = map[string]string{"ccc": "ddd"} | ||
newDaemonSet, err = clientset.Extensions().DaemonSets(namespace).Update(daemonset) | ||
if err == nil { | ||
return newDaemonSet | ||
} | ||
if !errors.IsConflict(err) && !errors.IsServerTimeout(err) { | ||
framework.Failf("failed to update daemonset %q: %v", FederatedDaemonSetName, err) | ||
} | ||
} | ||
framework.Failf("too many retries updating daemonset %q", FederatedDaemonSetName) | ||
return newDaemonSet | ||
} | ||
|
||
func waitForDaemonSetShardsOrFail(namespace string, daemonset *v1beta1.DaemonSet, clusters map[string]*cluster) { | ||
framework.Logf("Waiting for daemonset %q in %d clusters", daemonset.Name, len(clusters)) | ||
for _, c := range clusters { | ||
waitForDaemonSetOrFail(c.Clientset, namespace, daemonset, true, FederatedDaemonSetTimeout) | ||
} | ||
} | ||
|
||
func waitForDaemonSetOrFail(clientset *kubeclientset.Clientset, namespace string, daemonset *v1beta1.DaemonSet, present bool, timeout time.Duration) { | ||
By(fmt.Sprintf("Fetching a federated daemonset shard of daemonset %q in namespace %q from cluster", daemonset.Name, namespace)) | ||
var clusterDaemonSet *v1beta1.DaemonSet | ||
err := wait.PollImmediate(framework.Poll, timeout, func() (bool, error) { | ||
clusterDaemonSet, err := clientset.Extensions().DaemonSets(namespace).Get(daemonset.Name) | ||
if (!present) && errors.IsNotFound(err) { // We want it gone, and it's gone. | ||
By(fmt.Sprintf("Success: shard of federated daemonset %q in namespace %q in cluster is absent", daemonset.Name, namespace)) | ||
return true, nil // Success | ||
} | ||
if present && err == nil { // We want it present, and the Get succeeded, so we're all good. | ||
By(fmt.Sprintf("Success: shard of federated daemonset %q in namespace %q in cluster is present", daemonset.Name, namespace)) | ||
return true, nil // Success | ||
} | ||
By(fmt.Sprintf("DaemonSet %q in namespace %q in cluster. Found: %v, waiting for Found: %v, trying again in %s (err=%v)", daemonset.Name, namespace, clusterDaemonSet != nil && err == nil, present, framework.Poll, err)) | ||
return false, nil | ||
}) | ||
framework.ExpectNoError(err, "Failed to verify daemonset %q in namespace %q in cluster: Present=%v", daemonset.Name, namespace, present) | ||
|
||
if present && clusterDaemonSet != nil { | ||
Expect(util.ObjectMetaAndSpecEquivalent(clusterDaemonSet, daemonset)) | ||
} | ||
} | ||
|
||
func waitForDaemonSetShardsUpdatedOrFail(namespace string, daemonset *v1beta1.DaemonSet, clusters map[string]*cluster) { | ||
framework.Logf("Waiting for daemonset %q in %d clusters", daemonset.Name, len(clusters)) | ||
for _, c := range clusters { | ||
waitForDaemonSetUpdateOrFail(c.Clientset, namespace, daemonset, FederatedDaemonSetTimeout) | ||
} | ||
} | ||
|
||
func waitForDaemonSetUpdateOrFail(clientset *kubeclientset.Clientset, namespace string, daemonset *v1beta1.DaemonSet, timeout time.Duration) { | ||
By(fmt.Sprintf("Fetching a federated daemonset shard of daemonset %q in namespace %q from cluster", daemonset.Name, namespace)) | ||
err := wait.PollImmediate(framework.Poll, timeout, func() (bool, error) { | ||
clusterDaemonSet, err := clientset.Extensions().DaemonSets(namespace).Get(daemonset.Name) | ||
if err == nil { // We want it present, and the Get succeeded, so we're all good. | ||
if util.ObjectMetaAndSpecEquivalent(clusterDaemonSet, daemonset) { | ||
By(fmt.Sprintf("Success: shard of federated daemonset %q in namespace %q in cluster is updated", daemonset.Name, namespace)) | ||
return true, nil | ||
} else { | ||
By(fmt.Sprintf("Expected equal daemonsets. expected: %+v\nactual: %+v", *daemonset, *clusterDaemonSet)) | ||
} | ||
By(fmt.Sprintf("DaemonSet %q in namespace %q in cluster, waiting for daemonset being updated, trying again in %s (err=%v)", daemonset.Name, namespace, framework.Poll, err)) | ||
return false, nil | ||
} | ||
By(fmt.Sprintf("DaemonSet %q in namespace %q in cluster, waiting for being updated, trying again in %s (err=%v)", daemonset.Name, namespace, framework.Poll, err)) | ||
return false, nil | ||
}) | ||
framework.ExpectNoError(err, "Failed to verify daemonset %q in namespace %q in cluster", daemonset.Name, namespace) | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the "12" for here?