fix: fix codeformat

Signed-off-by: KevinBetterQ <1093850932@qq.com>
This commit is contained in:
KevinBetterQ 2019-07-17 17:52:28 +08:00
parent 25bedbb6a4
commit 40d92db3d2
14 changed files with 109 additions and 72 deletions

View File

@ -37,10 +37,12 @@ var (
lists map[string][]string = map[string][]string{}
)
// Input contains the input text
type Input struct {
InputText string `json:"input_text"`
}
// GetList gets list by key
func GetList(key string) ([]string, error) {
// Using Redis
if slavePool != nil {
@ -62,6 +64,7 @@ func GetList(key string) ([]string, error) {
return lists[key], nil
}
// AppendToList put item into list
func AppendToList(item string, key string) ([]string, error) {
var err error
var items []string
@ -82,6 +85,7 @@ func AppendToList(item string, key string) ([]string, error) {
return items, nil
}
// ListRangeHandler handles lrange request
func ListRangeHandler(rw http.ResponseWriter, req *http.Request) {
var data []byte
@ -97,6 +101,7 @@ func ListRangeHandler(rw http.ResponseWriter, req *http.Request) {
rw.Write(data)
}
// ListPushHandler handles rpush request
func ListPushHandler(rw http.ResponseWriter, req *http.Request) {
var data []byte

View File

@ -164,11 +164,11 @@ func (spc *realStatefulPodControl) UpdateStatefulPodCondition(set *appsv1alpha1.
updateErr := retry.RetryOnConflict(retry.DefaultRetry, func() error {
updatePodCondition(pod, condition)
if _, err := spc.client.CoreV1().Pods(pod.Namespace).UpdateStatus(pod); err != nil {
if updated, gotErr := spc.podLister.Pods(pod.Namespace).Get(pod.Name); gotErr != nil {
updated, gotErr := spc.podLister.Pods(pod.Namespace).Get(pod.Name)
if gotErr != nil {
return gotErr
} else {
pod = updated.DeepCopy()
}
pod = updated.DeepCopy()
return err
}
return nil

View File

@ -31,7 +31,7 @@ import (
"k8s.io/kubernetes/pkg/controller/history"
)
// StatefulSetControl implements the control logic for updating StatefulSets and their children Pods. It is implemented
// StatefulSetControlInterface implements the control logic for updating StatefulSets and their children Pods. It is implemented
// as an interface to allow for extensions that provide different semantics. Currently, there is only one implementation.
type StatefulSetControlInterface interface {
// UpdateStatefulSet implements the control logic for Pod creation, update, and deletion, and

View File

@ -39,9 +39,9 @@ import (
// maxUpdateRetries is the maximum number of retries used for update conflict resolution prior to failure
const maxUpdateRetries = 10
// updateConflictError is the error used to indicate that the maximum number of retries against the API server have
// errUpdateConflict is the error used to indicate that the maximum number of retries against the API server have
// been attempted and we need to back off
var updateConflictError = fmt.Errorf("aborting update after %d attempts", maxUpdateRetries)
var errUpdateConflict = fmt.Errorf("aborting update after %d attempts", maxUpdateRetries)
var patchCodec = scheme.Codecs.LegacyCodec(appsv1alpha1.SchemeGroupVersion)
// overlappingStatefulSets sorts a list of StatefulSets by creation timestamp, using their names as a tie breaker.

View File

@ -19,6 +19,7 @@ package apps
import "github.com/onsi/ginkgo"
// SIGDescribe describes SIG information
func SIGDescribe(text string, body func()) bool {
return ginkgo.Describe("[sig-apps] "+text, body)
}

View File

@ -22,5 +22,6 @@ import (
)
var (
// NewNginxImage gets a Niginx image
NewNginxImage = imageutils.GetE2EImage(imageutils.NginxNew)
)

View File

@ -19,6 +19,7 @@ package framework
import "sync"
// CleanupActionHandle defines a type for cleanup action handle
type CleanupActionHandle *int
var cleanupActionsLock sync.Mutex

View File

@ -43,7 +43,7 @@ import (
const (
maxKubectlExecRetries = 5
// TODO(mikedanese): reset this to 5 minutes once #47135 is resolved.
// ref https://github.com/kubernetes/kubernetes/issues/47135
// DefaultNamespaceDeletionTimeout ref https://github.com/kubernetes/kubernetes/issues/47135
DefaultNamespaceDeletionTimeout = 10 * time.Minute
)
@ -83,19 +83,21 @@ type Framework struct {
TestSummaries []TestDataSummary
}
// TestDataSummary defines a interface to test data summary
type TestDataSummary interface {
SummaryKind() string
PrintHumanReadable() string
PrintJSON() string
}
// FrameworkOptions contains some options
type FrameworkOptions struct {
ClientQPS float32
ClientBurst int
GroupVersion *schema.GroupVersion
}
// NewFramework makes a new framework and sets up a BeforeEach/AfterEach for
// NewDefaultFramework makes a new framework and sets up a BeforeEach/AfterEach for
// you (you can write additional before/after each functions).
func NewDefaultFramework(baseName string) *Framework {
options := FrameworkOptions{
@ -105,6 +107,7 @@ func NewDefaultFramework(baseName string) *Framework {
return NewFramework(baseName, options, nil)
}
// NewFramework makes a new framework and sets up a BeforeEach/AfterEach
func NewFramework(baseName string, options FrameworkOptions, client clientset.Interface) *Framework {
f := &Framework{
BaseName: baseName,
@ -266,6 +269,7 @@ func (f *Framework) AfterEach() {
}
}
// CreateNamespace is used to create namespace
func (f *Framework) CreateNamespace(baseName string, labels map[string]string) (*v1.Namespace, error) {
createTestingNS := TestContext.CreateTestingNS
if createTestingNS == nil {
@ -296,12 +300,12 @@ func (f *Framework) WaitForPodRunning(podName string) error {
return WaitForPodNameRunningInNamespace(f.ClientSet, podName, f.Namespace.Name)
}
// Wrapper function for ginkgo describe. Adds namespacing.
// KruiseDescribe is a wrapper function for ginkgo describe. Adds namespacing.
func KruiseDescribe(text string, body func()) bool {
return Describe("[kruise.io] "+text, body)
}
// Wrapper function for ginkgo It. Adds "[Conformance]" tag and makes static analysis easier.
// ConformanceIt is a wrapper function for ginkgo It. Adds "[Conformance]" tag and makes static analysis easier.
func ConformanceIt(text string, body interface{}, timeout ...float64) bool {
return It(text+" [Conformance]", body, timeout...)
}

View File

@ -28,7 +28,7 @@ import (
v1core "k8s.io/client-go/kubernetes/typed/core/v1"
)
// Convenience method for getting a pod client interface in the framework's namespace,
// PodClient is convenience method for getting a pod client interface in the framework's namespace,
// possibly applying test-suite specific transformations to the pod spec, e.g. for
// node e2e pod scheduling.
func (f *Framework) PodClient() *PodClient {
@ -38,6 +38,7 @@ func (f *Framework) PodClient() *PodClient {
}
}
// PodClient defines a convenience method for getting a pod client interface in the framework's namespace
type PodClient struct {
f *Framework
v1core.PodInterface

View File

@ -33,7 +33,7 @@ func createPV(c clientset.Interface, pv *v1.PersistentVolume) (*v1.PersistentVol
return pv, nil
}
// create the PV resource. Fails test on error.
// CreatePV creates the PV resource. Fails test on error.
func CreatePV(c clientset.Interface, pv *v1.PersistentVolume) (*v1.PersistentVolume, error) {
return createPV(c, pv)
}

View File

@ -22,6 +22,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
// CreateServiceSpec creates service spec
func CreateServiceSpec(serviceName, externalName string, isHeadless bool, selector map[string]string) *v1.Service {
headlessService := &v1.Service{
ObjectMeta: metav1.ObjectMeta{

View File

@ -48,11 +48,11 @@ import (
)
const (
// Poll interval for StatefulSet tests
// StatefulSetPoll indicates poll interval for StatefulSet tests
StatefulSetPoll = 10 * time.Second
// Timeout interval for StatefulSet operations
// StatefulSetTimeout indicates timeout interval for StatefulSet operations
StatefulSetTimeout = 10 * time.Minute
// Timeout for stateful pods to change state
// StatefulPodTimeout indicates timeout for stateful pods to change state
StatefulPodTimeout = 5 * time.Minute
)
@ -474,16 +474,15 @@ func (s *StatefulSetTester) WaitForPartitionedRollingUpdate(set *appsv1alpha1.St
}
}
return false, nil
} else {
for i := int(*set.Spec.Replicas) - 1; i >= partition; i-- {
if pods.Items[i].Labels[apps.StatefulSetRevisionLabel] != set.Status.UpdateRevision {
Logf("Waiting for Pod %s/%s to have revision %s update revision %s",
pods.Items[i].Namespace,
pods.Items[i].Name,
set.Status.UpdateRevision,
pods.Items[i].Labels[apps.StatefulSetRevisionLabel])
return false, nil
}
}
for i := int(*set.Spec.Replicas) - 1; i >= partition; i-- {
if pods.Items[i].Labels[apps.StatefulSetRevisionLabel] != set.Status.UpdateRevision {
Logf("Waiting for Pod %s/%s to have revision %s update revision %s",
pods.Items[i].Namespace,
pods.Items[i].Name,
set.Status.UpdateRevision,
pods.Items[i].Labels[apps.StatefulSetRevisionLabel])
return false, nil
}
}
return true, nil
@ -491,7 +490,7 @@ func (s *StatefulSetTester) WaitForPartitionedRollingUpdate(set *appsv1alpha1.St
return set, pods
}
// WaitForRunningAndReady waits for numStatefulPods in ss to be Running and not Ready.
// WaitForRunningAndNotReady waits for numStatefulPods in ss to be Running and not Ready.
func (s *StatefulSetTester) WaitForRunningAndNotReady(numStatefulPods int32, ss *appsv1alpha1.StatefulSet) {
s.WaitForRunning(numStatefulPods, 0, ss)
}
@ -661,7 +660,7 @@ func (s *StatefulSetTester) WaitForStatusReplicas(ss *appsv1alpha1.StatefulSet,
}
// CheckServiceName asserts that the ServiceName for ss is equivalent to expectedServiceName.
func (p *StatefulSetTester) CheckServiceName(ss *appsv1alpha1.StatefulSet, expectedServiceName string) error {
func (s *StatefulSetTester) CheckServiceName(ss *appsv1alpha1.StatefulSet, expectedServiceName string) error {
Logf("Checking if statefulset spec.serviceName is %s", expectedServiceName)
if expectedServiceName != ss.Spec.ServiceName {
@ -876,6 +875,7 @@ func (sp statefulPodsByOrdinal) Less(i, j int) bool {
type updateStatefulSetFunc func(*appsv1alpha1.StatefulSet)
// UpdateStatefulSetWithRetries update StatefulSet with retries
func UpdateStatefulSetWithRetries(kc kruiseclientset.Interface, namespace, name string, applyUpdate updateStatefulSetFunc) (statefulSet *appsv1alpha1.StatefulSet, err error) {
statefulSets := kc.AppsV1alpha1().StatefulSets(namespace)
var updateErr error

View File

@ -169,6 +169,7 @@ type NodeTestContextType struct {
ExtraEnvs map[string]string
}
// CloudConfig defines some config
type CloudConfig struct {
ApiEndpoint string
ProjectID string
@ -190,9 +191,10 @@ type CloudConfig struct {
Provider ProviderInterface
}
// TestContext defines a context include test settings and global state
var TestContext TestContextType
// Register flags common to all e2e test suites.
// RegisterCommonFlags registers flags common to all e2e test suites.
func RegisterCommonFlags() {
// Turn on verbose by default to get spec names
config.DefaultReporterConfig.Verbose = true
@ -230,7 +232,7 @@ func RegisterCommonFlags() {
flag.StringVar(&TestContext.KubernetesAnywherePath, "kubernetes-anywhere-path", "/workspace/k8s.io/kubernetes-anywhere", "Which directory kubernetes-anywhere is installed to.")
}
// Register flags specific to the cluster e2e test suite.
// RegisterClusterFlags registers flags specific to the cluster e2e test suite.
func RegisterClusterFlags() {
flag.BoolVar(&TestContext.VerifyServiceAccount, "e2e-verify-service-account", true, "If true tests will verify the service account before running.")
flag.StringVar(&TestContext.KubeConfig, clientcmd.RecommendedConfigPathFlag, os.Getenv(clientcmd.RecommendedConfigPathEnvVar), "Path to kubeconfig containing embedded authinfo.")
@ -281,7 +283,7 @@ func RegisterClusterFlags() {
flag.BoolVar(&TestContext.CleanStart, "clean-start", false, "If true, purge all namespaces except default and system before running tests. This serves to Cleanup test namespaces from failed/interrupted e2e runs in a long-lived cluster.")
}
// Register flags specific to the node e2e test suite.
// RegisterNodeFlags registers flags specific to the node e2e test suite.
func RegisterNodeFlags() {
// Mark the test as node e2e when node flags are api.Registry.
TestContext.NodeE2E = true

View File

@ -58,23 +58,24 @@ import (
)
const (
// How long to wait for the pod to be listable
// PodListTimeout indicates how long to wait for the pod to be listable
PodListTimeout = time.Minute
// Initial pod start can be delayed O(minutes) by slow docker pulls
// PodStartTimeout indicates that initial pod start can be delayed O(minutes) by slow docker pulls
// TODO: Make this 30 seconds once #4566 is resolved.
PodStartTimeout = 5 * time.Minute
// Same as `PodStartTimeout` to wait for the pod to be started, but shorter.
// PodStartShortTimeout is same as `PodStartTimeout` to wait for the pod to be started, but shorter.
// Use it case by case when we are sure pod start will not be delayed
// minutes by slow docker pulls or something else.
PodStartShortTimeout = 2 * time.Minute
// How long to wait for a pod to be deleted
// PodDeleteTimeout indicates how long to wait for a pod to be deleted
PodDeleteTimeout = 5 * time.Minute
// PodEventTimeout is how much we wait for a pod event to occur.
PodEventTimeout = 2 * time.Minute
// NamespaceCleanupTimeout indicates:
// If there are any orphaned namespaces to clean up, this test is running
// on a long lived cluster. A long wait here is preferably to spurious test
// failures caused by leaked resources from a previous test run.
@ -83,29 +84,30 @@ const (
// Some pods can take much longer to get ready due to volume attach/detach latency.
slowPodStartTimeout = 15 * time.Minute
// How long to wait for a service endpoint to be resolvable.
// ServiceStartTimeout indicates how long to wait for a service endpoint to be resolvable.
ServiceStartTimeout = 3 * time.Minute
// How often to Poll pods, nodes and claims.
// Poll indicates how often to Poll pods, nodes and claims.
Poll = 2 * time.Second
pollShortTimeout = 1 * time.Minute
pollLongTimeout = 5 * time.Minute
// ServiceAccountProvisionTimeout indicates a service account provision timeout.
// service accounts are provisioned after namespace creation
// a service account is required to support pod creation in a namespace as part of admission control
ServiceAccountProvisionTimeout = 2 * time.Minute
// How long to try single API calls (like 'get' or 'list'). Used to prevent
// SingleCallTimeout indicates how long to try single API calls (like 'get' or 'list'). Used to prevent
// transient failures from failing tests.
// TODO: client should not apply this timeout to Watch calls. Increased from 30s until that is fixed.
SingleCallTimeout = 5 * time.Minute
// How long nodes have to be "ready" when a test begins. They should already
// NodeReadyInitialTimeout indicates how long nodes have to be "ready" when a test begins. They should already
// be "ready" before the test starts, so this is small.
NodeReadyInitialTimeout = 20 * time.Second
// How long pods have to be "ready" when a test begins.
// PodReadyBeforeTimeout indicates how long pods have to be "ready" when a test begins.
PodReadyBeforeTimeout = 5 * time.Minute
// How long pods have to become scheduled onto nodes
@ -115,33 +117,33 @@ const (
ServiceRespondingTimeout = 2 * time.Minute
EndpointRegisterTimeout = time.Minute
// How long claims have to become dynamically provisioned
// ClaimProvisionTimeout indicates how long claims have to become dynamically provisioned
ClaimProvisionTimeout = 5 * time.Minute
// Same as `ClaimProvisionTimeout` to wait for claim to be dynamically provisioned, but shorter.
// ClaimProvisionShortTimeout is same as `ClaimProvisionTimeout` to wait for claim to be dynamically provisioned, but shorter.
// Use it case by case when we are sure this timeout is enough.
ClaimProvisionShortTimeout = 1 * time.Minute
// How long claims have to become bound
// ClaimBindingTimeout indicates how long claims have to become bound
ClaimBindingTimeout = 3 * time.Minute
// How long claims have to become deleted
// ClaimDeletingTimeout indicates how long claims have to become deleted
ClaimDeletingTimeout = 3 * time.Minute
// How long PVs have to beome reclaimed
// PVReclaimingTimeout indicates how long PVs have to beome reclaimed
PVReclaimingTimeout = 3 * time.Minute
// How long PVs have to become bound
// PVBindingTimeout indicates how long PVs have to become bound
PVBindingTimeout = 3 * time.Minute
// How long PVs have to become deleted
// PVDeletingTimeout indicates how long PVs have to become deleted
PVDeletingTimeout = 3 * time.Minute
// How long a node is allowed to become "Ready" after it is restarted before
// RestartNodeReadyAgainTimeout indicates how long a node is allowed to become "Ready" after it is restarted before
// the test is considered failed.
RestartNodeReadyAgainTimeout = 5 * time.Minute
// How long a pod is allowed to become "running" and "ready" after a node
// RestartPodReadyAgainTimeout indicates how long a pod is allowed to become "running" and "ready" after a node
// restart before test is considered failed.
RestartPodReadyAgainTimeout = 5 * time.Minute
@ -165,15 +167,17 @@ var (
Key: schedulerapi.TaintNodeUnreachable,
Effect: v1.TaintEffectNoExecute,
}
// NotReadyTaintTemplate is the taint for when a node doesn't ready.
NotReadyTaintTemplate = &v1.Taint{
Key: schedulerapi.TaintNodeNotReady,
Effect: v1.TaintEffectNoExecute,
}
)
// unique identifier of the e2e run
// RunId is a unique identifier of the e2e run
var RunId = uuid.NewUUID()
// CreateTestingNSFn defines a function to create test
type CreateTestingNSFn func(baseName string, c clientset.Interface, labels map[string]string) (*v1.Namespace, error)
// CreateTestingNS should be used by every test, note that we append a common prefix to the provided test name.
@ -464,6 +468,7 @@ func isDynamicDiscoveryError(err error) bool {
return true
}
// DumpAllNamespaceInfo is used to dump all namespace info
func DumpAllNamespaceInfo(c clientset.Interface, namespace string) {
DumpEventsInNamespace(func(opts metav1.ListOptions, ns string) (*v1.EventList, error) {
return c.CoreV1().Events(ns).List(opts)
@ -508,8 +513,10 @@ func dumpAllNodeInfo(c clientset.Interface) {
//DumpNodeDebugInfo(c, names, Logf)
}
// EventsLister defines a event listener
type EventsLister func(opts metav1.ListOptions, ns string) (*v1.EventList, error)
// DumpEventsInNamespace dump events in namespace
func DumpEventsInNamespace(eventsLister EventsLister, namespace string) {
By(fmt.Sprintf("Collecting events from namespace %q.", namespace))
events, err := eventsLister(metav1.ListOptions{}, namespace)
@ -542,7 +549,7 @@ func (o byFirstTimestamp) Less(i, j int) bool {
return o[i].FirstTimestamp.Before(&o[j].FirstTimestamp)
}
// Checks whether all registered nodes are ready.
// AllNodesReady checks whether all registered nodes are ready.
// TODO: we should change the AllNodesReady call in AfterEach to WaitForAllNodesHealthy,
// and figure out how to do it in a configurable way, as we can't expect all setups to run
// default test add-ons.
@ -588,6 +595,7 @@ func AllNodesReady(c clientset.Interface, timeout time.Duration) error {
return nil
}
// RestclientConfig loads config
func RestclientConfig(kubeContext string) (*clientcmdapi.Config, error) {
Logf(">>> kubeConfig: %s", TestContext.KubeConfig)
if TestContext.KubeConfig == "" {
@ -604,8 +612,10 @@ func RestclientConfig(kubeContext string) (*clientcmdapi.Config, error) {
return c, nil
}
// ClientConfigGetter gets client config
type ClientConfigGetter func() (*restclient.Config, error)
// LoadConfig loads config
func LoadConfig() (*restclient.Config, error) {
c, err := RestclientConfig(TestContext.KubeContext)
if err != nil {
@ -619,6 +629,7 @@ func LoadConfig() (*restclient.Config, error) {
return clientcmd.NewDefaultClientConfig(*c, &clientcmd.ConfigOverrides{ClusterInfo: clientcmdapi.Cluster{Server: TestContext.Host}}).ClientConfig()
}
// LoadClientset loads config of client set
func LoadClientset() (*clientset.Clientset, error) {
config, err := LoadConfig()
if err != nil {
@ -635,10 +646,12 @@ func log(level string, format string, args ...interface{}) {
fmt.Fprintf(GinkgoWriter, nowStamp()+": "+level+": "+format+"\n", args...)
}
// Logf print info log
func Logf(format string, args ...interface{}) {
log("INFO", format, args...)
}
// Failf print fail log
func Failf(format string, args ...interface{}) {
FailfWithOffset(1, format, args...)
}
@ -651,12 +664,14 @@ func FailfWithOffset(offset int, format string, args ...interface{}) {
ginkgowrapper.Fail(nowStamp()+": "+msg, 1+offset)
}
// Skip log info with skip
func Skipf(format string, args ...interface{}) {
msg := fmt.Sprintf(format, args...)
log("INFO", msg)
ginkgowrapper.Skip(nowStamp() + ": " + msg)
}
// ExpectNoError checks if "err" is set
func ExpectNoError(err error, explain ...interface{}) {
ExpectNoErrorWithOffset(1, err, explain...)
}
@ -670,6 +685,7 @@ func ExpectNoErrorWithOffset(offset int, err error, explain ...interface{}) {
ExpectWithOffset(1+offset, err).NotTo(HaveOccurred(), explain...)
}
// ExpectNoErrorWithRetries checks if "err" is set with retries
func ExpectNoErrorWithRetries(fn func() error, maxRetries int, explain ...interface{}) {
var err error
for i := 0; i < maxRetries; i++ {
@ -742,6 +758,7 @@ func RunHostCmdWithRetries(ns, name, cmd string, interval, timeout time.Duration
}
}
// DumpDebugInfo dumps debug info
func DumpDebugInfo(c clientset.Interface, ns string) {
sl, _ := c.CoreV1().Pods(ns).List(metav1.ListOptions{LabelSelector: labels.Everything().String()})
for _, s := range sl.Items {
@ -753,7 +770,7 @@ func DumpDebugInfo(c clientset.Interface, ns string) {
}
}
// Waits default amount of time (PodStartTimeout) for the specified pod to become running.
// WaitForPodRunningInNamespace waits default amount of time (PodStartTimeout) for the specified pod to become running.
// Returns an error if timeout occurs first, or pod goes in to failed state.
func WaitForPodRunningInNamespace(c clientset.Interface, pod *v1.Pod) error {
if pod.Status.Phase == v1.PodRunning {
@ -762,7 +779,7 @@ func WaitForPodRunningInNamespace(c clientset.Interface, pod *v1.Pod) error {
return WaitTimeoutForPodRunningInNamespace(c, pod.Name, pod.Namespace, PodStartTimeout)
}
// Waits default amount of time (PodStartTimeout) for the specified pod to become running.
// WaitForPodNameRunningInNamespace waits default amount of time (PodStartTimeout) for the specified pod to become running.
// Returns an error if timeout occurs first, or pod goes in to failed state.
func WaitForPodNameRunningInNamespace(c clientset.Interface, podName, namespace string) error {
return WaitTimeoutForPodRunningInNamespace(c, podName, namespace, PodStartTimeout)
@ -775,6 +792,7 @@ func waitForPodRunningInNamespaceSlow(c clientset.Interface, podName, namespace
return WaitTimeoutForPodRunningInNamespace(c, podName, namespace, slowPodStartTimeout)
}
// WaitTimeoutForPodRunningInNamespace waits default amount of time
func WaitTimeoutForPodRunningInNamespace(c clientset.Interface, podName, namespace string, timeout time.Duration) error {
return wait.PollImmediate(Poll, timeout, podRunning(c, podName, namespace))
}
@ -812,6 +830,7 @@ type kubectlBuilder struct {
timeout <-chan time.Time
}
// NewKubectlCommand return a kubectlBuilder
func NewKubectlCommand(args ...string) *kubectlBuilder {
b := new(kubectlBuilder)
b.cmd = KubectlCmd(args...)
@ -936,7 +955,7 @@ func KubectlCmd(args ...string) *exec.Cmd {
return cmd
}
// Filters nodes in NodeList in place, removing nodes that do not
// FilterNodes filters nodes in NodeList in place, removing nodes that do not
// satisfy the given condition
// TODO: consider merging with pkg/client/cache.NodeLister
func FilterNodes(nodeList *v1.NodeList, fn func(node v1.Node) bool) {
@ -961,10 +980,12 @@ func isNodeSchedulable(node *v1.Node) bool {
return !node.Spec.Unschedulable && nodeReady && networkReady
}
// IsNodeConditionSetAsExpected indicate if node is ready
func IsNodeConditionSetAsExpected(node *v1.Node, conditionType v1.NodeConditionType, wantTrue bool) bool {
return isNodeConditionSetAsExpected(node, conditionType, wantTrue, false)
}
// IsNodeConditionSetAsExpectedSilent indicate if node is ready with silent
func IsNodeConditionSetAsExpectedSilent(node *v1.Node, conditionType v1.NodeConditionType, wantTrue bool) bool {
return isNodeConditionSetAsExpected(node, conditionType, wantTrue, true)
}
@ -988,20 +1009,19 @@ func isNodeConditionSetAsExpected(node *v1.Node, conditionType v1.NodeConditionT
if wantTrue {
if (cond.Status == v1.ConditionTrue) && !hasNodeControllerTaints {
return true
} else {
msg := ""
if !hasNodeControllerTaints {
msg = fmt.Sprintf("Condition %s of node %s is %v instead of %t. Reason: %v, message: %v",
conditionType, node.Name, cond.Status == v1.ConditionTrue, wantTrue, cond.Reason, cond.Message)
} else {
msg = fmt.Sprintf("Condition %s of node %s is %v, but Node is tainted by NodeController with %v. Failure",
conditionType, node.Name, cond.Status == v1.ConditionTrue, taints)
}
if !silent {
Logf(msg)
}
return false
}
msg := ""
if !hasNodeControllerTaints {
msg = fmt.Sprintf("Condition %s of node %s is %v instead of %t. Reason: %v, message: %v",
conditionType, node.Name, cond.Status == v1.ConditionTrue, wantTrue, cond.Reason, cond.Message)
} else {
msg = fmt.Sprintf("Condition %s of node %s is %v, but Node is tainted by NodeController with %v. Failure",
conditionType, node.Name, cond.Status == v1.ConditionTrue, taints)
}
if !silent {
Logf(msg)
}
return false
} else {
// TODO: check if the Node is tainted once we enable NC notReady/unreachable taints by default
if cond.Status != v1.ConditionTrue {
@ -1016,13 +1036,12 @@ func isNodeConditionSetAsExpected(node *v1.Node, conditionType v1.NodeConditionT
}
if (wantTrue && (cond.Status == v1.ConditionTrue)) || (!wantTrue && (cond.Status != v1.ConditionTrue)) {
return true
} else {
if !silent {
Logf("Condition %s of node %s is %v instead of %t. Reason: %v, message: %v",
conditionType, node.Name, cond.Status == v1.ConditionTrue, wantTrue, cond.Reason, cond.Message)
}
return false
}
if !silent {
Logf("Condition %s of node %s is %v instead of %t. Reason: %v, message: %v",
conditionType, node.Name, cond.Status == v1.ConditionTrue, wantTrue, cond.Reason, cond.Message)
}
return false
}
}
@ -1032,6 +1051,7 @@ func isNodeConditionSetAsExpected(node *v1.Node, conditionType v1.NodeConditionT
return false
}
// IsNodeConditionUnset indicate if set condition
func IsNodeConditionUnset(node *v1.Node, conditionType v1.NodeConditionType) bool {
for _, cond := range node.Status.Conditions {
if cond.Type == conditionType {
@ -1117,6 +1137,7 @@ func waitListSchedulableNodes(c clientset.Interface) (*v1.NodeList, error) {
type podCondition func(pod *v1.Pod) (bool, error)
// WaitForPodCondition waits until pod satisfied condition
func WaitForPodCondition(c clientset.Interface, ns, podName, desc string, timeout time.Duration, condition podCondition) error {
Logf("Waiting up to %v for pod %q in namespace %q to be %q", timeout, podName, ns, desc)
for start := time.Now(); time.Since(start) < timeout; time.Sleep(Poll) {