...

Source file src/sigs.k8s.io/gateway-api/conformance/utils/config/timeout.go

Documentation: sigs.k8s.io/gateway-api/conformance/utils/config

     1  /*
     2  Copyright 2022 The Kubernetes Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package config
    18  
    19  import "time"
    20  
    21  type TimeoutConfig struct {
    22  	// CreateTimeout represents the maximum time for a Kubernetes object to be created.
    23  	// Max value for conformant implementation: None
    24  	CreateTimeout time.Duration
    25  
    26  	// DeleteTimeout represents the maximum time for a Kubernetes object to be deleted.
    27  	// Max value for conformant implementation: None
    28  	DeleteTimeout time.Duration
    29  
    30  	// GetTimeout represents the maximum time to get a Kubernetes object.
    31  	// Max value for conformant implementation: None
    32  	GetTimeout time.Duration
    33  
    34  	// GatewayMustHaveAddress represents the maximum time for at least one IP Address has been set in the status of a Gateway.
    35  	// Max value for conformant implementation: None
    36  	GatewayMustHaveAddress time.Duration
    37  
    38  	// GatewayMustHaveCondition represents the maximum amount of time for a
    39  	// Gateway to have the supplied Condition.
    40  	// Max value for conformant implementation: None
    41  	GatewayMustHaveCondition time.Duration
    42  
    43  	// GatewayStatusMustHaveListeners represents the maximum time for a Gateway to have listeners in status that match the expected listeners.
    44  	// Max value for conformant implementation: None
    45  	GatewayStatusMustHaveListeners time.Duration
    46  
    47  	// GatewayListenersMustHaveCondition represents the maximum time for a Gateway to have all listeners with a specific condition.
    48  	// Max value for conformant implementation: None
    49  	GatewayListenersMustHaveCondition time.Duration
    50  
    51  	// GWCMustBeAccepted represents the maximum time for a GatewayClass to have an Accepted condition set to true.
    52  	// Max value for conformant implementation: None
    53  	GWCMustBeAccepted time.Duration
    54  
    55  	// HTTPRouteMustNotHaveParents represents the maximum time for an HTTPRoute to have either no parents or a single parent that is not accepted.
    56  	// Max value for conformant implementation: None
    57  	HTTPRouteMustNotHaveParents time.Duration
    58  
    59  	// HTTPRouteMustHaveCondition represents the maximum time for an HTTPRoute to have the supplied Condition.
    60  	// Max value for conformant implementation: None
    61  	HTTPRouteMustHaveCondition time.Duration
    62  
    63  	// TLSRouteMustHaveCondition represents the maximum time for an TLSRoute to have the supplied Condition.
    64  	// Max value for conformant implementation: None
    65  	TLSRouteMustHaveCondition time.Duration
    66  
    67  	// RouteMustHaveParents represents the maximum time for an xRoute to have parents in status that match the expected parents.
    68  	// Max value for conformant implementation: None
    69  	RouteMustHaveParents time.Duration
    70  
    71  	// ManifestFetchTimeout represents the maximum time for getting content from a https:// URL.
    72  	// Max value for conformant implementation: None
    73  	ManifestFetchTimeout time.Duration
    74  
    75  	// MaxTimeToConsistency is the maximum time for requiredConsecutiveSuccesses (default 3) requests to succeed in a row before failing the test.
    76  	// Max value for conformant implementation: 30 seconds
    77  	MaxTimeToConsistency time.Duration
    78  
    79  	// NamespacesMustBeReady represents the maximum time for the following to happen within
    80  	// specified namespace(s):
    81  	// * All Pods to be marked as "Ready"
    82  	// * All Gateways to be marked as "Accepted" and "Programmed"
    83  	// Max value for conformant implementation: None
    84  	NamespacesMustBeReady time.Duration
    85  
    86  	// RequestTimeout represents the maximum time for making an HTTP Request with the roundtripper.
    87  	// Max value for conformant implementation: None
    88  	RequestTimeout time.Duration
    89  
    90  	// LatestObservedGenerationSet represents the maximum time for an ObservedGeneration to bump.
    91  	// Max value for conformant implementation: None
    92  	LatestObservedGenerationSet time.Duration
    93  
    94  	// RequiredConsecutiveSuccesses is the number of requests that must succeed in a row
    95  	// to consider a response "consistent" before making additional assertions on the response body.
    96  	// If this number is not reached within MaxTimeToConsistency, the test will fail.
    97  	RequiredConsecutiveSuccesses int
    98  }
    99  
   100  // DefaultTimeoutConfig populates a TimeoutConfig with the default values.
   101  func DefaultTimeoutConfig() TimeoutConfig {
   102  	return TimeoutConfig{
   103  		CreateTimeout:                     60 * time.Second,
   104  		DeleteTimeout:                     10 * time.Second,
   105  		GetTimeout:                        10 * time.Second,
   106  		GatewayMustHaveAddress:            180 * time.Second,
   107  		GatewayMustHaveCondition:          180 * time.Second,
   108  		GatewayStatusMustHaveListeners:    60 * time.Second,
   109  		GatewayListenersMustHaveCondition: 60 * time.Second,
   110  		GWCMustBeAccepted:                 180 * time.Second,
   111  		HTTPRouteMustNotHaveParents:       60 * time.Second,
   112  		HTTPRouteMustHaveCondition:        60 * time.Second,
   113  		TLSRouteMustHaveCondition:         60 * time.Second,
   114  		RouteMustHaveParents:              60 * time.Second,
   115  		ManifestFetchTimeout:              10 * time.Second,
   116  		MaxTimeToConsistency:              30 * time.Second,
   117  		NamespacesMustBeReady:             300 * time.Second,
   118  		RequestTimeout:                    10 * time.Second,
   119  		LatestObservedGenerationSet:       60 * time.Second,
   120  		RequiredConsecutiveSuccesses:      3,
   121  	}
   122  }
   123  
   124  func SetupTimeoutConfig(timeoutConfig *TimeoutConfig) {
   125  	defaultTimeoutConfig := DefaultTimeoutConfig()
   126  	if timeoutConfig.CreateTimeout == 0 {
   127  		timeoutConfig.CreateTimeout = defaultTimeoutConfig.CreateTimeout
   128  	}
   129  	if timeoutConfig.DeleteTimeout == 0 {
   130  		timeoutConfig.DeleteTimeout = defaultTimeoutConfig.DeleteTimeout
   131  	}
   132  	if timeoutConfig.GetTimeout == 0 {
   133  		timeoutConfig.GetTimeout = defaultTimeoutConfig.GetTimeout
   134  	}
   135  	if timeoutConfig.GatewayMustHaveAddress == 0 {
   136  		timeoutConfig.GatewayMustHaveAddress = defaultTimeoutConfig.GatewayMustHaveAddress
   137  	}
   138  	if timeoutConfig.GatewayMustHaveCondition == 0 {
   139  		timeoutConfig.GatewayMustHaveCondition = defaultTimeoutConfig.GatewayMustHaveCondition
   140  	}
   141  	if timeoutConfig.GatewayStatusMustHaveListeners == 0 {
   142  		timeoutConfig.GatewayStatusMustHaveListeners = defaultTimeoutConfig.GatewayStatusMustHaveListeners
   143  	}
   144  	if timeoutConfig.GatewayListenersMustHaveCondition == 0 {
   145  		timeoutConfig.GatewayListenersMustHaveCondition = defaultTimeoutConfig.GatewayListenersMustHaveCondition
   146  	}
   147  	if timeoutConfig.GWCMustBeAccepted == 0 {
   148  		timeoutConfig.GWCMustBeAccepted = defaultTimeoutConfig.GWCMustBeAccepted
   149  	}
   150  	if timeoutConfig.HTTPRouteMustNotHaveParents == 0 {
   151  		timeoutConfig.HTTPRouteMustNotHaveParents = defaultTimeoutConfig.HTTPRouteMustNotHaveParents
   152  	}
   153  	if timeoutConfig.HTTPRouteMustHaveCondition == 0 {
   154  		timeoutConfig.HTTPRouteMustHaveCondition = defaultTimeoutConfig.HTTPRouteMustHaveCondition
   155  	}
   156  	if timeoutConfig.RouteMustHaveParents == 0 {
   157  		timeoutConfig.RouteMustHaveParents = defaultTimeoutConfig.RouteMustHaveParents
   158  	}
   159  	if timeoutConfig.ManifestFetchTimeout == 0 {
   160  		timeoutConfig.ManifestFetchTimeout = defaultTimeoutConfig.ManifestFetchTimeout
   161  	}
   162  	if timeoutConfig.MaxTimeToConsistency == 0 {
   163  		timeoutConfig.MaxTimeToConsistency = defaultTimeoutConfig.MaxTimeToConsistency
   164  	}
   165  	if timeoutConfig.NamespacesMustBeReady == 0 {
   166  		timeoutConfig.NamespacesMustBeReady = defaultTimeoutConfig.NamespacesMustBeReady
   167  	}
   168  	if timeoutConfig.RequestTimeout == 0 {
   169  		timeoutConfig.RequestTimeout = defaultTimeoutConfig.RequestTimeout
   170  	}
   171  	if timeoutConfig.LatestObservedGenerationSet == 0 {
   172  		timeoutConfig.LatestObservedGenerationSet = defaultTimeoutConfig.LatestObservedGenerationSet
   173  	}
   174  	if timeoutConfig.TLSRouteMustHaveCondition == 0 {
   175  		timeoutConfig.TLSRouteMustHaveCondition = defaultTimeoutConfig.TLSRouteMustHaveCondition
   176  	}
   177  }
   178  

View as plain text