3415
vendor/k8s.io/api/core/v1/generated.pb.go
generated
vendored
3415
vendor/k8s.io/api/core/v1/generated.pb.go
generated
vendored
File diff suppressed because it is too large
Load Diff
165
vendor/k8s.io/api/core/v1/generated.proto
generated
vendored
165
vendor/k8s.io/api/core/v1/generated.proto
generated
vendored
@@ -400,6 +400,36 @@ message CinderVolumeSource {
|
||||
optional LocalObjectReference secretRef = 4;
|
||||
}
|
||||
|
||||
// ClaimSource describes a reference to a ResourceClaim.
|
||||
//
|
||||
// Exactly one of these fields should be set. Consumers of this type must
|
||||
// treat an empty object as if it has an unknown value.
|
||||
message ClaimSource {
|
||||
// ResourceClaimName is the name of a ResourceClaim object in the same
|
||||
// namespace as this pod.
|
||||
optional string resourceClaimName = 1;
|
||||
|
||||
// ResourceClaimTemplateName is the name of a ResourceClaimTemplate
|
||||
// object in the same namespace as this pod.
|
||||
//
|
||||
// The template will be used to create a new ResourceClaim, which will
|
||||
// be bound to this pod. When this pod is deleted, the ResourceClaim
|
||||
// will also be deleted. The name of the ResourceClaim will be <pod
|
||||
// name>-<resource name>, where <resource name> is the
|
||||
// PodResourceClaim.Name. Pod validation will reject the pod if the
|
||||
// concatenated name is not valid for a ResourceClaim (e.g. too long).
|
||||
//
|
||||
// An existing ResourceClaim with that name that is not owned by the
|
||||
// pod will not be used for the pod to avoid using an unrelated
|
||||
// resource by mistake. Scheduling and pod startup are then blocked
|
||||
// until the unrelated ResourceClaim is removed.
|
||||
//
|
||||
// This field is immutable and no changes will be made to the
|
||||
// corresponding ResourceClaim by the control plane after creating the
|
||||
// ResourceClaim.
|
||||
optional string resourceClaimTemplateName = 2;
|
||||
}
|
||||
|
||||
// ClientIPConfig represents the configurations of Client IP based session affinity.
|
||||
message ClientIPConfig {
|
||||
// timeoutSeconds specifies the seconds of ClientIP type session sticky time.
|
||||
@@ -2413,7 +2443,7 @@ message NodeSpec {
|
||||
// +optional
|
||||
repeated Taint taints = 5;
|
||||
|
||||
// Deprecated: Previously used to specify the source of the node's configuration for the DynamicKubeletConfig feature. This feature is removed from Kubelets as of 1.24 and will be fully removed in 1.26.
|
||||
// Deprecated: Previously used to specify the source of the node's configuration for the DynamicKubeletConfig feature. This feature is removed.
|
||||
// +optional
|
||||
optional NodeConfigSource configSource = 6;
|
||||
|
||||
@@ -2453,7 +2483,7 @@ message NodeStatus {
|
||||
// More info: https://kubernetes.io/docs/concepts/nodes/node/#addresses
|
||||
// Note: This field is declared as mergeable, but the merge key is not sufficiently
|
||||
// unique, which can cause data corruption when it is merged. Callers should instead
|
||||
// use a full-replacement patch. See http://pr.k8s.io/79391 for an example.
|
||||
// use a full-replacement patch. See https://pr.k8s.io/79391 for an example.
|
||||
// +optional
|
||||
// +patchMergeKey=type
|
||||
// +patchStrategy=merge
|
||||
@@ -2711,30 +2741,37 @@ message PersistentVolumeClaimSpec {
|
||||
// * An existing PVC (PersistentVolumeClaim)
|
||||
// If the provisioner or an external controller can support the specified data source,
|
||||
// it will create a new volume based on the contents of the specified data source.
|
||||
// If the AnyVolumeDataSource feature gate is enabled, this field will always have
|
||||
// the same contents as the DataSourceRef field.
|
||||
// When the AnyVolumeDataSource feature gate is enabled, dataSource contents will be copied to dataSourceRef,
|
||||
// and dataSourceRef contents will be copied to dataSource when dataSourceRef.namespace is not specified.
|
||||
// If the namespace is specified, then dataSourceRef will not be copied to dataSource.
|
||||
// +optional
|
||||
optional TypedLocalObjectReference dataSource = 7;
|
||||
|
||||
// dataSourceRef specifies the object from which to populate the volume with data, if a non-empty
|
||||
// volume is desired. This may be any local object from a non-empty API group (non
|
||||
// volume is desired. This may be any object from a non-empty API group (non
|
||||
// core object) or a PersistentVolumeClaim object.
|
||||
// When this field is specified, volume binding will only succeed if the type of
|
||||
// the specified object matches some installed volume populator or dynamic
|
||||
// provisioner.
|
||||
// This field will replace the functionality of the DataSource field and as such
|
||||
// This field will replace the functionality of the dataSource field and as such
|
||||
// if both fields are non-empty, they must have the same value. For backwards
|
||||
// compatibility, both fields (DataSource and DataSourceRef) will be set to the same
|
||||
// compatibility, when namespace isn't specified in dataSourceRef,
|
||||
// both fields (dataSource and dataSourceRef) will be set to the same
|
||||
// value automatically if one of them is empty and the other is non-empty.
|
||||
// There are two important differences between DataSource and DataSourceRef:
|
||||
// * While DataSource only allows two specific types of objects, DataSourceRef
|
||||
// When namespace is specified in dataSourceRef,
|
||||
// dataSource isn't set to the same value and must be empty.
|
||||
// There are three important differences between dataSource and dataSourceRef:
|
||||
// * While dataSource only allows two specific types of objects, dataSourceRef
|
||||
// allows any non-core object, as well as PersistentVolumeClaim objects.
|
||||
// * While DataSource ignores disallowed values (dropping them), DataSourceRef
|
||||
// * While dataSource ignores disallowed values (dropping them), dataSourceRef
|
||||
// preserves all values, and generates an error if a disallowed value is
|
||||
// specified.
|
||||
// * While dataSource only allows local objects, dataSourceRef allows objects
|
||||
// in any namespaces.
|
||||
// (Beta) Using this field requires the AnyVolumeDataSource feature gate to be enabled.
|
||||
// (Alpha) Using the namespace field of dataSourceRef requires the CrossNamespaceVolumeDataSource feature gate to be enabled.
|
||||
// +optional
|
||||
optional TypedLocalObjectReference dataSourceRef = 8;
|
||||
optional TypedObjectReference dataSourceRef = 8;
|
||||
}
|
||||
|
||||
// PersistentVolumeClaimStatus is the current status of a persistent volume claim.
|
||||
@@ -3353,6 +3390,25 @@ message PodReadinessGate {
|
||||
optional string conditionType = 1;
|
||||
}
|
||||
|
||||
// PodResourceClaim references exactly one ResourceClaim through a ClaimSource.
|
||||
// It adds a name to it that uniquely identifies the ResourceClaim inside the Pod.
|
||||
// Containers that need access to the ResourceClaim reference it with this name.
|
||||
message PodResourceClaim {
|
||||
// Name uniquely identifies this resource claim inside the pod.
|
||||
// This must be a DNS_LABEL.
|
||||
optional string name = 1;
|
||||
|
||||
// Source describes where to find the ResourceClaim.
|
||||
optional ClaimSource source = 2;
|
||||
}
|
||||
|
||||
// PodSchedulingGate is associated to a Pod to guard its scheduling.
|
||||
message PodSchedulingGate {
|
||||
// Name of the scheduling gate.
|
||||
// Each scheduling gate must have a unique name field.
|
||||
optional string name = 1;
|
||||
}
|
||||
|
||||
// PodSecurityContext holds pod-level security attributes and common container settings.
|
||||
// Some fields are also present in container.securityContext. Field values of
|
||||
// container.securityContext take precedence over field values of PodSecurityContext.
|
||||
@@ -3401,8 +3457,11 @@ message PodSecurityContext {
|
||||
optional bool runAsNonRoot = 3;
|
||||
|
||||
// A list of groups applied to the first process run in each container, in addition
|
||||
// to the container's primary GID. If unspecified, no groups will be added to
|
||||
// any container.
|
||||
// to the container's primary GID, the fsGroup (if specified), and group memberships
|
||||
// defined in the container image for the uid of the container process. If unspecified,
|
||||
// no additional groups are added to any container. Note that group memberships
|
||||
// defined in the container image for the uid of the container process are still effective,
|
||||
// even if they are not included in this list.
|
||||
// Note that this field cannot be set when spec.os.name is windows.
|
||||
// +optional
|
||||
repeated int64 supplementalGroups = 4;
|
||||
@@ -3747,6 +3806,35 @@ message PodSpec {
|
||||
// +k8s:conversion-gen=false
|
||||
// +optional
|
||||
optional bool hostUsers = 37;
|
||||
|
||||
// SchedulingGates is an opaque list of values that if specified will block scheduling the pod.
|
||||
// More info: https://git.k8s.io/enhancements/keps/sig-scheduling/3521-pod-scheduling-readiness.
|
||||
//
|
||||
// This is an alpha-level feature enabled by PodSchedulingReadiness feature gate.
|
||||
// +optional
|
||||
// +patchMergeKey=name
|
||||
// +patchStrategy=merge
|
||||
// +listType=map
|
||||
// +listMapKey=name
|
||||
repeated PodSchedulingGate schedulingGates = 38;
|
||||
|
||||
// ResourceClaims defines which ResourceClaims must be allocated
|
||||
// and reserved before the Pod is allowed to start. The resources
|
||||
// will be made available to those containers which consume them
|
||||
// by name.
|
||||
//
|
||||
// This is an alpha field and requires enabling the
|
||||
// DynamicResourceAllocation feature gate.
|
||||
//
|
||||
// This field is immutable.
|
||||
//
|
||||
// +patchMergeKey=name
|
||||
// +patchStrategy=merge,retainKeys
|
||||
// +listType=map
|
||||
// +listMapKey=name
|
||||
// +featureGate=DynamicResourceAllocation
|
||||
// +optional
|
||||
repeated PodResourceClaim resourceClaims = 39;
|
||||
}
|
||||
|
||||
// PodStatus represents information about the status of a pod. Status may trail the actual
|
||||
@@ -4293,7 +4381,7 @@ message ReplicationControllerSpec {
|
||||
// ReplicationControllerStatus represents the current status of a replication
|
||||
// controller.
|
||||
message ReplicationControllerStatus {
|
||||
// Replicas is the most recently oberved number of replicas.
|
||||
// Replicas is the most recently observed number of replicas.
|
||||
// More info: https://kubernetes.io/docs/concepts/workloads/controllers/replicationcontroller#what-is-a-replicationcontroller
|
||||
optional int32 replicas = 1;
|
||||
|
||||
@@ -4320,6 +4408,14 @@ message ReplicationControllerStatus {
|
||||
repeated ReplicationControllerCondition conditions = 6;
|
||||
}
|
||||
|
||||
// ResourceClaim references one entry in PodSpec.ResourceClaims.
|
||||
message ResourceClaim {
|
||||
// Name must match the name of one entry in pod.spec.resourceClaims of
|
||||
// the Pod where this field is used. It makes that resource available
|
||||
// inside a container.
|
||||
optional string name = 1;
|
||||
}
|
||||
|
||||
// ResourceFieldSelector represents container resources (cpu, memory) and their output format
|
||||
// +structType=atomic
|
||||
message ResourceFieldSelector {
|
||||
@@ -4409,6 +4505,20 @@ message ResourceRequirements {
|
||||
// More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/
|
||||
// +optional
|
||||
map<string, k8s.io.apimachinery.pkg.api.resource.Quantity> requests = 2;
|
||||
|
||||
// Claims lists the names of resources, defined in spec.resourceClaims,
|
||||
// that are used by this container.
|
||||
//
|
||||
// This is an alpha field and requires enabling the
|
||||
// DynamicResourceAllocation feature gate.
|
||||
//
|
||||
// This field is immutable.
|
||||
//
|
||||
// +listType=map
|
||||
// +listMapKey=name
|
||||
// +featureGate=DynamicResourceAllocation
|
||||
// +optional
|
||||
repeated ResourceClaim claims = 3;
|
||||
}
|
||||
|
||||
// SELinuxOptions are the labels to be applied to the container
|
||||
@@ -5203,7 +5313,6 @@ message ServiceSpec {
|
||||
// implementation (e.g. cloud providers) should ignore Services that set this field.
|
||||
// This field can only be set when creating or updating a Service to type 'LoadBalancer'.
|
||||
// Once set, it can not be changed. This field will be wiped when a service is updated to a non 'LoadBalancer' type.
|
||||
// +featureGate=LoadBalancerClass
|
||||
// +optional
|
||||
optional string loadBalancerClass = 21;
|
||||
|
||||
@@ -5213,7 +5322,6 @@ message ServiceSpec {
|
||||
// dropping the traffic if there are no local endpoints. The default value,
|
||||
// "Cluster", uses the standard behavior of routing to all endpoints evenly
|
||||
// (possibly modified by topology and other features).
|
||||
// +featureGate=ServiceInternalTrafficPolicy
|
||||
// +optional
|
||||
optional string internalTrafficPolicy = 22;
|
||||
}
|
||||
@@ -5501,7 +5609,7 @@ message TopologySpreadConstraint {
|
||||
// - Ignore: nodeAffinity/nodeSelector are ignored. All nodes are included in the calculations.
|
||||
//
|
||||
// If this value is nil, the behavior is equivalent to the Honor policy.
|
||||
// This is a alpha-level feature enabled by the NodeInclusionPolicyInPodTopologySpread feature flag.
|
||||
// This is a beta-level feature default enabled by the NodeInclusionPolicyInPodTopologySpread feature flag.
|
||||
// +optional
|
||||
optional string nodeAffinityPolicy = 6;
|
||||
|
||||
@@ -5512,7 +5620,7 @@ message TopologySpreadConstraint {
|
||||
// - Ignore: node taints are ignored. All nodes are included.
|
||||
//
|
||||
// If this value is nil, the behavior is equivalent to the Ignore policy.
|
||||
// This is a alpha-level feature enabled by the NodeInclusionPolicyInPodTopologySpread feature flag.
|
||||
// This is a beta-level feature default enabled by the NodeInclusionPolicyInPodTopologySpread feature flag.
|
||||
// +optional
|
||||
optional string nodeTaintsPolicy = 7;
|
||||
|
||||
@@ -5544,6 +5652,27 @@ message TypedLocalObjectReference {
|
||||
optional string name = 3;
|
||||
}
|
||||
|
||||
message TypedObjectReference {
|
||||
// APIGroup is the group for the resource being referenced.
|
||||
// If APIGroup is not specified, the specified Kind must be in the core API group.
|
||||
// For any other third-party types, APIGroup is required.
|
||||
// +optional
|
||||
optional string apiGroup = 1;
|
||||
|
||||
// Kind is the type of resource being referenced
|
||||
optional string kind = 2;
|
||||
|
||||
// Name is the name of resource being referenced
|
||||
optional string name = 3;
|
||||
|
||||
// Namespace is the namespace of resource being referenced
|
||||
// Note that when a namespace is specified, a gateway.networking.k8s.io/ReferenceGrant object is required in the referent namespace to allow that namespace's owner to accept the reference. See the ReferenceGrant documentation for details.
|
||||
// (Alpha) This field requires the CrossNamespaceVolumeDataSource feature gate to be enabled.
|
||||
// +featureGate=CrossNamespaceVolumeDataSource
|
||||
// +optional
|
||||
optional string namespace = 4;
|
||||
}
|
||||
|
||||
// Volume represents a named volume in a pod that may be accessed by any container in the pod.
|
||||
message Volume {
|
||||
// name of the volume.
|
||||
|
||||
186
vendor/k8s.io/api/core/v1/types.go
generated
vendored
186
vendor/k8s.io/api/core/v1/types.go
generated
vendored
@@ -497,29 +497,54 @@ type PersistentVolumeClaimSpec struct {
|
||||
// * An existing PVC (PersistentVolumeClaim)
|
||||
// If the provisioner or an external controller can support the specified data source,
|
||||
// it will create a new volume based on the contents of the specified data source.
|
||||
// If the AnyVolumeDataSource feature gate is enabled, this field will always have
|
||||
// the same contents as the DataSourceRef field.
|
||||
// When the AnyVolumeDataSource feature gate is enabled, dataSource contents will be copied to dataSourceRef,
|
||||
// and dataSourceRef contents will be copied to dataSource when dataSourceRef.namespace is not specified.
|
||||
// If the namespace is specified, then dataSourceRef will not be copied to dataSource.
|
||||
// +optional
|
||||
DataSource *TypedLocalObjectReference `json:"dataSource,omitempty" protobuf:"bytes,7,opt,name=dataSource"`
|
||||
// dataSourceRef specifies the object from which to populate the volume with data, if a non-empty
|
||||
// volume is desired. This may be any local object from a non-empty API group (non
|
||||
// volume is desired. This may be any object from a non-empty API group (non
|
||||
// core object) or a PersistentVolumeClaim object.
|
||||
// When this field is specified, volume binding will only succeed if the type of
|
||||
// the specified object matches some installed volume populator or dynamic
|
||||
// provisioner.
|
||||
// This field will replace the functionality of the DataSource field and as such
|
||||
// This field will replace the functionality of the dataSource field and as such
|
||||
// if both fields are non-empty, they must have the same value. For backwards
|
||||
// compatibility, both fields (DataSource and DataSourceRef) will be set to the same
|
||||
// compatibility, when namespace isn't specified in dataSourceRef,
|
||||
// both fields (dataSource and dataSourceRef) will be set to the same
|
||||
// value automatically if one of them is empty and the other is non-empty.
|
||||
// There are two important differences between DataSource and DataSourceRef:
|
||||
// * While DataSource only allows two specific types of objects, DataSourceRef
|
||||
// When namespace is specified in dataSourceRef,
|
||||
// dataSource isn't set to the same value and must be empty.
|
||||
// There are three important differences between dataSource and dataSourceRef:
|
||||
// * While dataSource only allows two specific types of objects, dataSourceRef
|
||||
// allows any non-core object, as well as PersistentVolumeClaim objects.
|
||||
// * While DataSource ignores disallowed values (dropping them), DataSourceRef
|
||||
// * While dataSource ignores disallowed values (dropping them), dataSourceRef
|
||||
// preserves all values, and generates an error if a disallowed value is
|
||||
// specified.
|
||||
// * While dataSource only allows local objects, dataSourceRef allows objects
|
||||
// in any namespaces.
|
||||
// (Beta) Using this field requires the AnyVolumeDataSource feature gate to be enabled.
|
||||
// (Alpha) Using the namespace field of dataSourceRef requires the CrossNamespaceVolumeDataSource feature gate to be enabled.
|
||||
// +optional
|
||||
DataSourceRef *TypedLocalObjectReference `json:"dataSourceRef,omitempty" protobuf:"bytes,8,opt,name=dataSourceRef"`
|
||||
DataSourceRef *TypedObjectReference `json:"dataSourceRef,omitempty" protobuf:"bytes,8,opt,name=dataSourceRef"`
|
||||
}
|
||||
|
||||
type TypedObjectReference struct {
|
||||
// APIGroup is the group for the resource being referenced.
|
||||
// If APIGroup is not specified, the specified Kind must be in the core API group.
|
||||
// For any other third-party types, APIGroup is required.
|
||||
// +optional
|
||||
APIGroup *string `json:"apiGroup" protobuf:"bytes,1,opt,name=apiGroup"`
|
||||
// Kind is the type of resource being referenced
|
||||
Kind string `json:"kind" protobuf:"bytes,2,opt,name=kind"`
|
||||
// Name is the name of resource being referenced
|
||||
Name string `json:"name" protobuf:"bytes,3,opt,name=name"`
|
||||
// Namespace is the namespace of resource being referenced
|
||||
// Note that when a namespace is specified, a gateway.networking.k8s.io/ReferenceGrant object is required in the referent namespace to allow that namespace's owner to accept the reference. See the ReferenceGrant documentation for details.
|
||||
// (Alpha) This field requires the CrossNamespaceVolumeDataSource feature gate to be enabled.
|
||||
// +featureGate=CrossNamespaceVolumeDataSource
|
||||
// +optional
|
||||
Namespace *string `json:"namespace,omitempty" protobuf:"bytes,4,opt,name=namespace"`
|
||||
}
|
||||
|
||||
// PersistentVolumeClaimConditionType is a valid value of PersistentVolumeClaimCondition.Type
|
||||
@@ -1663,7 +1688,7 @@ type ServiceAccountTokenProjection struct {
|
||||
// must identify itself with an identifier specified in the audience of the
|
||||
// token, and otherwise should reject the token. The audience defaults to the
|
||||
// identifier of the apiserver.
|
||||
//+optional
|
||||
// +optional
|
||||
Audience string `json:"audience,omitempty" protobuf:"bytes,1,rep,name=audience"`
|
||||
// expirationSeconds is the requested duration of validity of the service
|
||||
// account token. As the token approaches expiration, the kubelet volume
|
||||
@@ -1671,7 +1696,7 @@ type ServiceAccountTokenProjection struct {
|
||||
// start trying to rotate the token if the token is older than 80 percent of
|
||||
// its time to live or if the token is older than 24 hours.Defaults to 1 hour
|
||||
// and must be at least 10 minutes.
|
||||
//+optional
|
||||
// +optional
|
||||
ExpirationSeconds *int64 `json:"expirationSeconds,omitempty" protobuf:"varint,2,opt,name=expirationSeconds"`
|
||||
// path is the path relative to the mount point of the file to project the
|
||||
// token into.
|
||||
@@ -2289,6 +2314,27 @@ type ResourceRequirements struct {
|
||||
// More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/
|
||||
// +optional
|
||||
Requests ResourceList `json:"requests,omitempty" protobuf:"bytes,2,rep,name=requests,casttype=ResourceList,castkey=ResourceName"`
|
||||
// Claims lists the names of resources, defined in spec.resourceClaims,
|
||||
// that are used by this container.
|
||||
//
|
||||
// This is an alpha field and requires enabling the
|
||||
// DynamicResourceAllocation feature gate.
|
||||
//
|
||||
// This field is immutable.
|
||||
//
|
||||
// +listType=map
|
||||
// +listMapKey=name
|
||||
// +featureGate=DynamicResourceAllocation
|
||||
// +optional
|
||||
Claims []ResourceClaim `json:"claims,omitempty" protobuf:"bytes,3,opt,name=claims"`
|
||||
}
|
||||
|
||||
// ResourceClaim references one entry in PodSpec.ResourceClaims.
|
||||
type ResourceClaim struct {
|
||||
// Name must match the name of one entry in pod.spec.resourceClaims of
|
||||
// the Pod where this field is used. It makes that resource available
|
||||
// inside a container.
|
||||
Name string `json:"name" protobuf:"bytes,1,opt,name=name"`
|
||||
}
|
||||
|
||||
const (
|
||||
@@ -2654,10 +2700,9 @@ const (
|
||||
PodReady PodConditionType = "Ready"
|
||||
// PodScheduled represents status of the scheduling process for this pod.
|
||||
PodScheduled PodConditionType = "PodScheduled"
|
||||
// AlphaNoCompatGuaranteeDisruptionTarget indicates the pod is about to be deleted due to a
|
||||
// DisruptionTarget indicates the pod is about to be terminated due to a
|
||||
// disruption (such as preemption, eviction API or garbage-collection).
|
||||
// The constant is to be renamed once the name is accepted within the KEP-3329.
|
||||
AlphaNoCompatGuaranteeDisruptionTarget PodConditionType = "DisruptionTarget"
|
||||
DisruptionTarget PodConditionType = "DisruptionTarget"
|
||||
)
|
||||
|
||||
// These are reasons for a pod's transition to a condition.
|
||||
@@ -2665,6 +2710,18 @@ const (
|
||||
// PodReasonUnschedulable reason in PodScheduled PodCondition means that the scheduler
|
||||
// can't schedule the pod right now, for example due to insufficient resources in the cluster.
|
||||
PodReasonUnschedulable = "Unschedulable"
|
||||
|
||||
// PodReasonSchedulingGated reason in PodScheduled PodCondition means that the scheduler
|
||||
// skips scheduling the pod because one or more scheduling gates are still present.
|
||||
PodReasonSchedulingGated = "SchedulingGated"
|
||||
|
||||
// PodReasonSchedulerError reason in PodScheduled PodCondition means that some internal error happens
|
||||
// during scheduling, for example due to nodeAffinity parsing errors.
|
||||
PodReasonSchedulerError = "SchedulerError"
|
||||
|
||||
// TerminationByKubelet reason in DisruptionTarget pod condition indicates that the termination
|
||||
// is initiated by kubelet
|
||||
PodReasonTerminationByKubelet = "TerminationByKubelet"
|
||||
)
|
||||
|
||||
// PodCondition contains details for the current condition of this pod.
|
||||
@@ -2739,7 +2796,7 @@ const (
|
||||
// by the node selector terms.
|
||||
// +structType=atomic
|
||||
type NodeSelector struct {
|
||||
//Required. A list of node selector terms. The terms are ORed.
|
||||
// Required. A list of node selector terms. The terms are ORed.
|
||||
NodeSelectorTerms []NodeSelectorTerm `json:"nodeSelectorTerms" protobuf:"bytes,1,rep,name=nodeSelectorTerms"`
|
||||
}
|
||||
|
||||
@@ -3311,6 +3368,7 @@ type PodSpec struct {
|
||||
// - spec.containers[*].securityContext.runAsGroup
|
||||
// +optional
|
||||
OS *PodOS `json:"os,omitempty" protobuf:"bytes,36,opt,name=os"`
|
||||
|
||||
// Use the host's user namespace.
|
||||
// Optional: Default to true.
|
||||
// If set to true or not present, the pod will be run in the host user namespace, useful
|
||||
@@ -3323,6 +3381,76 @@ type PodSpec struct {
|
||||
// +k8s:conversion-gen=false
|
||||
// +optional
|
||||
HostUsers *bool `json:"hostUsers,omitempty" protobuf:"bytes,37,opt,name=hostUsers"`
|
||||
|
||||
// SchedulingGates is an opaque list of values that if specified will block scheduling the pod.
|
||||
// More info: https://git.k8s.io/enhancements/keps/sig-scheduling/3521-pod-scheduling-readiness.
|
||||
//
|
||||
// This is an alpha-level feature enabled by PodSchedulingReadiness feature gate.
|
||||
// +optional
|
||||
// +patchMergeKey=name
|
||||
// +patchStrategy=merge
|
||||
// +listType=map
|
||||
// +listMapKey=name
|
||||
SchedulingGates []PodSchedulingGate `json:"schedulingGates,omitempty" patchStrategy:"merge" patchMergeKey:"name" protobuf:"bytes,38,opt,name=schedulingGates"`
|
||||
// ResourceClaims defines which ResourceClaims must be allocated
|
||||
// and reserved before the Pod is allowed to start. The resources
|
||||
// will be made available to those containers which consume them
|
||||
// by name.
|
||||
//
|
||||
// This is an alpha field and requires enabling the
|
||||
// DynamicResourceAllocation feature gate.
|
||||
//
|
||||
// This field is immutable.
|
||||
//
|
||||
// +patchMergeKey=name
|
||||
// +patchStrategy=merge,retainKeys
|
||||
// +listType=map
|
||||
// +listMapKey=name
|
||||
// +featureGate=DynamicResourceAllocation
|
||||
// +optional
|
||||
ResourceClaims []PodResourceClaim `json:"resourceClaims,omitempty" patchStrategy:"merge,retainKeys" patchMergeKey:"name" protobuf:"bytes,39,rep,name=resourceClaims"`
|
||||
}
|
||||
|
||||
// PodResourceClaim references exactly one ResourceClaim through a ClaimSource.
|
||||
// It adds a name to it that uniquely identifies the ResourceClaim inside the Pod.
|
||||
// Containers that need access to the ResourceClaim reference it with this name.
|
||||
type PodResourceClaim struct {
|
||||
// Name uniquely identifies this resource claim inside the pod.
|
||||
// This must be a DNS_LABEL.
|
||||
Name string `json:"name" protobuf:"bytes,1,name=name"`
|
||||
|
||||
// Source describes where to find the ResourceClaim.
|
||||
Source ClaimSource `json:"source,omitempty" protobuf:"bytes,2,name=source"`
|
||||
}
|
||||
|
||||
// ClaimSource describes a reference to a ResourceClaim.
|
||||
//
|
||||
// Exactly one of these fields should be set. Consumers of this type must
|
||||
// treat an empty object as if it has an unknown value.
|
||||
type ClaimSource struct {
|
||||
// ResourceClaimName is the name of a ResourceClaim object in the same
|
||||
// namespace as this pod.
|
||||
ResourceClaimName *string `json:"resourceClaimName,omitempty" protobuf:"bytes,1,opt,name=resourceClaimName"`
|
||||
|
||||
// ResourceClaimTemplateName is the name of a ResourceClaimTemplate
|
||||
// object in the same namespace as this pod.
|
||||
//
|
||||
// The template will be used to create a new ResourceClaim, which will
|
||||
// be bound to this pod. When this pod is deleted, the ResourceClaim
|
||||
// will also be deleted. The name of the ResourceClaim will be <pod
|
||||
// name>-<resource name>, where <resource name> is the
|
||||
// PodResourceClaim.Name. Pod validation will reject the pod if the
|
||||
// concatenated name is not valid for a ResourceClaim (e.g. too long).
|
||||
//
|
||||
// An existing ResourceClaim with that name that is not owned by the
|
||||
// pod will not be used for the pod to avoid using an unrelated
|
||||
// resource by mistake. Scheduling and pod startup are then blocked
|
||||
// until the unrelated ResourceClaim is removed.
|
||||
//
|
||||
// This field is immutable and no changes will be made to the
|
||||
// corresponding ResourceClaim by the control plane after creating the
|
||||
// ResourceClaim.
|
||||
ResourceClaimTemplateName *string `json:"resourceClaimTemplateName,omitempty" protobuf:"bytes,2,opt,name=resourceClaimTemplateName"`
|
||||
}
|
||||
|
||||
// OSName is the set of OS'es that can be used in OS.
|
||||
@@ -3343,6 +3471,13 @@ type PodOS struct {
|
||||
Name OSName `json:"name" protobuf:"bytes,1,opt,name=name"`
|
||||
}
|
||||
|
||||
// PodSchedulingGate is associated to a Pod to guard its scheduling.
|
||||
type PodSchedulingGate struct {
|
||||
// Name of the scheduling gate.
|
||||
// Each scheduling gate must have a unique name field.
|
||||
Name string `json:"name" protobuf:"bytes,1,opt,name=name"`
|
||||
}
|
||||
|
||||
// +enum
|
||||
type UnsatisfiableConstraintAction string
|
||||
|
||||
@@ -3459,7 +3594,7 @@ type TopologySpreadConstraint struct {
|
||||
// - Ignore: nodeAffinity/nodeSelector are ignored. All nodes are included in the calculations.
|
||||
//
|
||||
// If this value is nil, the behavior is equivalent to the Honor policy.
|
||||
// This is a alpha-level feature enabled by the NodeInclusionPolicyInPodTopologySpread feature flag.
|
||||
// This is a beta-level feature default enabled by the NodeInclusionPolicyInPodTopologySpread feature flag.
|
||||
// +optional
|
||||
NodeAffinityPolicy *NodeInclusionPolicy `json:"nodeAffinityPolicy,omitempty" protobuf:"bytes,6,opt,name=nodeAffinityPolicy"`
|
||||
// NodeTaintsPolicy indicates how we will treat node taints when calculating
|
||||
@@ -3469,7 +3604,7 @@ type TopologySpreadConstraint struct {
|
||||
// - Ignore: node taints are ignored. All nodes are included.
|
||||
//
|
||||
// If this value is nil, the behavior is equivalent to the Ignore policy.
|
||||
// This is a alpha-level feature enabled by the NodeInclusionPolicyInPodTopologySpread feature flag.
|
||||
// This is a beta-level feature default enabled by the NodeInclusionPolicyInPodTopologySpread feature flag.
|
||||
// +optional
|
||||
NodeTaintsPolicy *NodeInclusionPolicy `json:"nodeTaintsPolicy,omitempty" protobuf:"bytes,7,opt,name=nodeTaintsPolicy"`
|
||||
// MatchLabelKeys is a set of pod label keys to select the pods over which
|
||||
@@ -3557,8 +3692,11 @@ type PodSecurityContext struct {
|
||||
// +optional
|
||||
RunAsNonRoot *bool `json:"runAsNonRoot,omitempty" protobuf:"varint,3,opt,name=runAsNonRoot"`
|
||||
// A list of groups applied to the first process run in each container, in addition
|
||||
// to the container's primary GID. If unspecified, no groups will be added to
|
||||
// any container.
|
||||
// to the container's primary GID, the fsGroup (if specified), and group memberships
|
||||
// defined in the container image for the uid of the container process. If unspecified,
|
||||
// no additional groups are added to any container. Note that group memberships
|
||||
// defined in the container image for the uid of the container process are still effective,
|
||||
// even if they are not included in this list.
|
||||
// Note that this field cannot be set when spec.os.name is windows.
|
||||
// +optional
|
||||
SupplementalGroups []int64 `json:"supplementalGroups,omitempty" protobuf:"varint,4,rep,name=supplementalGroups"`
|
||||
@@ -4079,7 +4217,7 @@ type ReplicationControllerSpec struct {
|
||||
// ReplicationControllerStatus represents the current status of a replication
|
||||
// controller.
|
||||
type ReplicationControllerStatus struct {
|
||||
// Replicas is the most recently oberved number of replicas.
|
||||
// Replicas is the most recently observed number of replicas.
|
||||
// More info: https://kubernetes.io/docs/concepts/workloads/controllers/replicationcontroller#what-is-a-replicationcontroller
|
||||
Replicas int32 `json:"replicas" protobuf:"varint,1,opt,name=replicas"`
|
||||
|
||||
@@ -4522,7 +4660,7 @@ type ServiceSpec struct {
|
||||
SessionAffinityConfig *SessionAffinityConfig `json:"sessionAffinityConfig,omitempty" protobuf:"bytes,14,opt,name=sessionAffinityConfig"`
|
||||
|
||||
// TopologyKeys is tombstoned to show why 16 is reserved protobuf tag.
|
||||
//TopologyKeys []string `json:"topologyKeys,omitempty" protobuf:"bytes,16,opt,name=topologyKeys"`
|
||||
// TopologyKeys []string `json:"topologyKeys,omitempty" protobuf:"bytes,16,opt,name=topologyKeys"`
|
||||
|
||||
// IPFamily is tombstoned to show why 15 is a reserved protobuf tag.
|
||||
// IPFamily *IPFamily `json:"ipFamily,omitempty" protobuf:"bytes,15,opt,name=ipFamily,Configcasttype=IPFamily"`
|
||||
@@ -4578,7 +4716,6 @@ type ServiceSpec struct {
|
||||
// implementation (e.g. cloud providers) should ignore Services that set this field.
|
||||
// This field can only be set when creating or updating a Service to type 'LoadBalancer'.
|
||||
// Once set, it can not be changed. This field will be wiped when a service is updated to a non 'LoadBalancer' type.
|
||||
// +featureGate=LoadBalancerClass
|
||||
// +optional
|
||||
LoadBalancerClass *string `json:"loadBalancerClass,omitempty" protobuf:"bytes,21,opt,name=loadBalancerClass"`
|
||||
|
||||
@@ -4588,7 +4725,6 @@ type ServiceSpec struct {
|
||||
// dropping the traffic if there are no local endpoints. The default value,
|
||||
// "Cluster", uses the standard behavior of routing to all endpoints evenly
|
||||
// (possibly modified by topology and other features).
|
||||
// +featureGate=ServiceInternalTrafficPolicy
|
||||
// +optional
|
||||
InternalTrafficPolicy *ServiceInternalTrafficPolicyType `json:"internalTrafficPolicy,omitempty" protobuf:"bytes,22,opt,name=internalTrafficPolicy"`
|
||||
}
|
||||
@@ -4895,7 +5031,7 @@ type NodeSpec struct {
|
||||
// +optional
|
||||
Taints []Taint `json:"taints,omitempty" protobuf:"bytes,5,opt,name=taints"`
|
||||
|
||||
// Deprecated: Previously used to specify the source of the node's configuration for the DynamicKubeletConfig feature. This feature is removed from Kubelets as of 1.24 and will be fully removed in 1.26.
|
||||
// Deprecated: Previously used to specify the source of the node's configuration for the DynamicKubeletConfig feature. This feature is removed.
|
||||
// +optional
|
||||
ConfigSource *NodeConfigSource `json:"configSource,omitempty" protobuf:"bytes,6,opt,name=configSource"`
|
||||
|
||||
@@ -5069,7 +5205,7 @@ type NodeStatus struct {
|
||||
// More info: https://kubernetes.io/docs/concepts/nodes/node/#addresses
|
||||
// Note: This field is declared as mergeable, but the merge key is not sufficiently
|
||||
// unique, which can cause data corruption when it is merged. Callers should instead
|
||||
// use a full-replacement patch. See http://pr.k8s.io/79391 for an example.
|
||||
// use a full-replacement patch. See https://pr.k8s.io/79391 for an example.
|
||||
// +optional
|
||||
// +patchMergeKey=type
|
||||
// +patchStrategy=merge
|
||||
|
||||
68
vendor/k8s.io/api/core/v1/types_swagger_doc_generated.go
generated
vendored
68
vendor/k8s.io/api/core/v1/types_swagger_doc_generated.go
generated
vendored
@@ -209,6 +209,16 @@ func (CinderVolumeSource) SwaggerDoc() map[string]string {
|
||||
return map_CinderVolumeSource
|
||||
}
|
||||
|
||||
var map_ClaimSource = map[string]string{
|
||||
"": "ClaimSource describes a reference to a ResourceClaim.\n\nExactly one of these fields should be set. Consumers of this type must treat an empty object as if it has an unknown value.",
|
||||
"resourceClaimName": "ResourceClaimName is the name of a ResourceClaim object in the same namespace as this pod.",
|
||||
"resourceClaimTemplateName": "ResourceClaimTemplateName is the name of a ResourceClaimTemplate object in the same namespace as this pod.\n\nThe template will be used to create a new ResourceClaim, which will be bound to this pod. When this pod is deleted, the ResourceClaim will also be deleted. The name of the ResourceClaim will be <pod name>-<resource name>, where <resource name> is the PodResourceClaim.Name. Pod validation will reject the pod if the concatenated name is not valid for a ResourceClaim (e.g. too long).\n\nAn existing ResourceClaim with that name that is not owned by the pod will not be used for the pod to avoid using an unrelated resource by mistake. Scheduling and pod startup are then blocked until the unrelated ResourceClaim is removed.\n\nThis field is immutable and no changes will be made to the corresponding ResourceClaim by the control plane after creating the ResourceClaim.",
|
||||
}
|
||||
|
||||
func (ClaimSource) SwaggerDoc() map[string]string {
|
||||
return map_ClaimSource
|
||||
}
|
||||
|
||||
var map_ClientIPConfig = map[string]string{
|
||||
"": "ClientIPConfig represents the configurations of Client IP based session affinity.",
|
||||
"timeoutSeconds": "timeoutSeconds specifies the seconds of ClientIP type session sticky time. The value must be >0 && <=86400(for 1 day) if ServiceAffinity == \"ClientIP\". Default value is 10800(for 3 hours).",
|
||||
@@ -1189,7 +1199,7 @@ var map_NodeSpec = map[string]string{
|
||||
"providerID": "ID of the node assigned by the cloud provider in the format: <ProviderName>://<ProviderSpecificNodeID>",
|
||||
"unschedulable": "Unschedulable controls node schedulability of new pods. By default, node is schedulable. More info: https://kubernetes.io/docs/concepts/nodes/node/#manual-node-administration",
|
||||
"taints": "If specified, the node's taints.",
|
||||
"configSource": "Deprecated: Previously used to specify the source of the node's configuration for the DynamicKubeletConfig feature. This feature is removed from Kubelets as of 1.24 and will be fully removed in 1.26.",
|
||||
"configSource": "Deprecated: Previously used to specify the source of the node's configuration for the DynamicKubeletConfig feature. This feature is removed.",
|
||||
"externalID": "Deprecated. Not all kubelets will set this field. Remove field after 1.13. see: https://issues.k8s.io/61966",
|
||||
}
|
||||
|
||||
@@ -1203,7 +1213,7 @@ var map_NodeStatus = map[string]string{
|
||||
"allocatable": "Allocatable represents the resources of a node that are available for scheduling. Defaults to Capacity.",
|
||||
"phase": "NodePhase is the recently observed lifecycle phase of the node. More info: https://kubernetes.io/docs/concepts/nodes/node/#phase The field is never populated, and now is deprecated.",
|
||||
"conditions": "Conditions is an array of current observed node conditions. More info: https://kubernetes.io/docs/concepts/nodes/node/#condition",
|
||||
"addresses": "List of addresses reachable to the node. Queried from cloud provider, if available. More info: https://kubernetes.io/docs/concepts/nodes/node/#addresses Note: This field is declared as mergeable, but the merge key is not sufficiently unique, which can cause data corruption when it is merged. Callers should instead use a full-replacement patch. See http://pr.k8s.io/79391 for an example.",
|
||||
"addresses": "List of addresses reachable to the node. Queried from cloud provider, if available. More info: https://kubernetes.io/docs/concepts/nodes/node/#addresses Note: This field is declared as mergeable, but the merge key is not sufficiently unique, which can cause data corruption when it is merged. Callers should instead use a full-replacement patch. See https://pr.k8s.io/79391 for an example.",
|
||||
"daemonEndpoints": "Endpoints of daemons running on the Node.",
|
||||
"nodeInfo": "Set of ids/uuids to uniquely identify the node. More info: https://kubernetes.io/docs/concepts/nodes/node/#info",
|
||||
"images": "List of container images on this node",
|
||||
@@ -1311,8 +1321,8 @@ var map_PersistentVolumeClaimSpec = map[string]string{
|
||||
"volumeName": "volumeName is the binding reference to the PersistentVolume backing this claim.",
|
||||
"storageClassName": "storageClassName is the name of the StorageClass required by the claim. More info: https://kubernetes.io/docs/concepts/storage/persistent-volumes#class-1",
|
||||
"volumeMode": "volumeMode defines what type of volume is required by the claim. Value of Filesystem is implied when not included in claim spec.",
|
||||
"dataSource": "dataSource field can be used to specify either: * An existing VolumeSnapshot object (snapshot.storage.k8s.io/VolumeSnapshot) * An existing PVC (PersistentVolumeClaim) If the provisioner or an external controller can support the specified data source, it will create a new volume based on the contents of the specified data source. If the AnyVolumeDataSource feature gate is enabled, this field will always have the same contents as the DataSourceRef field.",
|
||||
"dataSourceRef": "dataSourceRef specifies the object from which to populate the volume with data, if a non-empty volume is desired. This may be any local object from a non-empty API group (non core object) or a PersistentVolumeClaim object. When this field is specified, volume binding will only succeed if the type of the specified object matches some installed volume populator or dynamic provisioner. This field will replace the functionality of the DataSource field and as such if both fields are non-empty, they must have the same value. For backwards compatibility, both fields (DataSource and DataSourceRef) will be set to the same value automatically if one of them is empty and the other is non-empty. There are two important differences between DataSource and DataSourceRef: * While DataSource only allows two specific types of objects, DataSourceRef\n allows any non-core object, as well as PersistentVolumeClaim objects.\n* While DataSource ignores disallowed values (dropping them), DataSourceRef\n preserves all values, and generates an error if a disallowed value is\n specified.\n(Beta) Using this field requires the AnyVolumeDataSource feature gate to be enabled.",
|
||||
"dataSource": "dataSource field can be used to specify either: * An existing VolumeSnapshot object (snapshot.storage.k8s.io/VolumeSnapshot) * An existing PVC (PersistentVolumeClaim) If the provisioner or an external controller can support the specified data source, it will create a new volume based on the contents of the specified data source. When the AnyVolumeDataSource feature gate is enabled, dataSource contents will be copied to dataSourceRef, and dataSourceRef contents will be copied to dataSource when dataSourceRef.namespace is not specified. If the namespace is specified, then dataSourceRef will not be copied to dataSource.",
|
||||
"dataSourceRef": "dataSourceRef specifies the object from which to populate the volume with data, if a non-empty volume is desired. This may be any object from a non-empty API group (non core object) or a PersistentVolumeClaim object. When this field is specified, volume binding will only succeed if the type of the specified object matches some installed volume populator or dynamic provisioner. This field will replace the functionality of the dataSource field and as such if both fields are non-empty, they must have the same value. For backwards compatibility, when namespace isn't specified in dataSourceRef, both fields (dataSource and dataSourceRef) will be set to the same value automatically if one of them is empty and the other is non-empty. When namespace is specified in dataSourceRef, dataSource isn't set to the same value and must be empty. There are three important differences between dataSource and dataSourceRef: * While dataSource only allows two specific types of objects, dataSourceRef\n allows any non-core object, as well as PersistentVolumeClaim objects.\n* While dataSource ignores disallowed values (dropping them), dataSourceRef\n preserves all values, and generates an error if a disallowed value is\n specified.\n* While dataSource only allows local objects, dataSourceRef allows objects\n in any namespaces.\n(Beta) Using this field requires the AnyVolumeDataSource feature gate to be enabled. (Alpha) Using the namespace field of dataSourceRef requires the CrossNamespaceVolumeDataSource feature gate to be enabled.",
|
||||
}
|
||||
|
||||
func (PersistentVolumeClaimSpec) SwaggerDoc() map[string]string {
|
||||
@@ -1606,6 +1616,25 @@ func (PodReadinessGate) SwaggerDoc() map[string]string {
|
||||
return map_PodReadinessGate
|
||||
}
|
||||
|
||||
var map_PodResourceClaim = map[string]string{
|
||||
"": "PodResourceClaim references exactly one ResourceClaim through a ClaimSource. It adds a name to it that uniquely identifies the ResourceClaim inside the Pod. Containers that need access to the ResourceClaim reference it with this name.",
|
||||
"name": "Name uniquely identifies this resource claim inside the pod. This must be a DNS_LABEL.",
|
||||
"source": "Source describes where to find the ResourceClaim.",
|
||||
}
|
||||
|
||||
func (PodResourceClaim) SwaggerDoc() map[string]string {
|
||||
return map_PodResourceClaim
|
||||
}
|
||||
|
||||
var map_PodSchedulingGate = map[string]string{
|
||||
"": "PodSchedulingGate is associated to a Pod to guard its scheduling.",
|
||||
"name": "Name of the scheduling gate. Each scheduling gate must have a unique name field.",
|
||||
}
|
||||
|
||||
func (PodSchedulingGate) SwaggerDoc() map[string]string {
|
||||
return map_PodSchedulingGate
|
||||
}
|
||||
|
||||
var map_PodSecurityContext = map[string]string{
|
||||
"": "PodSecurityContext holds pod-level security attributes and common container settings. Some fields are also present in container.securityContext. Field values of container.securityContext take precedence over field values of PodSecurityContext.",
|
||||
"seLinuxOptions": "The SELinux context to be applied to all containers. If unspecified, the container runtime will allocate a random SELinux context for each container. May also be set in SecurityContext. If set in both SecurityContext and PodSecurityContext, the value specified in SecurityContext takes precedence for that container. Note that this field cannot be set when spec.os.name is windows.",
|
||||
@@ -1613,7 +1642,7 @@ var map_PodSecurityContext = map[string]string{
|
||||
"runAsUser": "The UID to run the entrypoint of the container process. Defaults to user specified in image metadata if unspecified. May also be set in SecurityContext. If set in both SecurityContext and PodSecurityContext, the value specified in SecurityContext takes precedence for that container. Note that this field cannot be set when spec.os.name is windows.",
|
||||
"runAsGroup": "The GID to run the entrypoint of the container process. Uses runtime default if unset. May also be set in SecurityContext. If set in both SecurityContext and PodSecurityContext, the value specified in SecurityContext takes precedence for that container. Note that this field cannot be set when spec.os.name is windows.",
|
||||
"runAsNonRoot": "Indicates that the container must run as a non-root user. If true, the Kubelet will validate the image at runtime to ensure that it does not run as UID 0 (root) and fail to start the container if it does. If unset or false, no such validation will be performed. May also be set in SecurityContext. If set in both SecurityContext and PodSecurityContext, the value specified in SecurityContext takes precedence.",
|
||||
"supplementalGroups": "A list of groups applied to the first process run in each container, in addition to the container's primary GID. If unspecified, no groups will be added to any container. Note that this field cannot be set when spec.os.name is windows.",
|
||||
"supplementalGroups": "A list of groups applied to the first process run in each container, in addition to the container's primary GID, the fsGroup (if specified), and group memberships defined in the container image for the uid of the container process. If unspecified, no additional groups are added to any container. Note that group memberships defined in the container image for the uid of the container process are still effective, even if they are not included in this list. Note that this field cannot be set when spec.os.name is windows.",
|
||||
"fsGroup": "A special supplemental group that applies to all containers in a pod. Some volume types allow the Kubelet to change the ownership of that volume to be owned by the pod:\n\n1. The owning GID will be the FSGroup 2. The setgid bit is set (new files created in the volume will be owned by FSGroup) 3. The permission bits are OR'd with rw-rw ",
|
||||
"sysctls": "Sysctls hold a list of namespaced sysctls used for the pod. Pods with unsupported sysctls (by the container runtime) might fail to launch. Note that this field cannot be set when spec.os.name is windows.",
|
||||
"fsGroupChangePolicy": "fsGroupChangePolicy defines behavior of changing ownership and permission of the volume before being exposed inside Pod. This field will only apply to volume types which support fsGroup based ownership(and permissions). It will have no effect on ephemeral volume types such as: secret, configmaps and emptydir. Valid values are \"OnRootMismatch\" and \"Always\". If not specified, \"Always\" is used. Note that this field cannot be set when spec.os.name is windows.",
|
||||
@@ -1672,6 +1701,8 @@ var map_PodSpec = map[string]string{
|
||||
"setHostnameAsFQDN": "If true the pod's hostname will be configured as the pod's FQDN, rather than the leaf name (the default). In Linux containers, this means setting the FQDN in the hostname field of the kernel (the nodename field of struct utsname). In Windows containers, this means setting the registry value of hostname for the registry key HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters to FQDN. If a pod does not have FQDN, this has no effect. Default to false.",
|
||||
"os": "Specifies the OS of the containers in the pod. Some pod and container fields are restricted if this is set.\n\nIf the OS field is set to linux, the following fields must be unset: -securityContext.windowsOptions\n\nIf the OS field is set to windows, following fields must be unset: - spec.hostPID - spec.hostIPC - spec.hostUsers - spec.securityContext.seLinuxOptions - spec.securityContext.seccompProfile - spec.securityContext.fsGroup - spec.securityContext.fsGroupChangePolicy - spec.securityContext.sysctls - spec.shareProcessNamespace - spec.securityContext.runAsUser - spec.securityContext.runAsGroup - spec.securityContext.supplementalGroups - spec.containers[*].securityContext.seLinuxOptions - spec.containers[*].securityContext.seccompProfile - spec.containers[*].securityContext.capabilities - spec.containers[*].securityContext.readOnlyRootFilesystem - spec.containers[*].securityContext.privileged - spec.containers[*].securityContext.allowPrivilegeEscalation - spec.containers[*].securityContext.procMount - spec.containers[*].securityContext.runAsUser - spec.containers[*].securityContext.runAsGroup",
|
||||
"hostUsers": "Use the host's user namespace. Optional: Default to true. If set to true or not present, the pod will be run in the host user namespace, useful for when the pod needs a feature only available to the host user namespace, such as loading a kernel module with CAP_SYS_MODULE. When set to false, a new userns is created for the pod. Setting false is useful for mitigating container breakout vulnerabilities even allowing users to run their containers as root without actually having root privileges on the host. This field is alpha-level and is only honored by servers that enable the UserNamespacesSupport feature.",
|
||||
"schedulingGates": "SchedulingGates is an opaque list of values that if specified will block scheduling the pod. More info: https://git.k8s.io/enhancements/keps/sig-scheduling/3521-pod-scheduling-readiness.\n\nThis is an alpha-level feature enabled by PodSchedulingReadiness feature gate.",
|
||||
"resourceClaims": "ResourceClaims defines which ResourceClaims must be allocated and reserved before the Pod is allowed to start. The resources will be made available to those containers which consume them by name.\n\nThis is an alpha field and requires enabling the DynamicResourceAllocation feature gate.\n\nThis field is immutable.",
|
||||
}
|
||||
|
||||
func (PodSpec) SwaggerDoc() map[string]string {
|
||||
@@ -1932,7 +1963,7 @@ func (ReplicationControllerSpec) SwaggerDoc() map[string]string {
|
||||
|
||||
var map_ReplicationControllerStatus = map[string]string{
|
||||
"": "ReplicationControllerStatus represents the current status of a replication controller.",
|
||||
"replicas": "Replicas is the most recently oberved number of replicas. More info: https://kubernetes.io/docs/concepts/workloads/controllers/replicationcontroller#what-is-a-replicationcontroller",
|
||||
"replicas": "Replicas is the most recently observed number of replicas. More info: https://kubernetes.io/docs/concepts/workloads/controllers/replicationcontroller#what-is-a-replicationcontroller",
|
||||
"fullyLabeledReplicas": "The number of pods that have labels matching the labels of the pod template of the replication controller.",
|
||||
"readyReplicas": "The number of ready replicas for this replication controller.",
|
||||
"availableReplicas": "The number of available replicas (ready for at least minReadySeconds) for this replication controller.",
|
||||
@@ -1944,6 +1975,15 @@ func (ReplicationControllerStatus) SwaggerDoc() map[string]string {
|
||||
return map_ReplicationControllerStatus
|
||||
}
|
||||
|
||||
var map_ResourceClaim = map[string]string{
|
||||
"": "ResourceClaim references one entry in PodSpec.ResourceClaims.",
|
||||
"name": "Name must match the name of one entry in pod.spec.resourceClaims of the Pod where this field is used. It makes that resource available inside a container.",
|
||||
}
|
||||
|
||||
func (ResourceClaim) SwaggerDoc() map[string]string {
|
||||
return map_ResourceClaim
|
||||
}
|
||||
|
||||
var map_ResourceFieldSelector = map[string]string{
|
||||
"": "ResourceFieldSelector represents container resources (cpu, memory) and their output format",
|
||||
"containerName": "Container name: required for volumes, optional for env vars",
|
||||
@@ -2001,6 +2041,7 @@ var map_ResourceRequirements = map[string]string{
|
||||
"": "ResourceRequirements describes the compute resource requirements.",
|
||||
"limits": "Limits describes the maximum amount of compute resources allowed. More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/",
|
||||
"requests": "Requests describes the minimum amount of compute resources required. If Requests is omitted for a container, it defaults to Limits if that is explicitly specified, otherwise to an implementation-defined value. More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/",
|
||||
"claims": "Claims lists the names of resources, defined in spec.resourceClaims, that are used by this container.\n\nThis is an alpha field and requires enabling the DynamicResourceAllocation feature gate.\n\nThis field is immutable.",
|
||||
}
|
||||
|
||||
func (ResourceRequirements) SwaggerDoc() map[string]string {
|
||||
@@ -2407,8 +2448,8 @@ var map_TopologySpreadConstraint = map[string]string{
|
||||
"whenUnsatisfiable": "WhenUnsatisfiable indicates how to deal with a pod if it doesn't satisfy the spread constraint. - DoNotSchedule (default) tells the scheduler not to schedule it. - ScheduleAnyway tells the scheduler to schedule the pod in any location,\n but giving higher precedence to topologies that would help reduce the\n skew.\nA constraint is considered \"Unsatisfiable\" for an incoming pod if and only if every possible node assignment for that pod would violate \"MaxSkew\" on some topology. For example, in a 3-zone cluster, MaxSkew is set to 1, and pods with the same labelSelector spread as 3/1/1: ",
|
||||
"labelSelector": "LabelSelector is used to find matching pods. Pods that match this label selector are counted to determine the number of pods in their corresponding topology domain.",
|
||||
"minDomains": "MinDomains indicates a minimum number of eligible domains. When the number of eligible domains with matching topology keys is less than minDomains, Pod Topology Spread treats \"global minimum\" as 0, and then the calculation of Skew is performed. And when the number of eligible domains with matching topology keys equals or greater than minDomains, this value has no effect on scheduling. As a result, when the number of eligible domains is less than minDomains, scheduler won't schedule more than maxSkew Pods to those domains. If value is nil, the constraint behaves as if MinDomains is equal to 1. Valid values are integers greater than 0. When value is not nil, WhenUnsatisfiable must be DoNotSchedule.\n\nFor example, in a 3-zone cluster, MaxSkew is set to 2, MinDomains is set to 5 and pods with the same labelSelector spread as 2/2/2: ",
|
||||
"nodeAffinityPolicy": "NodeAffinityPolicy indicates how we will treat Pod's nodeAffinity/nodeSelector when calculating pod topology spread skew. Options are: - Honor: only nodes matching nodeAffinity/nodeSelector are included in the calculations. - Ignore: nodeAffinity/nodeSelector are ignored. All nodes are included in the calculations.\n\nIf this value is nil, the behavior is equivalent to the Honor policy. This is a alpha-level feature enabled by the NodeInclusionPolicyInPodTopologySpread feature flag.",
|
||||
"nodeTaintsPolicy": "NodeTaintsPolicy indicates how we will treat node taints when calculating pod topology spread skew. Options are: - Honor: nodes without taints, along with tainted nodes for which the incoming pod has a toleration, are included. - Ignore: node taints are ignored. All nodes are included.\n\nIf this value is nil, the behavior is equivalent to the Ignore policy. This is a alpha-level feature enabled by the NodeInclusionPolicyInPodTopologySpread feature flag.",
|
||||
"nodeAffinityPolicy": "NodeAffinityPolicy indicates how we will treat Pod's nodeAffinity/nodeSelector when calculating pod topology spread skew. Options are: - Honor: only nodes matching nodeAffinity/nodeSelector are included in the calculations. - Ignore: nodeAffinity/nodeSelector are ignored. All nodes are included in the calculations.\n\nIf this value is nil, the behavior is equivalent to the Honor policy. This is a beta-level feature default enabled by the NodeInclusionPolicyInPodTopologySpread feature flag.",
|
||||
"nodeTaintsPolicy": "NodeTaintsPolicy indicates how we will treat node taints when calculating pod topology spread skew. Options are: - Honor: nodes without taints, along with tainted nodes for which the incoming pod has a toleration, are included. - Ignore: node taints are ignored. All nodes are included.\n\nIf this value is nil, the behavior is equivalent to the Ignore policy. This is a beta-level feature default enabled by the NodeInclusionPolicyInPodTopologySpread feature flag.",
|
||||
"matchLabelKeys": "MatchLabelKeys is a set of pod label keys to select the pods over which spreading will be calculated. The keys are used to lookup values from the incoming pod labels, those key-value labels are ANDed with labelSelector to select the group of existing pods over which spreading will be calculated for the incoming pod. Keys that don't exist in the incoming pod labels will be ignored. A null or empty list means only match against labelSelector.",
|
||||
}
|
||||
|
||||
@@ -2427,6 +2468,17 @@ func (TypedLocalObjectReference) SwaggerDoc() map[string]string {
|
||||
return map_TypedLocalObjectReference
|
||||
}
|
||||
|
||||
var map_TypedObjectReference = map[string]string{
|
||||
"apiGroup": "APIGroup is the group for the resource being referenced. If APIGroup is not specified, the specified Kind must be in the core API group. For any other third-party types, APIGroup is required.",
|
||||
"kind": "Kind is the type of resource being referenced",
|
||||
"name": "Name is the name of resource being referenced",
|
||||
"namespace": "Namespace is the namespace of resource being referenced Note that when a namespace is specified, a gateway.networking.k8s.io/ReferenceGrant object is required in the referent namespace to allow that namespace's owner to accept the reference. See the ReferenceGrant documentation for details. (Alpha) This field requires the CrossNamespaceVolumeDataSource feature gate to be enabled.",
|
||||
}
|
||||
|
||||
func (TypedObjectReference) SwaggerDoc() map[string]string {
|
||||
return map_TypedObjectReference
|
||||
}
|
||||
|
||||
var map_Volume = map[string]string{
|
||||
"": "Volume represents a named volume in a pod that may be accessed by any container in the pod.",
|
||||
"name": "name of the volume. Must be a DNS_LABEL and unique within the pod. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names",
|
||||
|
||||
120
vendor/k8s.io/api/core/v1/zz_generated.deepcopy.go
generated
vendored
120
vendor/k8s.io/api/core/v1/zz_generated.deepcopy.go
generated
vendored
@@ -419,6 +419,32 @@ func (in *CinderVolumeSource) DeepCopy() *CinderVolumeSource {
|
||||
return out
|
||||
}
|
||||
|
||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||
func (in *ClaimSource) DeepCopyInto(out *ClaimSource) {
|
||||
*out = *in
|
||||
if in.ResourceClaimName != nil {
|
||||
in, out := &in.ResourceClaimName, &out.ResourceClaimName
|
||||
*out = new(string)
|
||||
**out = **in
|
||||
}
|
||||
if in.ResourceClaimTemplateName != nil {
|
||||
in, out := &in.ResourceClaimTemplateName, &out.ResourceClaimTemplateName
|
||||
*out = new(string)
|
||||
**out = **in
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ClaimSource.
|
||||
func (in *ClaimSource) DeepCopy() *ClaimSource {
|
||||
if in == nil {
|
||||
return nil
|
||||
}
|
||||
out := new(ClaimSource)
|
||||
in.DeepCopyInto(out)
|
||||
return out
|
||||
}
|
||||
|
||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||
func (in *ClientIPConfig) DeepCopyInto(out *ClientIPConfig) {
|
||||
*out = *in
|
||||
@@ -2963,7 +2989,7 @@ func (in *PersistentVolumeClaimSpec) DeepCopyInto(out *PersistentVolumeClaimSpec
|
||||
}
|
||||
if in.DataSourceRef != nil {
|
||||
in, out := &in.DataSourceRef, &out.DataSourceRef
|
||||
*out = new(TypedLocalObjectReference)
|
||||
*out = new(TypedObjectReference)
|
||||
(*in).DeepCopyInto(*out)
|
||||
}
|
||||
return
|
||||
@@ -3726,6 +3752,39 @@ func (in *PodReadinessGate) DeepCopy() *PodReadinessGate {
|
||||
return out
|
||||
}
|
||||
|
||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||
func (in *PodResourceClaim) DeepCopyInto(out *PodResourceClaim) {
|
||||
*out = *in
|
||||
in.Source.DeepCopyInto(&out.Source)
|
||||
return
|
||||
}
|
||||
|
||||
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PodResourceClaim.
|
||||
func (in *PodResourceClaim) DeepCopy() *PodResourceClaim {
|
||||
if in == nil {
|
||||
return nil
|
||||
}
|
||||
out := new(PodResourceClaim)
|
||||
in.DeepCopyInto(out)
|
||||
return out
|
||||
}
|
||||
|
||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||
func (in *PodSchedulingGate) DeepCopyInto(out *PodSchedulingGate) {
|
||||
*out = *in
|
||||
return
|
||||
}
|
||||
|
||||
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PodSchedulingGate.
|
||||
func (in *PodSchedulingGate) DeepCopy() *PodSchedulingGate {
|
||||
if in == nil {
|
||||
return nil
|
||||
}
|
||||
out := new(PodSchedulingGate)
|
||||
in.DeepCopyInto(out)
|
||||
return out
|
||||
}
|
||||
|
||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||
func (in *PodSecurityContext) DeepCopyInto(out *PodSecurityContext) {
|
||||
*out = *in
|
||||
@@ -3959,6 +4018,18 @@ func (in *PodSpec) DeepCopyInto(out *PodSpec) {
|
||||
*out = new(bool)
|
||||
**out = **in
|
||||
}
|
||||
if in.SchedulingGates != nil {
|
||||
in, out := &in.SchedulingGates, &out.SchedulingGates
|
||||
*out = make([]PodSchedulingGate, len(*in))
|
||||
copy(*out, *in)
|
||||
}
|
||||
if in.ResourceClaims != nil {
|
||||
in, out := &in.ResourceClaims, &out.ResourceClaims
|
||||
*out = make([]PodResourceClaim, len(*in))
|
||||
for i := range *in {
|
||||
(*in)[i].DeepCopyInto(&(*out)[i])
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
@@ -4542,6 +4613,22 @@ func (in *ReplicationControllerStatus) DeepCopy() *ReplicationControllerStatus {
|
||||
return out
|
||||
}
|
||||
|
||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||
func (in *ResourceClaim) DeepCopyInto(out *ResourceClaim) {
|
||||
*out = *in
|
||||
return
|
||||
}
|
||||
|
||||
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ResourceClaim.
|
||||
func (in *ResourceClaim) DeepCopy() *ResourceClaim {
|
||||
if in == nil {
|
||||
return nil
|
||||
}
|
||||
out := new(ResourceClaim)
|
||||
in.DeepCopyInto(out)
|
||||
return out
|
||||
}
|
||||
|
||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||
func (in *ResourceFieldSelector) DeepCopyInto(out *ResourceFieldSelector) {
|
||||
*out = *in
|
||||
@@ -4722,6 +4809,11 @@ func (in *ResourceRequirements) DeepCopyInto(out *ResourceRequirements) {
|
||||
(*out)[key] = val.DeepCopy()
|
||||
}
|
||||
}
|
||||
if in.Claims != nil {
|
||||
in, out := &in.Claims, &out.Claims
|
||||
*out = make([]ResourceClaim, len(*in))
|
||||
copy(*out, *in)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
@@ -5708,6 +5800,32 @@ func (in *TypedLocalObjectReference) DeepCopy() *TypedLocalObjectReference {
|
||||
return out
|
||||
}
|
||||
|
||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||
func (in *TypedObjectReference) DeepCopyInto(out *TypedObjectReference) {
|
||||
*out = *in
|
||||
if in.APIGroup != nil {
|
||||
in, out := &in.APIGroup, &out.APIGroup
|
||||
*out = new(string)
|
||||
**out = **in
|
||||
}
|
||||
if in.Namespace != nil {
|
||||
in, out := &in.Namespace, &out.Namespace
|
||||
*out = new(string)
|
||||
**out = **in
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TypedObjectReference.
|
||||
func (in *TypedObjectReference) DeepCopy() *TypedObjectReference {
|
||||
if in == nil {
|
||||
return nil
|
||||
}
|
||||
out := new(TypedObjectReference)
|
||||
in.DeepCopyInto(out)
|
||||
return out
|
||||
}
|
||||
|
||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||
func (in *Volume) DeepCopyInto(out *Volume) {
|
||||
*out = *in
|
||||
|
||||
35
vendor/k8s.io/apimachinery/pkg/api/meta/errors.go
generated
vendored
35
vendor/k8s.io/apimachinery/pkg/api/meta/errors.go
generated
vendored
@@ -17,6 +17,7 @@ limitations under the License.
|
||||
package meta
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||
@@ -43,6 +44,11 @@ func (e *AmbiguousResourceError) Error() string {
|
||||
return fmt.Sprintf("%v matches multiple resources or kinds", e.PartialResource)
|
||||
}
|
||||
|
||||
func (*AmbiguousResourceError) Is(target error) bool {
|
||||
_, ok := target.(*AmbiguousResourceError)
|
||||
return ok
|
||||
}
|
||||
|
||||
// AmbiguousKindError is returned if the RESTMapper finds multiple matches for a kind
|
||||
type AmbiguousKindError struct {
|
||||
PartialKind schema.GroupVersionKind
|
||||
@@ -63,16 +69,16 @@ func (e *AmbiguousKindError) Error() string {
|
||||
return fmt.Sprintf("%v matches multiple resources or kinds", e.PartialKind)
|
||||
}
|
||||
|
||||
func (*AmbiguousKindError) Is(target error) bool {
|
||||
_, ok := target.(*AmbiguousKindError)
|
||||
return ok
|
||||
}
|
||||
|
||||
func IsAmbiguousError(err error) bool {
|
||||
if err == nil {
|
||||
return false
|
||||
}
|
||||
switch err.(type) {
|
||||
case *AmbiguousResourceError, *AmbiguousKindError:
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
return errors.Is(err, &AmbiguousResourceError{}) || errors.Is(err, &AmbiguousKindError{})
|
||||
}
|
||||
|
||||
// NoResourceMatchError is returned if the RESTMapper can't find any match for a resource
|
||||
@@ -84,6 +90,11 @@ func (e *NoResourceMatchError) Error() string {
|
||||
return fmt.Sprintf("no matches for %v", e.PartialResource)
|
||||
}
|
||||
|
||||
func (*NoResourceMatchError) Is(target error) bool {
|
||||
_, ok := target.(*NoResourceMatchError)
|
||||
return ok
|
||||
}
|
||||
|
||||
// NoKindMatchError is returned if the RESTMapper can't find any match for a kind
|
||||
type NoKindMatchError struct {
|
||||
// GroupKind is the API group and kind that was searched
|
||||
@@ -108,14 +119,14 @@ func (e *NoKindMatchError) Error() string {
|
||||
}
|
||||
}
|
||||
|
||||
func (*NoKindMatchError) Is(target error) bool {
|
||||
_, ok := target.(*NoKindMatchError)
|
||||
return ok
|
||||
}
|
||||
|
||||
func IsNoMatchError(err error) bool {
|
||||
if err == nil {
|
||||
return false
|
||||
}
|
||||
switch err.(type) {
|
||||
case *NoResourceMatchError, *NoKindMatchError:
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
return errors.Is(err, &NoResourceMatchError{}) || errors.Is(err, &NoKindMatchError{})
|
||||
}
|
||||
|
||||
2
vendor/k8s.io/apimachinery/pkg/apis/meta/v1/helpers.go
generated
vendored
2
vendor/k8s.io/apimachinery/pkg/apis/meta/v1/helpers.go
generated
vendored
@@ -58,7 +58,7 @@ func LabelSelectorAsSelector(ps *LabelSelector) (labels.Selector, error) {
|
||||
case LabelSelectorOpDoesNotExist:
|
||||
op = selection.DoesNotExist
|
||||
default:
|
||||
return nil, fmt.Errorf("%q is not a valid pod selector operator", expr.Operator)
|
||||
return nil, fmt.Errorf("%q is not a valid label selector operator", expr.Operator)
|
||||
}
|
||||
r, err := labels.NewRequirement(expr.Key, op, append([]string(nil), expr.Values...))
|
||||
if err != nil {
|
||||
|
||||
40
vendor/k8s.io/apimachinery/pkg/apis/meta/v1/validation/validation.go
generated
vendored
40
vendor/k8s.io/apimachinery/pkg/apis/meta/v1/validation/validation.go
generated
vendored
@@ -28,19 +28,46 @@ import (
|
||||
"k8s.io/apimachinery/pkg/util/validation/field"
|
||||
)
|
||||
|
||||
func ValidateLabelSelector(ps *metav1.LabelSelector, fldPath *field.Path) field.ErrorList {
|
||||
// LabelSelectorValidationOptions is a struct that can be passed to ValidateLabelSelector to record the validate options
|
||||
type LabelSelectorValidationOptions struct {
|
||||
// Allow invalid label value in selector
|
||||
AllowInvalidLabelValueInSelector bool
|
||||
}
|
||||
|
||||
// LabelSelectorHasInvalidLabelValue returns true if the given selector contains an invalid label value in a match expression.
|
||||
// This is useful for determining whether AllowInvalidLabelValueInSelector should be set to true when validating an update
|
||||
// based on existing persisted invalid values.
|
||||
func LabelSelectorHasInvalidLabelValue(ps *metav1.LabelSelector) bool {
|
||||
if ps == nil {
|
||||
return false
|
||||
}
|
||||
for _, e := range ps.MatchExpressions {
|
||||
for _, v := range e.Values {
|
||||
if len(validation.IsValidLabelValue(v)) > 0 {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// ValidateLabelSelector validate the LabelSelector according to the opts and returns any validation errors.
|
||||
// opts.AllowInvalidLabelValueInSelector is only expected to be set to true when required for backwards compatibility with existing invalid data.
|
||||
func ValidateLabelSelector(ps *metav1.LabelSelector, opts LabelSelectorValidationOptions, fldPath *field.Path) field.ErrorList {
|
||||
allErrs := field.ErrorList{}
|
||||
if ps == nil {
|
||||
return allErrs
|
||||
}
|
||||
allErrs = append(allErrs, ValidateLabels(ps.MatchLabels, fldPath.Child("matchLabels"))...)
|
||||
for i, expr := range ps.MatchExpressions {
|
||||
allErrs = append(allErrs, ValidateLabelSelectorRequirement(expr, fldPath.Child("matchExpressions").Index(i))...)
|
||||
allErrs = append(allErrs, ValidateLabelSelectorRequirement(expr, opts, fldPath.Child("matchExpressions").Index(i))...)
|
||||
}
|
||||
return allErrs
|
||||
}
|
||||
|
||||
func ValidateLabelSelectorRequirement(sr metav1.LabelSelectorRequirement, fldPath *field.Path) field.ErrorList {
|
||||
// ValidateLabelSelectorRequirement validate the requirement according to the opts and returns any validation errors.
|
||||
// opts.AllowInvalidLabelValueInSelector is only expected to be set to true when required for backwards compatibility with existing invalid data.
|
||||
func ValidateLabelSelectorRequirement(sr metav1.LabelSelectorRequirement, opts LabelSelectorValidationOptions, fldPath *field.Path) field.ErrorList {
|
||||
allErrs := field.ErrorList{}
|
||||
switch sr.Operator {
|
||||
case metav1.LabelSelectorOpIn, metav1.LabelSelectorOpNotIn:
|
||||
@@ -55,6 +82,13 @@ func ValidateLabelSelectorRequirement(sr metav1.LabelSelectorRequirement, fldPat
|
||||
allErrs = append(allErrs, field.Invalid(fldPath.Child("operator"), sr.Operator, "not a valid selector operator"))
|
||||
}
|
||||
allErrs = append(allErrs, ValidateLabelName(sr.Key, fldPath.Child("key"))...)
|
||||
if !opts.AllowInvalidLabelValueInSelector {
|
||||
for valueIndex, value := range sr.Values {
|
||||
for _, msg := range validation.IsValidLabelValue(value) {
|
||||
allErrs = append(allErrs, field.Invalid(fldPath.Child("values").Index(valueIndex), value, msg))
|
||||
}
|
||||
}
|
||||
}
|
||||
return allErrs
|
||||
}
|
||||
|
||||
|
||||
10
vendor/k8s.io/apimachinery/pkg/labels/selector.go
generated
vendored
10
vendor/k8s.io/apimachinery/pkg/labels/selector.go
generated
vendored
@@ -74,9 +74,12 @@ type Selector interface {
|
||||
RequiresExactMatch(label string) (value string, found bool)
|
||||
}
|
||||
|
||||
// Sharing this saves 1 alloc per use; this is safe because it's immutable.
|
||||
var sharedEverythingSelector Selector = internalSelector{}
|
||||
|
||||
// Everything returns a selector that matches all labels.
|
||||
func Everything() Selector {
|
||||
return internalSelector{}
|
||||
return sharedEverythingSelector
|
||||
}
|
||||
|
||||
type nothingSelector struct{}
|
||||
@@ -91,9 +94,12 @@ func (n nothingSelector) RequiresExactMatch(label string) (value string, found b
|
||||
return "", false
|
||||
}
|
||||
|
||||
// Sharing this saves 1 alloc per use; this is safe because it's immutable.
|
||||
var sharedNothingSelector Selector = nothingSelector{}
|
||||
|
||||
// Nothing returns a selector that matches no labels
|
||||
func Nothing() Selector {
|
||||
return nothingSelector{}
|
||||
return sharedNothingSelector
|
||||
}
|
||||
|
||||
// NewSelector returns a nil selector
|
||||
|
||||
12
vendor/k8s.io/apimachinery/pkg/util/httpstream/spdy/roundtripper.go
generated
vendored
12
vendor/k8s.io/apimachinery/pkg/util/httpstream/spdy/roundtripper.go
generated
vendored
@@ -184,12 +184,15 @@ func (s *SpdyRoundTripper) dialWithHttpProxy(req *http.Request, proxyURL *url.UR
|
||||
|
||||
//nolint:staticcheck // SA1019 ignore deprecated httputil.NewProxyClientConn
|
||||
proxyClientConn := httputil.NewProxyClientConn(proxyDialConn, nil)
|
||||
_, err = proxyClientConn.Do(&proxyReq)
|
||||
response, err := proxyClientConn.Do(&proxyReq)
|
||||
//nolint:staticcheck // SA1019 ignore deprecated httputil.ErrPersistEOF: it might be
|
||||
// returned from the invocation of proxyClientConn.Do
|
||||
if err != nil && err != httputil.ErrPersistEOF {
|
||||
return nil, err
|
||||
}
|
||||
if response != nil && response.StatusCode >= 300 || response.StatusCode < 200 {
|
||||
return nil, fmt.Errorf("CONNECT request to %s returned response: %s", proxyURL.Redacted(), response.Status)
|
||||
}
|
||||
|
||||
rwc, _ := proxyClientConn.Hijack()
|
||||
|
||||
@@ -294,9 +297,10 @@ func (s *SpdyRoundTripper) proxyAuth(proxyURL *url.URL) string {
|
||||
if proxyURL == nil || proxyURL.User == nil {
|
||||
return ""
|
||||
}
|
||||
credentials := proxyURL.User.String()
|
||||
encodedAuth := base64.StdEncoding.EncodeToString([]byte(credentials))
|
||||
return fmt.Sprintf("Basic %s", encodedAuth)
|
||||
username := proxyURL.User.Username()
|
||||
password, _ := proxyURL.User.Password()
|
||||
auth := username + ":" + password
|
||||
return "Basic " + base64.StdEncoding.EncodeToString([]byte(auth))
|
||||
}
|
||||
|
||||
// RoundTrip executes the Request and upgrades it. After a successful upgrade,
|
||||
|
||||
4
vendor/k8s.io/apimachinery/pkg/util/remotecommand/constants.go
generated
vendored
4
vendor/k8s.io/apimachinery/pkg/util/remotecommand/constants.go
generated
vendored
@@ -27,8 +27,8 @@ const (
|
||||
|
||||
// The SPDY subprotocol "channel.k8s.io" is used for remote command
|
||||
// attachment/execution. This represents the initial unversioned subprotocol,
|
||||
// which has the known bugs http://issues.k8s.io/13394 and
|
||||
// http://issues.k8s.io/13395.
|
||||
// which has the known bugs https://issues.k8s.io/13394 and
|
||||
// https://issues.k8s.io/13395.
|
||||
StreamProtocolV1Name = "channel.k8s.io"
|
||||
|
||||
// The SPDY subprotocol "v2.channel.k8s.io" is used for remote command
|
||||
|
||||
148
vendor/k8s.io/apimachinery/pkg/util/sets/byte.go
generated
vendored
148
vendor/k8s.io/apimachinery/pkg/util/sets/byte.go
generated
vendored
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright The Kubernetes Authors.
|
||||
Copyright 2022 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.
|
||||
@@ -14,102 +14,75 @@ See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
// Code generated by set-gen. DO NOT EDIT.
|
||||
|
||||
package sets
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"sort"
|
||||
)
|
||||
|
||||
// sets.Byte is a set of bytes, implemented via map[byte]struct{} for minimal memory consumption.
|
||||
// Byte is a set of bytes, implemented via map[byte]struct{} for minimal memory consumption.
|
||||
//
|
||||
// Deprecated: use generic Set instead.
|
||||
// new ways:
|
||||
// s1 := Set[byte]{}
|
||||
// s2 := New[byte]()
|
||||
type Byte map[byte]Empty
|
||||
|
||||
// NewByte creates a Byte from a list of values.
|
||||
func NewByte(items ...byte) Byte {
|
||||
ss := make(Byte, len(items))
|
||||
ss.Insert(items...)
|
||||
return ss
|
||||
return Byte(New[byte](items...))
|
||||
}
|
||||
|
||||
// ByteKeySet creates a Byte from a keys of a map[byte](? extends interface{}).
|
||||
// If the value passed in is not actually a map, this will panic.
|
||||
func ByteKeySet(theMap interface{}) Byte {
|
||||
v := reflect.ValueOf(theMap)
|
||||
ret := Byte{}
|
||||
|
||||
for _, keyValue := range v.MapKeys() {
|
||||
ret.Insert(keyValue.Interface().(byte))
|
||||
}
|
||||
return ret
|
||||
func ByteKeySet[T any](theMap map[byte]T) Byte {
|
||||
return Byte(KeySet(theMap))
|
||||
}
|
||||
|
||||
// Insert adds items to the set.
|
||||
func (s Byte) Insert(items ...byte) Byte {
|
||||
for _, item := range items {
|
||||
s[item] = Empty{}
|
||||
}
|
||||
return s
|
||||
return Byte(cast(s).Insert(items...))
|
||||
}
|
||||
|
||||
// Delete removes all items from the set.
|
||||
func (s Byte) Delete(items ...byte) Byte {
|
||||
for _, item := range items {
|
||||
delete(s, item)
|
||||
}
|
||||
return s
|
||||
return Byte(cast(s).Delete(items...))
|
||||
}
|
||||
|
||||
// Has returns true if and only if item is contained in the set.
|
||||
func (s Byte) Has(item byte) bool {
|
||||
_, contained := s[item]
|
||||
return contained
|
||||
return cast(s).Has(item)
|
||||
}
|
||||
|
||||
// HasAll returns true if and only if all items are contained in the set.
|
||||
func (s Byte) HasAll(items ...byte) bool {
|
||||
for _, item := range items {
|
||||
if !s.Has(item) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
return cast(s).HasAll(items...)
|
||||
}
|
||||
|
||||
// HasAny returns true if any items are contained in the set.
|
||||
func (s Byte) HasAny(items ...byte) bool {
|
||||
for _, item := range items {
|
||||
if s.Has(item) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
return cast(s).HasAny(items...)
|
||||
}
|
||||
|
||||
// Clone returns a new set which is a copy of the current set.
|
||||
func (s Byte) Clone() Byte {
|
||||
result := make(Byte, len(s))
|
||||
for key := range s {
|
||||
result.Insert(key)
|
||||
}
|
||||
return result
|
||||
return Byte(cast(s).Clone())
|
||||
}
|
||||
|
||||
// Difference returns a set of objects that are not in s2
|
||||
// Difference returns a set of objects that are not in s2.
|
||||
// For example:
|
||||
// s1 = {a1, a2, a3}
|
||||
// s2 = {a1, a2, a4, a5}
|
||||
// s1.Difference(s2) = {a3}
|
||||
// s2.Difference(s1) = {a4, a5}
|
||||
func (s Byte) Difference(s2 Byte) Byte {
|
||||
result := NewByte()
|
||||
for key := range s {
|
||||
if !s2.Has(key) {
|
||||
result.Insert(key)
|
||||
}
|
||||
}
|
||||
return result
|
||||
func (s1 Byte) Difference(s2 Byte) Byte {
|
||||
return Byte(cast(s1).Difference(cast(s2)))
|
||||
}
|
||||
|
||||
// SymmetricDifference returns a set of elements which are in either of the sets, but not in their intersection.
|
||||
// For example:
|
||||
// s1 = {a1, a2, a3}
|
||||
// s2 = {a1, a2, a4, a5}
|
||||
// s1.SymmetricDifference(s2) = {a3, a4, a5}
|
||||
// s2.SymmetricDifference(s1) = {a3, a4, a5}
|
||||
func (s1 Byte) SymmetricDifference(s2 Byte) Byte {
|
||||
return Byte(cast(s1).SymmetricDifference(cast(s2)))
|
||||
}
|
||||
|
||||
// Union returns a new set which includes items in either s1 or s2.
|
||||
@@ -119,11 +92,7 @@ func (s Byte) Difference(s2 Byte) Byte {
|
||||
// s1.Union(s2) = {a1, a2, a3, a4}
|
||||
// s2.Union(s1) = {a1, a2, a3, a4}
|
||||
func (s1 Byte) Union(s2 Byte) Byte {
|
||||
result := s1.Clone()
|
||||
for key := range s2 {
|
||||
result.Insert(key)
|
||||
}
|
||||
return result
|
||||
return Byte(cast(s1).Union(cast(s2)))
|
||||
}
|
||||
|
||||
// Intersection returns a new set which includes the item in BOTH s1 and s2
|
||||
@@ -132,80 +101,37 @@ func (s1 Byte) Union(s2 Byte) Byte {
|
||||
// s2 = {a2, a3}
|
||||
// s1.Intersection(s2) = {a2}
|
||||
func (s1 Byte) Intersection(s2 Byte) Byte {
|
||||
var walk, other Byte
|
||||
result := NewByte()
|
||||
if s1.Len() < s2.Len() {
|
||||
walk = s1
|
||||
other = s2
|
||||
} else {
|
||||
walk = s2
|
||||
other = s1
|
||||
}
|
||||
for key := range walk {
|
||||
if other.Has(key) {
|
||||
result.Insert(key)
|
||||
}
|
||||
}
|
||||
return result
|
||||
return Byte(cast(s1).Intersection(cast(s2)))
|
||||
}
|
||||
|
||||
// IsSuperset returns true if and only if s1 is a superset of s2.
|
||||
func (s1 Byte) IsSuperset(s2 Byte) bool {
|
||||
for item := range s2 {
|
||||
if !s1.Has(item) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
return cast(s1).IsSuperset(cast(s2))
|
||||
}
|
||||
|
||||
// Equal returns true if and only if s1 is equal (as a set) to s2.
|
||||
// Two sets are equal if their membership is identical.
|
||||
// (In practice, this means same elements, order doesn't matter)
|
||||
func (s1 Byte) Equal(s2 Byte) bool {
|
||||
return len(s1) == len(s2) && s1.IsSuperset(s2)
|
||||
return cast(s1).Equal(cast(s2))
|
||||
}
|
||||
|
||||
type sortableSliceOfByte []byte
|
||||
|
||||
func (s sortableSliceOfByte) Len() int { return len(s) }
|
||||
func (s sortableSliceOfByte) Less(i, j int) bool { return lessByte(s[i], s[j]) }
|
||||
func (s sortableSliceOfByte) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
|
||||
|
||||
// List returns the contents as a sorted byte slice.
|
||||
func (s Byte) List() []byte {
|
||||
res := make(sortableSliceOfByte, 0, len(s))
|
||||
for key := range s {
|
||||
res = append(res, key)
|
||||
}
|
||||
sort.Sort(res)
|
||||
return []byte(res)
|
||||
return List(cast(s))
|
||||
}
|
||||
|
||||
// UnsortedList returns the slice with contents in random order.
|
||||
func (s Byte) UnsortedList() []byte {
|
||||
res := make([]byte, 0, len(s))
|
||||
for key := range s {
|
||||
res = append(res, key)
|
||||
}
|
||||
return res
|
||||
return cast(s).UnsortedList()
|
||||
}
|
||||
|
||||
// Returns a single element from the set.
|
||||
// PopAny returns a single element from the set.
|
||||
func (s Byte) PopAny() (byte, bool) {
|
||||
for key := range s {
|
||||
s.Delete(key)
|
||||
return key, true
|
||||
}
|
||||
var zeroValue byte
|
||||
return zeroValue, false
|
||||
return cast(s).PopAny()
|
||||
}
|
||||
|
||||
// Len returns the size of the set.
|
||||
func (s Byte) Len() int {
|
||||
return len(s)
|
||||
}
|
||||
|
||||
func lessByte(lhs, rhs byte) bool {
|
||||
return lhs < rhs
|
||||
}
|
||||
|
||||
7
vendor/k8s.io/apimachinery/pkg/util/sets/doc.go
generated
vendored
7
vendor/k8s.io/apimachinery/pkg/util/sets/doc.go
generated
vendored
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright The Kubernetes Authors.
|
||||
Copyright 2022 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.
|
||||
@@ -14,7 +14,6 @@ See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
// Code generated by set-gen. DO NOT EDIT.
|
||||
|
||||
// Package sets has auto-generated set types.
|
||||
// Package sets has generic set and specified sets. Generic set will
|
||||
// replace specified ones over time. And specific ones are deprecated.
|
||||
package sets
|
||||
|
||||
4
vendor/k8s.io/apimachinery/pkg/util/sets/empty.go
generated
vendored
4
vendor/k8s.io/apimachinery/pkg/util/sets/empty.go
generated
vendored
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright The Kubernetes Authors.
|
||||
Copyright 2022 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.
|
||||
@@ -14,8 +14,6 @@ See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
// Code generated by set-gen. DO NOT EDIT.
|
||||
|
||||
package sets
|
||||
|
||||
// Empty is public since it is used by some internal API objects for conversions between external
|
||||
|
||||
148
vendor/k8s.io/apimachinery/pkg/util/sets/int.go
generated
vendored
148
vendor/k8s.io/apimachinery/pkg/util/sets/int.go
generated
vendored
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright The Kubernetes Authors.
|
||||
Copyright 2022 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.
|
||||
@@ -14,102 +14,75 @@ See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
// Code generated by set-gen. DO NOT EDIT.
|
||||
|
||||
package sets
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"sort"
|
||||
)
|
||||
|
||||
// sets.Int is a set of ints, implemented via map[int]struct{} for minimal memory consumption.
|
||||
// Int is a set of ints, implemented via map[int]struct{} for minimal memory consumption.
|
||||
//
|
||||
// Deprecated: use generic Set instead.
|
||||
// new ways:
|
||||
// s1 := Set[int]{}
|
||||
// s2 := New[int]()
|
||||
type Int map[int]Empty
|
||||
|
||||
// NewInt creates a Int from a list of values.
|
||||
func NewInt(items ...int) Int {
|
||||
ss := make(Int, len(items))
|
||||
ss.Insert(items...)
|
||||
return ss
|
||||
return Int(New[int](items...))
|
||||
}
|
||||
|
||||
// IntKeySet creates a Int from a keys of a map[int](? extends interface{}).
|
||||
// If the value passed in is not actually a map, this will panic.
|
||||
func IntKeySet(theMap interface{}) Int {
|
||||
v := reflect.ValueOf(theMap)
|
||||
ret := Int{}
|
||||
|
||||
for _, keyValue := range v.MapKeys() {
|
||||
ret.Insert(keyValue.Interface().(int))
|
||||
}
|
||||
return ret
|
||||
func IntKeySet[T any](theMap map[int]T) Int {
|
||||
return Int(KeySet(theMap))
|
||||
}
|
||||
|
||||
// Insert adds items to the set.
|
||||
func (s Int) Insert(items ...int) Int {
|
||||
for _, item := range items {
|
||||
s[item] = Empty{}
|
||||
}
|
||||
return s
|
||||
return Int(cast(s).Insert(items...))
|
||||
}
|
||||
|
||||
// Delete removes all items from the set.
|
||||
func (s Int) Delete(items ...int) Int {
|
||||
for _, item := range items {
|
||||
delete(s, item)
|
||||
}
|
||||
return s
|
||||
return Int(cast(s).Delete(items...))
|
||||
}
|
||||
|
||||
// Has returns true if and only if item is contained in the set.
|
||||
func (s Int) Has(item int) bool {
|
||||
_, contained := s[item]
|
||||
return contained
|
||||
return cast(s).Has(item)
|
||||
}
|
||||
|
||||
// HasAll returns true if and only if all items are contained in the set.
|
||||
func (s Int) HasAll(items ...int) bool {
|
||||
for _, item := range items {
|
||||
if !s.Has(item) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
return cast(s).HasAll(items...)
|
||||
}
|
||||
|
||||
// HasAny returns true if any items are contained in the set.
|
||||
func (s Int) HasAny(items ...int) bool {
|
||||
for _, item := range items {
|
||||
if s.Has(item) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
return cast(s).HasAny(items...)
|
||||
}
|
||||
|
||||
// Clone returns a new set which is a copy of the current set.
|
||||
func (s Int) Clone() Int {
|
||||
result := make(Int, len(s))
|
||||
for key := range s {
|
||||
result.Insert(key)
|
||||
}
|
||||
return result
|
||||
return Int(cast(s).Clone())
|
||||
}
|
||||
|
||||
// Difference returns a set of objects that are not in s2
|
||||
// Difference returns a set of objects that are not in s2.
|
||||
// For example:
|
||||
// s1 = {a1, a2, a3}
|
||||
// s2 = {a1, a2, a4, a5}
|
||||
// s1.Difference(s2) = {a3}
|
||||
// s2.Difference(s1) = {a4, a5}
|
||||
func (s Int) Difference(s2 Int) Int {
|
||||
result := NewInt()
|
||||
for key := range s {
|
||||
if !s2.Has(key) {
|
||||
result.Insert(key)
|
||||
}
|
||||
}
|
||||
return result
|
||||
func (s1 Int) Difference(s2 Int) Int {
|
||||
return Int(cast(s1).Difference(cast(s2)))
|
||||
}
|
||||
|
||||
// SymmetricDifference returns a set of elements which are in either of the sets, but not in their intersection.
|
||||
// For example:
|
||||
// s1 = {a1, a2, a3}
|
||||
// s2 = {a1, a2, a4, a5}
|
||||
// s1.SymmetricDifference(s2) = {a3, a4, a5}
|
||||
// s2.SymmetricDifference(s1) = {a3, a4, a5}
|
||||
func (s1 Int) SymmetricDifference(s2 Int) Int {
|
||||
return Int(cast(s1).SymmetricDifference(cast(s2)))
|
||||
}
|
||||
|
||||
// Union returns a new set which includes items in either s1 or s2.
|
||||
@@ -119,11 +92,7 @@ func (s Int) Difference(s2 Int) Int {
|
||||
// s1.Union(s2) = {a1, a2, a3, a4}
|
||||
// s2.Union(s1) = {a1, a2, a3, a4}
|
||||
func (s1 Int) Union(s2 Int) Int {
|
||||
result := s1.Clone()
|
||||
for key := range s2 {
|
||||
result.Insert(key)
|
||||
}
|
||||
return result
|
||||
return Int(cast(s1).Union(cast(s2)))
|
||||
}
|
||||
|
||||
// Intersection returns a new set which includes the item in BOTH s1 and s2
|
||||
@@ -132,80 +101,37 @@ func (s1 Int) Union(s2 Int) Int {
|
||||
// s2 = {a2, a3}
|
||||
// s1.Intersection(s2) = {a2}
|
||||
func (s1 Int) Intersection(s2 Int) Int {
|
||||
var walk, other Int
|
||||
result := NewInt()
|
||||
if s1.Len() < s2.Len() {
|
||||
walk = s1
|
||||
other = s2
|
||||
} else {
|
||||
walk = s2
|
||||
other = s1
|
||||
}
|
||||
for key := range walk {
|
||||
if other.Has(key) {
|
||||
result.Insert(key)
|
||||
}
|
||||
}
|
||||
return result
|
||||
return Int(cast(s1).Intersection(cast(s2)))
|
||||
}
|
||||
|
||||
// IsSuperset returns true if and only if s1 is a superset of s2.
|
||||
func (s1 Int) IsSuperset(s2 Int) bool {
|
||||
for item := range s2 {
|
||||
if !s1.Has(item) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
return cast(s1).IsSuperset(cast(s2))
|
||||
}
|
||||
|
||||
// Equal returns true if and only if s1 is equal (as a set) to s2.
|
||||
// Two sets are equal if their membership is identical.
|
||||
// (In practice, this means same elements, order doesn't matter)
|
||||
func (s1 Int) Equal(s2 Int) bool {
|
||||
return len(s1) == len(s2) && s1.IsSuperset(s2)
|
||||
return cast(s1).Equal(cast(s2))
|
||||
}
|
||||
|
||||
type sortableSliceOfInt []int
|
||||
|
||||
func (s sortableSliceOfInt) Len() int { return len(s) }
|
||||
func (s sortableSliceOfInt) Less(i, j int) bool { return lessInt(s[i], s[j]) }
|
||||
func (s sortableSliceOfInt) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
|
||||
|
||||
// List returns the contents as a sorted int slice.
|
||||
func (s Int) List() []int {
|
||||
res := make(sortableSliceOfInt, 0, len(s))
|
||||
for key := range s {
|
||||
res = append(res, key)
|
||||
}
|
||||
sort.Sort(res)
|
||||
return []int(res)
|
||||
return List(cast(s))
|
||||
}
|
||||
|
||||
// UnsortedList returns the slice with contents in random order.
|
||||
func (s Int) UnsortedList() []int {
|
||||
res := make([]int, 0, len(s))
|
||||
for key := range s {
|
||||
res = append(res, key)
|
||||
}
|
||||
return res
|
||||
return cast(s).UnsortedList()
|
||||
}
|
||||
|
||||
// Returns a single element from the set.
|
||||
// PopAny returns a single element from the set.
|
||||
func (s Int) PopAny() (int, bool) {
|
||||
for key := range s {
|
||||
s.Delete(key)
|
||||
return key, true
|
||||
}
|
||||
var zeroValue int
|
||||
return zeroValue, false
|
||||
return cast(s).PopAny()
|
||||
}
|
||||
|
||||
// Len returns the size of the set.
|
||||
func (s Int) Len() int {
|
||||
return len(s)
|
||||
}
|
||||
|
||||
func lessInt(lhs, rhs int) bool {
|
||||
return lhs < rhs
|
||||
}
|
||||
|
||||
148
vendor/k8s.io/apimachinery/pkg/util/sets/int32.go
generated
vendored
148
vendor/k8s.io/apimachinery/pkg/util/sets/int32.go
generated
vendored
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright The Kubernetes Authors.
|
||||
Copyright 2022 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.
|
||||
@@ -14,102 +14,75 @@ See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
// Code generated by set-gen. DO NOT EDIT.
|
||||
|
||||
package sets
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"sort"
|
||||
)
|
||||
|
||||
// sets.Int32 is a set of int32s, implemented via map[int32]struct{} for minimal memory consumption.
|
||||
// Int32 is a set of int32s, implemented via map[int32]struct{} for minimal memory consumption.
|
||||
//
|
||||
// Deprecated: use generic Set instead.
|
||||
// new ways:
|
||||
// s1 := Set[int32]{}
|
||||
// s2 := New[int32]()
|
||||
type Int32 map[int32]Empty
|
||||
|
||||
// NewInt32 creates a Int32 from a list of values.
|
||||
func NewInt32(items ...int32) Int32 {
|
||||
ss := make(Int32, len(items))
|
||||
ss.Insert(items...)
|
||||
return ss
|
||||
return Int32(New[int32](items...))
|
||||
}
|
||||
|
||||
// Int32KeySet creates a Int32 from a keys of a map[int32](? extends interface{}).
|
||||
// If the value passed in is not actually a map, this will panic.
|
||||
func Int32KeySet(theMap interface{}) Int32 {
|
||||
v := reflect.ValueOf(theMap)
|
||||
ret := Int32{}
|
||||
|
||||
for _, keyValue := range v.MapKeys() {
|
||||
ret.Insert(keyValue.Interface().(int32))
|
||||
}
|
||||
return ret
|
||||
func Int32KeySet[T any](theMap map[int32]T) Int32 {
|
||||
return Int32(KeySet(theMap))
|
||||
}
|
||||
|
||||
// Insert adds items to the set.
|
||||
func (s Int32) Insert(items ...int32) Int32 {
|
||||
for _, item := range items {
|
||||
s[item] = Empty{}
|
||||
}
|
||||
return s
|
||||
return Int32(cast(s).Insert(items...))
|
||||
}
|
||||
|
||||
// Delete removes all items from the set.
|
||||
func (s Int32) Delete(items ...int32) Int32 {
|
||||
for _, item := range items {
|
||||
delete(s, item)
|
||||
}
|
||||
return s
|
||||
return Int32(cast(s).Delete(items...))
|
||||
}
|
||||
|
||||
// Has returns true if and only if item is contained in the set.
|
||||
func (s Int32) Has(item int32) bool {
|
||||
_, contained := s[item]
|
||||
return contained
|
||||
return cast(s).Has(item)
|
||||
}
|
||||
|
||||
// HasAll returns true if and only if all items are contained in the set.
|
||||
func (s Int32) HasAll(items ...int32) bool {
|
||||
for _, item := range items {
|
||||
if !s.Has(item) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
return cast(s).HasAll(items...)
|
||||
}
|
||||
|
||||
// HasAny returns true if any items are contained in the set.
|
||||
func (s Int32) HasAny(items ...int32) bool {
|
||||
for _, item := range items {
|
||||
if s.Has(item) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
return cast(s).HasAny(items...)
|
||||
}
|
||||
|
||||
// Clone returns a new set which is a copy of the current set.
|
||||
func (s Int32) Clone() Int32 {
|
||||
result := make(Int32, len(s))
|
||||
for key := range s {
|
||||
result.Insert(key)
|
||||
}
|
||||
return result
|
||||
return Int32(cast(s).Clone())
|
||||
}
|
||||
|
||||
// Difference returns a set of objects that are not in s2
|
||||
// Difference returns a set of objects that are not in s2.
|
||||
// For example:
|
||||
// s1 = {a1, a2, a3}
|
||||
// s2 = {a1, a2, a4, a5}
|
||||
// s1.Difference(s2) = {a3}
|
||||
// s2.Difference(s1) = {a4, a5}
|
||||
func (s Int32) Difference(s2 Int32) Int32 {
|
||||
result := NewInt32()
|
||||
for key := range s {
|
||||
if !s2.Has(key) {
|
||||
result.Insert(key)
|
||||
}
|
||||
}
|
||||
return result
|
||||
func (s1 Int32) Difference(s2 Int32) Int32 {
|
||||
return Int32(cast(s1).Difference(cast(s2)))
|
||||
}
|
||||
|
||||
// SymmetricDifference returns a set of elements which are in either of the sets, but not in their intersection.
|
||||
// For example:
|
||||
// s1 = {a1, a2, a3}
|
||||
// s2 = {a1, a2, a4, a5}
|
||||
// s1.SymmetricDifference(s2) = {a3, a4, a5}
|
||||
// s2.SymmetricDifference(s1) = {a3, a4, a5}
|
||||
func (s1 Int32) SymmetricDifference(s2 Int32) Int32 {
|
||||
return Int32(cast(s1).SymmetricDifference(cast(s2)))
|
||||
}
|
||||
|
||||
// Union returns a new set which includes items in either s1 or s2.
|
||||
@@ -119,11 +92,7 @@ func (s Int32) Difference(s2 Int32) Int32 {
|
||||
// s1.Union(s2) = {a1, a2, a3, a4}
|
||||
// s2.Union(s1) = {a1, a2, a3, a4}
|
||||
func (s1 Int32) Union(s2 Int32) Int32 {
|
||||
result := s1.Clone()
|
||||
for key := range s2 {
|
||||
result.Insert(key)
|
||||
}
|
||||
return result
|
||||
return Int32(cast(s1).Union(cast(s2)))
|
||||
}
|
||||
|
||||
// Intersection returns a new set which includes the item in BOTH s1 and s2
|
||||
@@ -132,80 +101,37 @@ func (s1 Int32) Union(s2 Int32) Int32 {
|
||||
// s2 = {a2, a3}
|
||||
// s1.Intersection(s2) = {a2}
|
||||
func (s1 Int32) Intersection(s2 Int32) Int32 {
|
||||
var walk, other Int32
|
||||
result := NewInt32()
|
||||
if s1.Len() < s2.Len() {
|
||||
walk = s1
|
||||
other = s2
|
||||
} else {
|
||||
walk = s2
|
||||
other = s1
|
||||
}
|
||||
for key := range walk {
|
||||
if other.Has(key) {
|
||||
result.Insert(key)
|
||||
}
|
||||
}
|
||||
return result
|
||||
return Int32(cast(s1).Intersection(cast(s2)))
|
||||
}
|
||||
|
||||
// IsSuperset returns true if and only if s1 is a superset of s2.
|
||||
func (s1 Int32) IsSuperset(s2 Int32) bool {
|
||||
for item := range s2 {
|
||||
if !s1.Has(item) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
return cast(s1).IsSuperset(cast(s2))
|
||||
}
|
||||
|
||||
// Equal returns true if and only if s1 is equal (as a set) to s2.
|
||||
// Two sets are equal if their membership is identical.
|
||||
// (In practice, this means same elements, order doesn't matter)
|
||||
func (s1 Int32) Equal(s2 Int32) bool {
|
||||
return len(s1) == len(s2) && s1.IsSuperset(s2)
|
||||
return cast(s1).Equal(cast(s2))
|
||||
}
|
||||
|
||||
type sortableSliceOfInt32 []int32
|
||||
|
||||
func (s sortableSliceOfInt32) Len() int { return len(s) }
|
||||
func (s sortableSliceOfInt32) Less(i, j int) bool { return lessInt32(s[i], s[j]) }
|
||||
func (s sortableSliceOfInt32) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
|
||||
|
||||
// List returns the contents as a sorted int32 slice.
|
||||
func (s Int32) List() []int32 {
|
||||
res := make(sortableSliceOfInt32, 0, len(s))
|
||||
for key := range s {
|
||||
res = append(res, key)
|
||||
}
|
||||
sort.Sort(res)
|
||||
return []int32(res)
|
||||
return List(cast(s))
|
||||
}
|
||||
|
||||
// UnsortedList returns the slice with contents in random order.
|
||||
func (s Int32) UnsortedList() []int32 {
|
||||
res := make([]int32, 0, len(s))
|
||||
for key := range s {
|
||||
res = append(res, key)
|
||||
}
|
||||
return res
|
||||
return cast(s).UnsortedList()
|
||||
}
|
||||
|
||||
// Returns a single element from the set.
|
||||
// PopAny returns a single element from the set.
|
||||
func (s Int32) PopAny() (int32, bool) {
|
||||
for key := range s {
|
||||
s.Delete(key)
|
||||
return key, true
|
||||
}
|
||||
var zeroValue int32
|
||||
return zeroValue, false
|
||||
return cast(s).PopAny()
|
||||
}
|
||||
|
||||
// Len returns the size of the set.
|
||||
func (s Int32) Len() int {
|
||||
return len(s)
|
||||
}
|
||||
|
||||
func lessInt32(lhs, rhs int32) bool {
|
||||
return lhs < rhs
|
||||
}
|
||||
|
||||
148
vendor/k8s.io/apimachinery/pkg/util/sets/int64.go
generated
vendored
148
vendor/k8s.io/apimachinery/pkg/util/sets/int64.go
generated
vendored
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright The Kubernetes Authors.
|
||||
Copyright 2022 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.
|
||||
@@ -14,102 +14,75 @@ See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
// Code generated by set-gen. DO NOT EDIT.
|
||||
|
||||
package sets
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"sort"
|
||||
)
|
||||
|
||||
// sets.Int64 is a set of int64s, implemented via map[int64]struct{} for minimal memory consumption.
|
||||
// Int64 is a set of int64s, implemented via map[int64]struct{} for minimal memory consumption.
|
||||
//
|
||||
// Deprecated: use generic Set instead.
|
||||
// new ways:
|
||||
// s1 := Set[int64]{}
|
||||
// s2 := New[int64]()
|
||||
type Int64 map[int64]Empty
|
||||
|
||||
// NewInt64 creates a Int64 from a list of values.
|
||||
func NewInt64(items ...int64) Int64 {
|
||||
ss := make(Int64, len(items))
|
||||
ss.Insert(items...)
|
||||
return ss
|
||||
return Int64(New[int64](items...))
|
||||
}
|
||||
|
||||
// Int64KeySet creates a Int64 from a keys of a map[int64](? extends interface{}).
|
||||
// If the value passed in is not actually a map, this will panic.
|
||||
func Int64KeySet(theMap interface{}) Int64 {
|
||||
v := reflect.ValueOf(theMap)
|
||||
ret := Int64{}
|
||||
|
||||
for _, keyValue := range v.MapKeys() {
|
||||
ret.Insert(keyValue.Interface().(int64))
|
||||
}
|
||||
return ret
|
||||
func Int64KeySet[T any](theMap map[int64]T) Int64 {
|
||||
return Int64(KeySet(theMap))
|
||||
}
|
||||
|
||||
// Insert adds items to the set.
|
||||
func (s Int64) Insert(items ...int64) Int64 {
|
||||
for _, item := range items {
|
||||
s[item] = Empty{}
|
||||
}
|
||||
return s
|
||||
return Int64(cast(s).Insert(items...))
|
||||
}
|
||||
|
||||
// Delete removes all items from the set.
|
||||
func (s Int64) Delete(items ...int64) Int64 {
|
||||
for _, item := range items {
|
||||
delete(s, item)
|
||||
}
|
||||
return s
|
||||
return Int64(cast(s).Delete(items...))
|
||||
}
|
||||
|
||||
// Has returns true if and only if item is contained in the set.
|
||||
func (s Int64) Has(item int64) bool {
|
||||
_, contained := s[item]
|
||||
return contained
|
||||
return cast(s).Has(item)
|
||||
}
|
||||
|
||||
// HasAll returns true if and only if all items are contained in the set.
|
||||
func (s Int64) HasAll(items ...int64) bool {
|
||||
for _, item := range items {
|
||||
if !s.Has(item) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
return cast(s).HasAll(items...)
|
||||
}
|
||||
|
||||
// HasAny returns true if any items are contained in the set.
|
||||
func (s Int64) HasAny(items ...int64) bool {
|
||||
for _, item := range items {
|
||||
if s.Has(item) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
return cast(s).HasAny(items...)
|
||||
}
|
||||
|
||||
// Clone returns a new set which is a copy of the current set.
|
||||
func (s Int64) Clone() Int64 {
|
||||
result := make(Int64, len(s))
|
||||
for key := range s {
|
||||
result.Insert(key)
|
||||
}
|
||||
return result
|
||||
return Int64(cast(s).Clone())
|
||||
}
|
||||
|
||||
// Difference returns a set of objects that are not in s2
|
||||
// Difference returns a set of objects that are not in s2.
|
||||
// For example:
|
||||
// s1 = {a1, a2, a3}
|
||||
// s2 = {a1, a2, a4, a5}
|
||||
// s1.Difference(s2) = {a3}
|
||||
// s2.Difference(s1) = {a4, a5}
|
||||
func (s Int64) Difference(s2 Int64) Int64 {
|
||||
result := NewInt64()
|
||||
for key := range s {
|
||||
if !s2.Has(key) {
|
||||
result.Insert(key)
|
||||
}
|
||||
}
|
||||
return result
|
||||
func (s1 Int64) Difference(s2 Int64) Int64 {
|
||||
return Int64(cast(s1).Difference(cast(s2)))
|
||||
}
|
||||
|
||||
// SymmetricDifference returns a set of elements which are in either of the sets, but not in their intersection.
|
||||
// For example:
|
||||
// s1 = {a1, a2, a3}
|
||||
// s2 = {a1, a2, a4, a5}
|
||||
// s1.SymmetricDifference(s2) = {a3, a4, a5}
|
||||
// s2.SymmetricDifference(s1) = {a3, a4, a5}
|
||||
func (s1 Int64) SymmetricDifference(s2 Int64) Int64 {
|
||||
return Int64(cast(s1).SymmetricDifference(cast(s2)))
|
||||
}
|
||||
|
||||
// Union returns a new set which includes items in either s1 or s2.
|
||||
@@ -119,11 +92,7 @@ func (s Int64) Difference(s2 Int64) Int64 {
|
||||
// s1.Union(s2) = {a1, a2, a3, a4}
|
||||
// s2.Union(s1) = {a1, a2, a3, a4}
|
||||
func (s1 Int64) Union(s2 Int64) Int64 {
|
||||
result := s1.Clone()
|
||||
for key := range s2 {
|
||||
result.Insert(key)
|
||||
}
|
||||
return result
|
||||
return Int64(cast(s1).Union(cast(s2)))
|
||||
}
|
||||
|
||||
// Intersection returns a new set which includes the item in BOTH s1 and s2
|
||||
@@ -132,80 +101,37 @@ func (s1 Int64) Union(s2 Int64) Int64 {
|
||||
// s2 = {a2, a3}
|
||||
// s1.Intersection(s2) = {a2}
|
||||
func (s1 Int64) Intersection(s2 Int64) Int64 {
|
||||
var walk, other Int64
|
||||
result := NewInt64()
|
||||
if s1.Len() < s2.Len() {
|
||||
walk = s1
|
||||
other = s2
|
||||
} else {
|
||||
walk = s2
|
||||
other = s1
|
||||
}
|
||||
for key := range walk {
|
||||
if other.Has(key) {
|
||||
result.Insert(key)
|
||||
}
|
||||
}
|
||||
return result
|
||||
return Int64(cast(s1).Intersection(cast(s2)))
|
||||
}
|
||||
|
||||
// IsSuperset returns true if and only if s1 is a superset of s2.
|
||||
func (s1 Int64) IsSuperset(s2 Int64) bool {
|
||||
for item := range s2 {
|
||||
if !s1.Has(item) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
return cast(s1).IsSuperset(cast(s2))
|
||||
}
|
||||
|
||||
// Equal returns true if and only if s1 is equal (as a set) to s2.
|
||||
// Two sets are equal if their membership is identical.
|
||||
// (In practice, this means same elements, order doesn't matter)
|
||||
func (s1 Int64) Equal(s2 Int64) bool {
|
||||
return len(s1) == len(s2) && s1.IsSuperset(s2)
|
||||
return cast(s1).Equal(cast(s2))
|
||||
}
|
||||
|
||||
type sortableSliceOfInt64 []int64
|
||||
|
||||
func (s sortableSliceOfInt64) Len() int { return len(s) }
|
||||
func (s sortableSliceOfInt64) Less(i, j int) bool { return lessInt64(s[i], s[j]) }
|
||||
func (s sortableSliceOfInt64) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
|
||||
|
||||
// List returns the contents as a sorted int64 slice.
|
||||
func (s Int64) List() []int64 {
|
||||
res := make(sortableSliceOfInt64, 0, len(s))
|
||||
for key := range s {
|
||||
res = append(res, key)
|
||||
}
|
||||
sort.Sort(res)
|
||||
return []int64(res)
|
||||
return List(cast(s))
|
||||
}
|
||||
|
||||
// UnsortedList returns the slice with contents in random order.
|
||||
func (s Int64) UnsortedList() []int64 {
|
||||
res := make([]int64, 0, len(s))
|
||||
for key := range s {
|
||||
res = append(res, key)
|
||||
}
|
||||
return res
|
||||
return cast(s).UnsortedList()
|
||||
}
|
||||
|
||||
// Returns a single element from the set.
|
||||
// PopAny returns a single element from the set.
|
||||
func (s Int64) PopAny() (int64, bool) {
|
||||
for key := range s {
|
||||
s.Delete(key)
|
||||
return key, true
|
||||
}
|
||||
var zeroValue int64
|
||||
return zeroValue, false
|
||||
return cast(s).PopAny()
|
||||
}
|
||||
|
||||
// Len returns the size of the set.
|
||||
func (s Int64) Len() int {
|
||||
return len(s)
|
||||
}
|
||||
|
||||
func lessInt64(lhs, rhs int64) bool {
|
||||
return lhs < rhs
|
||||
}
|
||||
|
||||
53
vendor/k8s.io/apimachinery/pkg/util/sets/ordered.go
generated
vendored
Normal file
53
vendor/k8s.io/apimachinery/pkg/util/sets/ordered.go
generated
vendored
Normal file
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
Copyright 2022 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 sets
|
||||
|
||||
// ordered is a constraint that permits any ordered type: any type
|
||||
// that supports the operators < <= >= >.
|
||||
// If future releases of Go add new ordered types,
|
||||
// this constraint will be modified to include them.
|
||||
type ordered interface {
|
||||
integer | float | ~string
|
||||
}
|
||||
|
||||
// integer is a constraint that permits any integer type.
|
||||
// If future releases of Go add new predeclared integer types,
|
||||
// this constraint will be modified to include them.
|
||||
type integer interface {
|
||||
signed | unsigned
|
||||
}
|
||||
|
||||
// float is a constraint that permits any floating-point type.
|
||||
// If future releases of Go add new predeclared floating-point types,
|
||||
// this constraint will be modified to include them.
|
||||
type float interface {
|
||||
~float32 | ~float64
|
||||
}
|
||||
|
||||
// signed is a constraint that permits any signed integer type.
|
||||
// If future releases of Go add new predeclared signed integer types,
|
||||
// this constraint will be modified to include them.
|
||||
type signed interface {
|
||||
~int | ~int8 | ~int16 | ~int32 | ~int64
|
||||
}
|
||||
|
||||
// unsigned is a constraint that permits any unsigned integer type.
|
||||
// If future releases of Go add new predeclared unsigned integer types,
|
||||
// this constraint will be modified to include them.
|
||||
type unsigned interface {
|
||||
~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr
|
||||
}
|
||||
227
vendor/k8s.io/apimachinery/pkg/util/sets/set.go
generated
vendored
Normal file
227
vendor/k8s.io/apimachinery/pkg/util/sets/set.go
generated
vendored
Normal file
@@ -0,0 +1,227 @@
|
||||
/*
|
||||
Copyright 2022 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 sets
|
||||
|
||||
import (
|
||||
"sort"
|
||||
)
|
||||
|
||||
// Set is a set of the same type elements, implemented via map[comparable]struct{} for minimal memory consumption.
|
||||
type Set[T comparable] map[T]Empty
|
||||
|
||||
// cast transforms specified set to generic Set[T].
|
||||
func cast[T comparable](s map[T]Empty) Set[T] { return s }
|
||||
|
||||
// New creates a Set from a list of values.
|
||||
// NOTE: type param must be explicitly instantiated if given items are empty.
|
||||
func New[T comparable](items ...T) Set[T] {
|
||||
ss := make(Set[T], len(items))
|
||||
ss.Insert(items...)
|
||||
return ss
|
||||
}
|
||||
|
||||
// KeySet creates a Set from a keys of a map[comparable](? extends interface{}).
|
||||
// If the value passed in is not actually a map, this will panic.
|
||||
func KeySet[T comparable, V any](theMap map[T]V) Set[T] {
|
||||
ret := Set[T]{}
|
||||
for keyValue := range theMap {
|
||||
ret.Insert(keyValue)
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
// Insert adds items to the set.
|
||||
func (s Set[T]) Insert(items ...T) Set[T] {
|
||||
for _, item := range items {
|
||||
s[item] = Empty{}
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
||||
func Insert[T comparable](set Set[T], items ...T) Set[T] {
|
||||
return set.Insert(items...)
|
||||
}
|
||||
|
||||
// Delete removes all items from the set.
|
||||
func (s Set[T]) Delete(items ...T) Set[T] {
|
||||
for _, item := range items {
|
||||
delete(s, item)
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
||||
// Has returns true if and only if item is contained in the set.
|
||||
func (s Set[T]) Has(item T) bool {
|
||||
_, contained := s[item]
|
||||
return contained
|
||||
}
|
||||
|
||||
// HasAll returns true if and only if all items are contained in the set.
|
||||
func (s Set[T]) HasAll(items ...T) bool {
|
||||
for _, item := range items {
|
||||
if !s.Has(item) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// HasAny returns true if any items are contained in the set.
|
||||
func (s Set[T]) HasAny(items ...T) bool {
|
||||
for _, item := range items {
|
||||
if s.Has(item) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// Clone returns a new set which is a copy of the current set.
|
||||
func (s Set[T]) Clone() Set[T] {
|
||||
result := make(Set[T], len(s))
|
||||
for key := range s {
|
||||
result.Insert(key)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// Difference returns a set of objects that are not in s2.
|
||||
// For example:
|
||||
// s1 = {a1, a2, a3}
|
||||
// s2 = {a1, a2, a4, a5}
|
||||
// s1.Difference(s2) = {a3}
|
||||
// s2.Difference(s1) = {a4, a5}
|
||||
func (s1 Set[T]) Difference(s2 Set[T]) Set[T] {
|
||||
result := New[T]()
|
||||
for key := range s1 {
|
||||
if !s2.Has(key) {
|
||||
result.Insert(key)
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// SymmetricDifference returns a set of elements which are in either of the sets, but not in their intersection.
|
||||
// For example:
|
||||
// s1 = {a1, a2, a3}
|
||||
// s2 = {a1, a2, a4, a5}
|
||||
// s1.SymmetricDifference(s2) = {a3, a4, a5}
|
||||
// s2.SymmetricDifference(s1) = {a3, a4, a5}
|
||||
func (s1 Set[T]) SymmetricDifference(s2 Set[T]) Set[T] {
|
||||
return s1.Difference(s2).Union(s2.Difference(s1))
|
||||
}
|
||||
|
||||
// Union returns a new set which includes items in either s1 or s2.
|
||||
// For example:
|
||||
// s1 = {a1, a2}
|
||||
// s2 = {a3, a4}
|
||||
// s1.Union(s2) = {a1, a2, a3, a4}
|
||||
// s2.Union(s1) = {a1, a2, a3, a4}
|
||||
func (s1 Set[T]) Union(s2 Set[T]) Set[T] {
|
||||
result := s1.Clone()
|
||||
for key := range s2 {
|
||||
result.Insert(key)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// Intersection returns a new set which includes the item in BOTH s1 and s2
|
||||
// For example:
|
||||
// s1 = {a1, a2}
|
||||
// s2 = {a2, a3}
|
||||
// s1.Intersection(s2) = {a2}
|
||||
func (s1 Set[T]) Intersection(s2 Set[T]) Set[T] {
|
||||
var walk, other Set[T]
|
||||
result := New[T]()
|
||||
if s1.Len() < s2.Len() {
|
||||
walk = s1
|
||||
other = s2
|
||||
} else {
|
||||
walk = s2
|
||||
other = s1
|
||||
}
|
||||
for key := range walk {
|
||||
if other.Has(key) {
|
||||
result.Insert(key)
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// IsSuperset returns true if and only if s1 is a superset of s2.
|
||||
func (s1 Set[T]) IsSuperset(s2 Set[T]) bool {
|
||||
for item := range s2 {
|
||||
if !s1.Has(item) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// Equal returns true if and only if s1 is equal (as a set) to s2.
|
||||
// Two sets are equal if their membership is identical.
|
||||
// (In practice, this means same elements, order doesn't matter)
|
||||
func (s1 Set[T]) Equal(s2 Set[T]) bool {
|
||||
return len(s1) == len(s2) && s1.IsSuperset(s2)
|
||||
}
|
||||
|
||||
type sortableSliceOfGeneric[T ordered] []T
|
||||
|
||||
func (g sortableSliceOfGeneric[T]) Len() int { return len(g) }
|
||||
func (g sortableSliceOfGeneric[T]) Less(i, j int) bool { return less[T](g[i], g[j]) }
|
||||
func (g sortableSliceOfGeneric[T]) Swap(i, j int) { g[i], g[j] = g[j], g[i] }
|
||||
|
||||
// List returns the contents as a sorted T slice.
|
||||
//
|
||||
// This is a separate function and not a method because not all types supported
|
||||
// by Generic are ordered and only those can be sorted.
|
||||
func List[T ordered](s Set[T]) []T {
|
||||
res := make(sortableSliceOfGeneric[T], 0, len(s))
|
||||
for key := range s {
|
||||
res = append(res, key)
|
||||
}
|
||||
sort.Sort(res)
|
||||
return res
|
||||
}
|
||||
|
||||
// UnsortedList returns the slice with contents in random order.
|
||||
func (s Set[T]) UnsortedList() []T {
|
||||
res := make([]T, 0, len(s))
|
||||
for key := range s {
|
||||
res = append(res, key)
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
// PopAny returns a single element from the set.
|
||||
func (s Set[T]) PopAny() (T, bool) {
|
||||
for key := range s {
|
||||
s.Delete(key)
|
||||
return key, true
|
||||
}
|
||||
var zeroValue T
|
||||
return zeroValue, false
|
||||
}
|
||||
|
||||
// Len returns the size of the set.
|
||||
func (s Set[T]) Len() int {
|
||||
return len(s)
|
||||
}
|
||||
|
||||
func less[T ordered](lhs, rhs T) bool {
|
||||
return lhs < rhs
|
||||
}
|
||||
148
vendor/k8s.io/apimachinery/pkg/util/sets/string.go
generated
vendored
148
vendor/k8s.io/apimachinery/pkg/util/sets/string.go
generated
vendored
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright The Kubernetes Authors.
|
||||
Copyright 2022 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.
|
||||
@@ -14,102 +14,75 @@ See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
// Code generated by set-gen. DO NOT EDIT.
|
||||
|
||||
package sets
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"sort"
|
||||
)
|
||||
|
||||
// sets.String is a set of strings, implemented via map[string]struct{} for minimal memory consumption.
|
||||
// String is a set of strings, implemented via map[string]struct{} for minimal memory consumption.
|
||||
//
|
||||
// Deprecated: use generic Set instead.
|
||||
// new ways:
|
||||
// s1 := Set[string]{}
|
||||
// s2 := New[string]()
|
||||
type String map[string]Empty
|
||||
|
||||
// NewString creates a String from a list of values.
|
||||
func NewString(items ...string) String {
|
||||
ss := make(String, len(items))
|
||||
ss.Insert(items...)
|
||||
return ss
|
||||
return String(New[string](items...))
|
||||
}
|
||||
|
||||
// StringKeySet creates a String from a keys of a map[string](? extends interface{}).
|
||||
// If the value passed in is not actually a map, this will panic.
|
||||
func StringKeySet(theMap interface{}) String {
|
||||
v := reflect.ValueOf(theMap)
|
||||
ret := String{}
|
||||
|
||||
for _, keyValue := range v.MapKeys() {
|
||||
ret.Insert(keyValue.Interface().(string))
|
||||
}
|
||||
return ret
|
||||
func StringKeySet[T any](theMap map[string]T) String {
|
||||
return String(KeySet(theMap))
|
||||
}
|
||||
|
||||
// Insert adds items to the set.
|
||||
func (s String) Insert(items ...string) String {
|
||||
for _, item := range items {
|
||||
s[item] = Empty{}
|
||||
}
|
||||
return s
|
||||
return String(cast(s).Insert(items...))
|
||||
}
|
||||
|
||||
// Delete removes all items from the set.
|
||||
func (s String) Delete(items ...string) String {
|
||||
for _, item := range items {
|
||||
delete(s, item)
|
||||
}
|
||||
return s
|
||||
return String(cast(s).Delete(items...))
|
||||
}
|
||||
|
||||
// Has returns true if and only if item is contained in the set.
|
||||
func (s String) Has(item string) bool {
|
||||
_, contained := s[item]
|
||||
return contained
|
||||
return cast(s).Has(item)
|
||||
}
|
||||
|
||||
// HasAll returns true if and only if all items are contained in the set.
|
||||
func (s String) HasAll(items ...string) bool {
|
||||
for _, item := range items {
|
||||
if !s.Has(item) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
return cast(s).HasAll(items...)
|
||||
}
|
||||
|
||||
// HasAny returns true if any items are contained in the set.
|
||||
func (s String) HasAny(items ...string) bool {
|
||||
for _, item := range items {
|
||||
if s.Has(item) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
return cast(s).HasAny(items...)
|
||||
}
|
||||
|
||||
// Clone returns a new set which is a copy of the current set.
|
||||
func (s String) Clone() String {
|
||||
result := make(String, len(s))
|
||||
for key := range s {
|
||||
result.Insert(key)
|
||||
}
|
||||
return result
|
||||
return String(cast(s).Clone())
|
||||
}
|
||||
|
||||
// Difference returns a set of objects that are not in s2
|
||||
// Difference returns a set of objects that are not in s2.
|
||||
// For example:
|
||||
// s1 = {a1, a2, a3}
|
||||
// s2 = {a1, a2, a4, a5}
|
||||
// s1.Difference(s2) = {a3}
|
||||
// s2.Difference(s1) = {a4, a5}
|
||||
func (s String) Difference(s2 String) String {
|
||||
result := NewString()
|
||||
for key := range s {
|
||||
if !s2.Has(key) {
|
||||
result.Insert(key)
|
||||
}
|
||||
}
|
||||
return result
|
||||
func (s1 String) Difference(s2 String) String {
|
||||
return String(cast(s1).Difference(cast(s2)))
|
||||
}
|
||||
|
||||
// SymmetricDifference returns a set of elements which are in either of the sets, but not in their intersection.
|
||||
// For example:
|
||||
// s1 = {a1, a2, a3}
|
||||
// s2 = {a1, a2, a4, a5}
|
||||
// s1.SymmetricDifference(s2) = {a3, a4, a5}
|
||||
// s2.SymmetricDifference(s1) = {a3, a4, a5}
|
||||
func (s1 String) SymmetricDifference(s2 String) String {
|
||||
return String(cast(s1).SymmetricDifference(cast(s2)))
|
||||
}
|
||||
|
||||
// Union returns a new set which includes items in either s1 or s2.
|
||||
@@ -119,11 +92,7 @@ func (s String) Difference(s2 String) String {
|
||||
// s1.Union(s2) = {a1, a2, a3, a4}
|
||||
// s2.Union(s1) = {a1, a2, a3, a4}
|
||||
func (s1 String) Union(s2 String) String {
|
||||
result := s1.Clone()
|
||||
for key := range s2 {
|
||||
result.Insert(key)
|
||||
}
|
||||
return result
|
||||
return String(cast(s1).Union(cast(s2)))
|
||||
}
|
||||
|
||||
// Intersection returns a new set which includes the item in BOTH s1 and s2
|
||||
@@ -132,80 +101,37 @@ func (s1 String) Union(s2 String) String {
|
||||
// s2 = {a2, a3}
|
||||
// s1.Intersection(s2) = {a2}
|
||||
func (s1 String) Intersection(s2 String) String {
|
||||
var walk, other String
|
||||
result := NewString()
|
||||
if s1.Len() < s2.Len() {
|
||||
walk = s1
|
||||
other = s2
|
||||
} else {
|
||||
walk = s2
|
||||
other = s1
|
||||
}
|
||||
for key := range walk {
|
||||
if other.Has(key) {
|
||||
result.Insert(key)
|
||||
}
|
||||
}
|
||||
return result
|
||||
return String(cast(s1).Intersection(cast(s2)))
|
||||
}
|
||||
|
||||
// IsSuperset returns true if and only if s1 is a superset of s2.
|
||||
func (s1 String) IsSuperset(s2 String) bool {
|
||||
for item := range s2 {
|
||||
if !s1.Has(item) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
return cast(s1).IsSuperset(cast(s2))
|
||||
}
|
||||
|
||||
// Equal returns true if and only if s1 is equal (as a set) to s2.
|
||||
// Two sets are equal if their membership is identical.
|
||||
// (In practice, this means same elements, order doesn't matter)
|
||||
func (s1 String) Equal(s2 String) bool {
|
||||
return len(s1) == len(s2) && s1.IsSuperset(s2)
|
||||
return cast(s1).Equal(cast(s2))
|
||||
}
|
||||
|
||||
type sortableSliceOfString []string
|
||||
|
||||
func (s sortableSliceOfString) Len() int { return len(s) }
|
||||
func (s sortableSliceOfString) Less(i, j int) bool { return lessString(s[i], s[j]) }
|
||||
func (s sortableSliceOfString) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
|
||||
|
||||
// List returns the contents as a sorted string slice.
|
||||
func (s String) List() []string {
|
||||
res := make(sortableSliceOfString, 0, len(s))
|
||||
for key := range s {
|
||||
res = append(res, key)
|
||||
}
|
||||
sort.Sort(res)
|
||||
return []string(res)
|
||||
return List(cast(s))
|
||||
}
|
||||
|
||||
// UnsortedList returns the slice with contents in random order.
|
||||
func (s String) UnsortedList() []string {
|
||||
res := make([]string, 0, len(s))
|
||||
for key := range s {
|
||||
res = append(res, key)
|
||||
}
|
||||
return res
|
||||
return cast(s).UnsortedList()
|
||||
}
|
||||
|
||||
// Returns a single element from the set.
|
||||
// PopAny returns a single element from the set.
|
||||
func (s String) PopAny() (string, bool) {
|
||||
for key := range s {
|
||||
s.Delete(key)
|
||||
return key, true
|
||||
}
|
||||
var zeroValue string
|
||||
return zeroValue, false
|
||||
return cast(s).PopAny()
|
||||
}
|
||||
|
||||
// Len returns the size of the set.
|
||||
func (s String) Len() int {
|
||||
return len(s)
|
||||
}
|
||||
|
||||
func lessString(lhs, rhs string) bool {
|
||||
return lhs < rhs
|
||||
}
|
||||
|
||||
183
vendor/k8s.io/apiserver/pkg/audit/context.go
generated
vendored
183
vendor/k8s.io/apiserver/pkg/audit/context.go
generated
vendored
@@ -20,6 +20,7 @@ import (
|
||||
"context"
|
||||
"sync"
|
||||
|
||||
"k8s.io/apimachinery/pkg/types"
|
||||
auditinternal "k8s.io/apiserver/pkg/apis/audit"
|
||||
genericapirequest "k8s.io/apiserver/pkg/endpoints/request"
|
||||
"k8s.io/klog/v2"
|
||||
@@ -28,38 +29,31 @@ import (
|
||||
// The key type is unexported to prevent collisions
|
||||
type key int
|
||||
|
||||
const (
|
||||
// auditAnnotationsKey is the context key for the audit annotations.
|
||||
// TODO: consolidate all audit info under the AuditContext, rather than storing 3 separate keys.
|
||||
auditAnnotationsKey key = iota
|
||||
// auditKey is the context key for storing the audit context that is being
|
||||
// captured and the evaluated policy that applies to the given request.
|
||||
const auditKey key = iota
|
||||
|
||||
// auditKey is the context key for storing the audit event that is being
|
||||
// captured and the evaluated policy that applies to the given request.
|
||||
auditKey
|
||||
// AuditContext holds the information for constructing the audit events for the current request.
|
||||
type AuditContext struct {
|
||||
// RequestAuditConfig is the audit configuration that applies to the request
|
||||
RequestAuditConfig RequestAuditConfig
|
||||
|
||||
// auditAnnotationsMutexKey is the context key for the audit annotations mutex.
|
||||
auditAnnotationsMutexKey
|
||||
)
|
||||
// Event is the audit Event object that is being captured to be written in
|
||||
// the API audit log. It is set to nil when the request is not being audited.
|
||||
Event *auditinternal.Event
|
||||
|
||||
// annotations = *[]annotation instead of a map to preserve order of insertions
|
||||
type annotation struct {
|
||||
key, value string
|
||||
// annotations holds audit annotations that are recorded before the event has been initialized.
|
||||
// This is represented as a slice rather than a map to preserve order.
|
||||
annotations []annotation
|
||||
// annotationMutex guards annotations AND event.Annotations
|
||||
annotationMutex sync.Mutex
|
||||
|
||||
// auditID is the Audit ID associated with this request.
|
||||
auditID types.UID
|
||||
}
|
||||
|
||||
// WithAuditAnnotations returns a new context that can store audit annotations
|
||||
// via the AddAuditAnnotation function. This function is meant to be called from
|
||||
// an early request handler to allow all later layers to set audit annotations.
|
||||
// This is required to support flows where handlers that come before WithAudit
|
||||
// (such as WithAuthentication) wish to set audit annotations.
|
||||
func WithAuditAnnotations(parent context.Context) context.Context {
|
||||
// this should never really happen, but prevent double registration of this slice
|
||||
if _, ok := parent.Value(auditAnnotationsKey).(*[]annotation); ok {
|
||||
return parent
|
||||
}
|
||||
parent = withAuditAnnotationsMutex(parent)
|
||||
|
||||
var annotations []annotation // avoid allocations until we actually need it
|
||||
return genericapirequest.WithValue(parent, auditAnnotationsKey, &annotations)
|
||||
type annotation struct {
|
||||
key, value string
|
||||
}
|
||||
|
||||
// AddAuditAnnotation sets the audit annotation for the given key, value pair.
|
||||
@@ -70,102 +64,79 @@ func WithAuditAnnotations(parent context.Context) context.Context {
|
||||
// Handlers that are unaware of their position in the overall request flow should
|
||||
// prefer AddAuditAnnotation over LogAnnotation to avoid dropping annotations.
|
||||
func AddAuditAnnotation(ctx context.Context, key, value string) {
|
||||
mutex, ok := auditAnnotationsMutex(ctx)
|
||||
if !ok {
|
||||
ac := AuditContextFrom(ctx)
|
||||
if ac == nil {
|
||||
// auditing is not enabled
|
||||
return
|
||||
}
|
||||
|
||||
mutex.Lock()
|
||||
defer mutex.Unlock()
|
||||
ac.annotationMutex.Lock()
|
||||
defer ac.annotationMutex.Unlock()
|
||||
|
||||
ae := AuditEventFrom(ctx)
|
||||
var ctxAnnotations *[]annotation
|
||||
if ae == nil {
|
||||
ctxAnnotations, _ = ctx.Value(auditAnnotationsKey).(*[]annotation)
|
||||
}
|
||||
|
||||
addAuditAnnotationLocked(ae, ctxAnnotations, key, value)
|
||||
addAuditAnnotationLocked(ac, key, value)
|
||||
}
|
||||
|
||||
// AddAuditAnnotations is a bulk version of AddAuditAnnotation. Refer to AddAuditAnnotation for
|
||||
// restrictions on when this can be called.
|
||||
// keysAndValues are the key-value pairs to add, and must have an even number of items.
|
||||
func AddAuditAnnotations(ctx context.Context, keysAndValues ...string) {
|
||||
mutex, ok := auditAnnotationsMutex(ctx)
|
||||
if !ok {
|
||||
ac := AuditContextFrom(ctx)
|
||||
if ac == nil {
|
||||
// auditing is not enabled
|
||||
return
|
||||
}
|
||||
|
||||
mutex.Lock()
|
||||
defer mutex.Unlock()
|
||||
|
||||
ae := AuditEventFrom(ctx)
|
||||
var ctxAnnotations *[]annotation
|
||||
if ae == nil {
|
||||
ctxAnnotations, _ = ctx.Value(auditAnnotationsKey).(*[]annotation)
|
||||
}
|
||||
ac.annotationMutex.Lock()
|
||||
defer ac.annotationMutex.Unlock()
|
||||
|
||||
if len(keysAndValues)%2 != 0 {
|
||||
klog.Errorf("Dropping mismatched audit annotation %q", keysAndValues[len(keysAndValues)-1])
|
||||
}
|
||||
for i := 0; i < len(keysAndValues); i += 2 {
|
||||
addAuditAnnotationLocked(ae, ctxAnnotations, keysAndValues[i], keysAndValues[i+1])
|
||||
addAuditAnnotationLocked(ac, keysAndValues[i], keysAndValues[i+1])
|
||||
}
|
||||
}
|
||||
|
||||
// AddAuditAnnotationsMap is a bulk version of AddAuditAnnotation. Refer to AddAuditAnnotation for
|
||||
// restrictions on when this can be called.
|
||||
func AddAuditAnnotationsMap(ctx context.Context, annotations map[string]string) {
|
||||
mutex, ok := auditAnnotationsMutex(ctx)
|
||||
if !ok {
|
||||
ac := AuditContextFrom(ctx)
|
||||
if ac == nil {
|
||||
// auditing is not enabled
|
||||
return
|
||||
}
|
||||
|
||||
mutex.Lock()
|
||||
defer mutex.Unlock()
|
||||
|
||||
ae := AuditEventFrom(ctx)
|
||||
var ctxAnnotations *[]annotation
|
||||
if ae == nil {
|
||||
ctxAnnotations, _ = ctx.Value(auditAnnotationsKey).(*[]annotation)
|
||||
}
|
||||
ac.annotationMutex.Lock()
|
||||
defer ac.annotationMutex.Unlock()
|
||||
|
||||
for k, v := range annotations {
|
||||
addAuditAnnotationLocked(ae, ctxAnnotations, k, v)
|
||||
addAuditAnnotationLocked(ac, k, v)
|
||||
}
|
||||
}
|
||||
|
||||
// addAuditAnnotationLocked is the shared code for recording an audit annotation. This method should
|
||||
// only be called while the auditAnnotationsMutex is locked.
|
||||
func addAuditAnnotationLocked(ae *auditinternal.Event, annotations *[]annotation, key, value string) {
|
||||
if ae != nil {
|
||||
logAnnotation(ae, key, value)
|
||||
} else if annotations != nil {
|
||||
*annotations = append(*annotations, annotation{key: key, value: value})
|
||||
func addAuditAnnotationLocked(ac *AuditContext, key, value string) {
|
||||
if ac.Event != nil {
|
||||
logAnnotation(ac.Event, key, value)
|
||||
} else {
|
||||
ac.annotations = append(ac.annotations, annotation{key: key, value: value})
|
||||
}
|
||||
}
|
||||
|
||||
// This is private to prevent reads/write to the slice from outside of this package.
|
||||
// The audit event should be directly read to get access to the annotations.
|
||||
func addAuditAnnotationsFrom(ctx context.Context, ev *auditinternal.Event) {
|
||||
mutex, ok := auditAnnotationsMutex(ctx)
|
||||
if !ok {
|
||||
ac := AuditContextFrom(ctx)
|
||||
if ac == nil {
|
||||
// auditing is not enabled
|
||||
return
|
||||
}
|
||||
|
||||
mutex.Lock()
|
||||
defer mutex.Unlock()
|
||||
ac.annotationMutex.Lock()
|
||||
defer ac.annotationMutex.Unlock()
|
||||
|
||||
annotations, ok := ctx.Value(auditAnnotationsKey).(*[]annotation)
|
||||
if !ok {
|
||||
return // no annotations to copy
|
||||
}
|
||||
|
||||
for _, kv := range *annotations {
|
||||
for _, kv := range ac.annotations {
|
||||
logAnnotation(ev, kv.key, kv.value)
|
||||
}
|
||||
}
|
||||
@@ -185,12 +156,13 @@ func logAnnotation(ae *auditinternal.Event, key, value string) {
|
||||
ae.Annotations[key] = value
|
||||
}
|
||||
|
||||
// WithAuditContext returns a new context that stores the pair of the audit
|
||||
// configuration object that applies to the given request and
|
||||
// the audit event that is going to be written to the API audit log.
|
||||
func WithAuditContext(parent context.Context, ev *AuditContext) context.Context {
|
||||
parent = withAuditAnnotationsMutex(parent)
|
||||
return genericapirequest.WithValue(parent, auditKey, ev)
|
||||
// WithAuditContext returns a new context that stores the AuditContext.
|
||||
func WithAuditContext(parent context.Context) context.Context {
|
||||
if AuditContextFrom(parent) != nil {
|
||||
return parent // Avoid double registering.
|
||||
}
|
||||
|
||||
return genericapirequest.WithValue(parent, auditKey, &AuditContext{})
|
||||
}
|
||||
|
||||
// AuditEventFrom returns the audit event struct on the ctx
|
||||
@@ -209,17 +181,46 @@ func AuditContextFrom(ctx context.Context) *AuditContext {
|
||||
return ev
|
||||
}
|
||||
|
||||
// WithAuditAnnotationMutex adds a mutex for guarding context.AddAuditAnnotation.
|
||||
func withAuditAnnotationsMutex(parent context.Context) context.Context {
|
||||
if _, ok := parent.Value(auditAnnotationsMutexKey).(*sync.Mutex); ok {
|
||||
return parent
|
||||
// WithAuditID sets the AuditID on the AuditContext. The AuditContext must already be present in the
|
||||
// request context. If the specified auditID is empty, no value is set.
|
||||
func WithAuditID(ctx context.Context, auditID types.UID) {
|
||||
if auditID == "" {
|
||||
return
|
||||
}
|
||||
ac := AuditContextFrom(ctx)
|
||||
if ac == nil {
|
||||
return
|
||||
}
|
||||
ac.auditID = auditID
|
||||
if ac.Event != nil {
|
||||
ac.Event.AuditID = auditID
|
||||
}
|
||||
var mutex sync.Mutex
|
||||
return genericapirequest.WithValue(parent, auditAnnotationsMutexKey, &mutex)
|
||||
}
|
||||
|
||||
// AuditAnnotationsMutex returns the audit annotations mutex from the context.
|
||||
func auditAnnotationsMutex(ctx context.Context) (*sync.Mutex, bool) {
|
||||
mutex, ok := ctx.Value(auditAnnotationsMutexKey).(*sync.Mutex)
|
||||
return mutex, ok
|
||||
// AuditIDFrom returns the value of the audit ID from the request context.
|
||||
func AuditIDFrom(ctx context.Context) (types.UID, bool) {
|
||||
if ac := AuditContextFrom(ctx); ac != nil {
|
||||
return ac.auditID, ac.auditID != ""
|
||||
}
|
||||
return "", false
|
||||
}
|
||||
|
||||
// GetAuditIDTruncated returns the audit ID (truncated) from the request context.
|
||||
// If the length of the Audit-ID value exceeds the limit, we truncate it to keep
|
||||
// the first N (maxAuditIDLength) characters.
|
||||
// This is intended to be used in logging only.
|
||||
func GetAuditIDTruncated(ctx context.Context) string {
|
||||
auditID, ok := AuditIDFrom(ctx)
|
||||
if !ok {
|
||||
return ""
|
||||
}
|
||||
|
||||
// if the user has specified a very long audit ID then we will use the first N characters
|
||||
// Note: assuming Audit-ID header is in ASCII
|
||||
const maxAuditIDLength = 64
|
||||
if len(auditID) > maxAuditIDLength {
|
||||
auditID = auditID[:maxAuditIDLength]
|
||||
}
|
||||
|
||||
return string(auditID)
|
||||
}
|
||||
|
||||
12
vendor/k8s.io/apiserver/pkg/audit/evaluator.go
generated
vendored
12
vendor/k8s.io/apiserver/pkg/audit/evaluator.go
generated
vendored
@@ -21,18 +21,6 @@ import (
|
||||
"k8s.io/apiserver/pkg/authorization/authorizer"
|
||||
)
|
||||
|
||||
// AuditContext is a pair of the audit configuration object that applies to
|
||||
// a given request and the audit Event object that is being captured.
|
||||
// It's a convenient placeholder to store both these objects in the request context.
|
||||
type AuditContext struct {
|
||||
// RequestAuditConfig is the audit configuration that applies to the request
|
||||
RequestAuditConfig RequestAuditConfig
|
||||
|
||||
// Event is the audit Event object that is being captured to be written in
|
||||
// the API audit log. It is set to nil when the request is not being audited.
|
||||
Event *audit.Event
|
||||
}
|
||||
|
||||
// RequestAuditConfig is the evaluated audit configuration that is applicable to
|
||||
// a given request. PolicyRuleEvaluator evaluates the audit policy against the
|
||||
// authorizer attributes and returns a RequestAuditConfig that applies to the request.
|
||||
|
||||
12
vendor/k8s.io/apiserver/pkg/audit/request.go
generated
vendored
12
vendor/k8s.io/apiserver/pkg/audit/request.go
generated
vendored
@@ -21,7 +21,6 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"reflect"
|
||||
"time"
|
||||
|
||||
authnv1 "k8s.io/api/authentication/v1"
|
||||
@@ -34,7 +33,6 @@ import (
|
||||
auditinternal "k8s.io/apiserver/pkg/apis/audit"
|
||||
"k8s.io/apiserver/pkg/authentication/user"
|
||||
"k8s.io/apiserver/pkg/authorization/authorizer"
|
||||
"k8s.io/apiserver/pkg/endpoints/request"
|
||||
"k8s.io/klog/v2"
|
||||
|
||||
"github.com/google/uuid"
|
||||
@@ -54,7 +52,7 @@ func NewEventFromRequest(req *http.Request, requestReceivedTimestamp time.Time,
|
||||
Level: level,
|
||||
}
|
||||
|
||||
auditID, found := request.AuditIDFrom(req.Context())
|
||||
auditID, found := AuditIDFrom(req.Context())
|
||||
if !found {
|
||||
auditID = types.UID(uuid.New().String())
|
||||
}
|
||||
@@ -154,7 +152,7 @@ func LogRequestObject(ctx context.Context, obj runtime.Object, objGV schema.Grou
|
||||
if shouldOmitManagedFields(ctx) {
|
||||
copy, ok, err := copyWithoutManagedFields(obj)
|
||||
if err != nil {
|
||||
klog.Warningf("error while dropping managed fields from the request for %q error: %v", reflect.TypeOf(obj).Name(), err)
|
||||
klog.ErrorS(err, "Error while dropping managed fields from the request", "auditID", ae.AuditID)
|
||||
}
|
||||
if ok {
|
||||
obj = copy
|
||||
@@ -166,7 +164,7 @@ func LogRequestObject(ctx context.Context, obj runtime.Object, objGV schema.Grou
|
||||
ae.RequestObject, err = encodeObject(obj, objGV, s)
|
||||
if err != nil {
|
||||
// TODO(audit): add error slice to audit event struct
|
||||
klog.Warningf("Auditing failed of %v request: %v", reflect.TypeOf(obj).Name(), err)
|
||||
klog.ErrorS(err, "Encoding failed of request object", "auditID", ae.AuditID, "gvr", gvr.String(), "obj", obj)
|
||||
return
|
||||
}
|
||||
}
|
||||
@@ -209,7 +207,7 @@ func LogResponseObject(ctx context.Context, obj runtime.Object, gv schema.GroupV
|
||||
if shouldOmitManagedFields(ctx) {
|
||||
copy, ok, err := copyWithoutManagedFields(obj)
|
||||
if err != nil {
|
||||
klog.Warningf("error while dropping managed fields from the response for %q error: %v", reflect.TypeOf(obj).Name(), err)
|
||||
klog.ErrorS(err, "Error while dropping managed fields from the response", "auditID", ae.AuditID)
|
||||
}
|
||||
if ok {
|
||||
obj = copy
|
||||
@@ -220,7 +218,7 @@ func LogResponseObject(ctx context.Context, obj runtime.Object, gv schema.GroupV
|
||||
var err error
|
||||
ae.ResponseObject, err = encodeObject(obj, gv, s)
|
||||
if err != nil {
|
||||
klog.Warningf("Audit failed for %q response: %v", reflect.TypeOf(obj).Name(), err)
|
||||
klog.ErrorS(err, "Encoding failed of response object", "auditID", ae.AuditID, "obj", obj)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
94
vendor/k8s.io/apiserver/pkg/endpoints/metrics/metrics.go
generated
vendored
94
vendor/k8s.io/apiserver/pkg/endpoints/metrics/metrics.go
generated
vendored
@@ -62,7 +62,8 @@ const (
|
||||
var (
|
||||
deprecatedRequestGauge = compbasemetrics.NewGaugeVec(
|
||||
&compbasemetrics.GaugeOpts{
|
||||
Name: "apiserver_requested_deprecated_apis",
|
||||
Subsystem: APIServerComponent,
|
||||
Name: "requested_deprecated_apis",
|
||||
Help: "Gauge of deprecated APIs that have been requested, broken out by API group, version, resource, subresource, and removed_release.",
|
||||
StabilityLevel: compbasemetrics.STABLE,
|
||||
},
|
||||
@@ -73,7 +74,8 @@ var (
|
||||
// the upstream library supports it.
|
||||
requestCounter = compbasemetrics.NewCounterVec(
|
||||
&compbasemetrics.CounterOpts{
|
||||
Name: "apiserver_request_total",
|
||||
Subsystem: APIServerComponent,
|
||||
Name: "request_total",
|
||||
Help: "Counter of apiserver requests broken out for each verb, dry run value, group, version, resource, scope, component, and HTTP response code.",
|
||||
StabilityLevel: compbasemetrics.STABLE,
|
||||
},
|
||||
@@ -81,7 +83,8 @@ var (
|
||||
)
|
||||
longRunningRequestsGauge = compbasemetrics.NewGaugeVec(
|
||||
&compbasemetrics.GaugeOpts{
|
||||
Name: "apiserver_longrunning_requests",
|
||||
Subsystem: APIServerComponent,
|
||||
Name: "longrunning_requests",
|
||||
Help: "Gauge of all active long-running apiserver requests broken out by verb, group, version, resource, scope and component. Not all requests are tracked this way.",
|
||||
StabilityLevel: compbasemetrics.STABLE,
|
||||
},
|
||||
@@ -89,8 +92,9 @@ var (
|
||||
)
|
||||
requestLatencies = compbasemetrics.NewHistogramVec(
|
||||
&compbasemetrics.HistogramOpts{
|
||||
Name: "apiserver_request_duration_seconds",
|
||||
Help: "Response latency distribution in seconds for each verb, dry run value, group, version, resource, subresource, scope and component.",
|
||||
Subsystem: APIServerComponent,
|
||||
Name: "request_duration_seconds",
|
||||
Help: "Response latency distribution in seconds for each verb, dry run value, group, version, resource, subresource, scope and component.",
|
||||
// This metric is used for verifying api call latencies SLO,
|
||||
// as well as tracking regressions in this aspects.
|
||||
// Thus we customize buckets significantly, to empower both usecases.
|
||||
@@ -102,8 +106,24 @@ var (
|
||||
)
|
||||
requestSloLatencies = compbasemetrics.NewHistogramVec(
|
||||
&compbasemetrics.HistogramOpts{
|
||||
Name: "apiserver_request_slo_duration_seconds",
|
||||
Help: "Response latency distribution (not counting webhook duration) in seconds for each verb, group, version, resource, subresource, scope and component.",
|
||||
Subsystem: APIServerComponent,
|
||||
Name: "request_slo_duration_seconds",
|
||||
Help: "Response latency distribution (not counting webhook duration) in seconds for each verb, group, version, resource, subresource, scope and component.",
|
||||
// This metric is supplementary to the requestLatencies metric.
|
||||
// It measures request duration excluding webhooks as they are mostly
|
||||
// dependant on user configuration.
|
||||
Buckets: []float64{0.05, 0.1, 0.2, 0.4, 0.6, 0.8, 1.0, 1.25, 1.5, 2, 3,
|
||||
4, 5, 6, 8, 10, 15, 20, 30, 45, 60},
|
||||
StabilityLevel: compbasemetrics.ALPHA,
|
||||
DeprecatedVersion: "1.27.0",
|
||||
},
|
||||
[]string{"verb", "group", "version", "resource", "subresource", "scope", "component"},
|
||||
)
|
||||
requestSliLatencies = compbasemetrics.NewHistogramVec(
|
||||
&compbasemetrics.HistogramOpts{
|
||||
Subsystem: APIServerComponent,
|
||||
Name: "request_sli_duration_seconds",
|
||||
Help: "Response latency distribution (not counting webhook duration) in seconds for each verb, group, version, resource, subresource, scope and component.",
|
||||
// This metric is supplementary to the requestLatencies metric.
|
||||
// It measures request duration excluding webhooks as they are mostly
|
||||
// dependant on user configuration.
|
||||
@@ -128,8 +148,9 @@ var (
|
||||
)
|
||||
responseSizes = compbasemetrics.NewHistogramVec(
|
||||
&compbasemetrics.HistogramOpts{
|
||||
Name: "apiserver_response_sizes",
|
||||
Help: "Response size distribution in bytes for each group, version, verb, resource, subresource, scope and component.",
|
||||
Subsystem: APIServerComponent,
|
||||
Name: "response_sizes",
|
||||
Help: "Response size distribution in bytes for each group, version, verb, resource, subresource, scope and component.",
|
||||
// Use buckets ranging from 1000 bytes (1KB) to 10^9 bytes (1GB).
|
||||
Buckets: compbasemetrics.ExponentialBuckets(1000, 10.0, 7),
|
||||
StabilityLevel: compbasemetrics.STABLE,
|
||||
@@ -139,14 +160,16 @@ var (
|
||||
// TLSHandshakeErrors is a number of requests dropped with 'TLS handshake error from' error
|
||||
TLSHandshakeErrors = compbasemetrics.NewCounter(
|
||||
&compbasemetrics.CounterOpts{
|
||||
Name: "apiserver_tls_handshake_errors_total",
|
||||
Subsystem: APIServerComponent,
|
||||
Name: "tls_handshake_errors_total",
|
||||
Help: "Number of requests dropped with 'TLS handshake error from' error",
|
||||
StabilityLevel: compbasemetrics.ALPHA,
|
||||
},
|
||||
)
|
||||
WatchEvents = compbasemetrics.NewCounterVec(
|
||||
&compbasemetrics.CounterOpts{
|
||||
Name: "apiserver_watch_events_total",
|
||||
Subsystem: APIServerComponent,
|
||||
Name: "watch_events_total",
|
||||
Help: "Number of events sent in watch clients",
|
||||
StabilityLevel: compbasemetrics.ALPHA,
|
||||
},
|
||||
@@ -154,7 +177,8 @@ var (
|
||||
)
|
||||
WatchEventsSizes = compbasemetrics.NewHistogramVec(
|
||||
&compbasemetrics.HistogramOpts{
|
||||
Name: "apiserver_watch_events_sizes",
|
||||
Subsystem: APIServerComponent,
|
||||
Name: "watch_events_sizes",
|
||||
Help: "Watch event size distribution in bytes",
|
||||
Buckets: compbasemetrics.ExponentialBuckets(1024, 2.0, 8), // 1K, 2K, 4K, 8K, ..., 128K.
|
||||
StabilityLevel: compbasemetrics.ALPHA,
|
||||
@@ -165,7 +189,8 @@ var (
|
||||
// it reports maximal usage during the last second.
|
||||
currentInflightRequests = compbasemetrics.NewGaugeVec(
|
||||
&compbasemetrics.GaugeOpts{
|
||||
Name: "apiserver_current_inflight_requests",
|
||||
Subsystem: APIServerComponent,
|
||||
Name: "current_inflight_requests",
|
||||
Help: "Maximal number of currently used inflight request limit of this apiserver per request kind in last second.",
|
||||
StabilityLevel: compbasemetrics.STABLE,
|
||||
},
|
||||
@@ -173,7 +198,8 @@ var (
|
||||
)
|
||||
currentInqueueRequests = compbasemetrics.NewGaugeVec(
|
||||
&compbasemetrics.GaugeOpts{
|
||||
Name: "apiserver_current_inqueue_requests",
|
||||
Subsystem: APIServerComponent,
|
||||
Name: "current_inqueue_requests",
|
||||
Help: "Maximal number of queued requests in this apiserver per request kind in last second.",
|
||||
StabilityLevel: compbasemetrics.ALPHA,
|
||||
},
|
||||
@@ -182,7 +208,8 @@ var (
|
||||
|
||||
requestTerminationsTotal = compbasemetrics.NewCounterVec(
|
||||
&compbasemetrics.CounterOpts{
|
||||
Name: "apiserver_request_terminations_total",
|
||||
Subsystem: APIServerComponent,
|
||||
Name: "request_terminations_total",
|
||||
Help: "Number of requests which apiserver terminated in self-defense.",
|
||||
StabilityLevel: compbasemetrics.ALPHA,
|
||||
},
|
||||
@@ -191,7 +218,8 @@ var (
|
||||
|
||||
apiSelfRequestCounter = compbasemetrics.NewCounterVec(
|
||||
&compbasemetrics.CounterOpts{
|
||||
Name: "apiserver_selfrequest_total",
|
||||
Subsystem: APIServerComponent,
|
||||
Name: "selfrequest_total",
|
||||
Help: "Counter of apiserver self-requests broken out for each verb, API resource and subresource.",
|
||||
StabilityLevel: compbasemetrics.ALPHA,
|
||||
},
|
||||
@@ -200,7 +228,8 @@ var (
|
||||
|
||||
requestFilterDuration = compbasemetrics.NewHistogramVec(
|
||||
&compbasemetrics.HistogramOpts{
|
||||
Name: "apiserver_request_filter_duration_seconds",
|
||||
Subsystem: APIServerComponent,
|
||||
Name: "request_filter_duration_seconds",
|
||||
Help: "Request filter latency distribution in seconds, for each filter type",
|
||||
Buckets: []float64{0.0001, 0.0003, 0.001, 0.003, 0.01, 0.03, 0.1, 0.3, 1.0, 5.0},
|
||||
StabilityLevel: compbasemetrics.ALPHA,
|
||||
@@ -211,7 +240,8 @@ var (
|
||||
// requestAbortsTotal is a number of aborted requests with http.ErrAbortHandler
|
||||
requestAbortsTotal = compbasemetrics.NewCounterVec(
|
||||
&compbasemetrics.CounterOpts{
|
||||
Name: "apiserver_request_aborts_total",
|
||||
Subsystem: APIServerComponent,
|
||||
Name: "request_aborts_total",
|
||||
Help: "Number of requests which apiserver aborted possibly due to a timeout, for each group, version, verb, resource, subresource and scope",
|
||||
StabilityLevel: compbasemetrics.ALPHA,
|
||||
},
|
||||
@@ -231,7 +261,8 @@ var (
|
||||
// within the wait threshold.
|
||||
requestPostTimeoutTotal = compbasemetrics.NewCounterVec(
|
||||
&compbasemetrics.CounterOpts{
|
||||
Name: "apiserver_request_post_timeout_total",
|
||||
Subsystem: APIServerComponent,
|
||||
Name: "request_post_timeout_total",
|
||||
Help: "Tracks the activity of the request handlers after the associated requests have been timed out by the apiserver",
|
||||
StabilityLevel: compbasemetrics.ALPHA,
|
||||
},
|
||||
@@ -240,7 +271,8 @@ var (
|
||||
|
||||
requestTimestampComparisonDuration = compbasemetrics.NewHistogramVec(
|
||||
&compbasemetrics.HistogramOpts{
|
||||
Name: "apiserver_request_timestamp_comparison_time",
|
||||
Subsystem: APIServerComponent,
|
||||
Name: "request_timestamp_comparison_time",
|
||||
Help: "Time taken for comparison of old vs new objects in UPDATE or PATCH requests",
|
||||
Buckets: []float64{0.0001, 0.0003, 0.001, 0.003, 0.01, 0.03, 0.1, 0.3, 1.0, 5.0},
|
||||
StabilityLevel: compbasemetrics.ALPHA,
|
||||
@@ -256,6 +288,7 @@ var (
|
||||
longRunningRequestsGauge,
|
||||
requestLatencies,
|
||||
requestSloLatencies,
|
||||
requestSliLatencies,
|
||||
fieldValidationRequestLatencies,
|
||||
responseSizes,
|
||||
TLSHandshakeErrors,
|
||||
@@ -502,8 +535,9 @@ func MonitorRequest(req *http.Request, verb, group, version, resource, subresour
|
||||
fieldValidationRequestLatencies.WithContext(req.Context()).WithLabelValues(fieldValidation, fieldValidationEnabled)
|
||||
|
||||
if wd, ok := request.LatencyTrackersFrom(req.Context()); ok {
|
||||
sloLatency := elapsedSeconds - (wd.MutatingWebhookTracker.GetLatency() + wd.ValidatingWebhookTracker.GetLatency()).Seconds()
|
||||
requestSloLatencies.WithContext(req.Context()).WithLabelValues(reportedVerb, group, version, resource, subresource, scope, component).Observe(sloLatency)
|
||||
sliLatency := elapsedSeconds - (wd.MutatingWebhookTracker.GetLatency() + wd.ValidatingWebhookTracker.GetLatency()).Seconds()
|
||||
requestSloLatencies.WithContext(req.Context()).WithLabelValues(reportedVerb, group, version, resource, subresource, scope, component).Observe(sliLatency)
|
||||
requestSliLatencies.WithContext(req.Context()).WithLabelValues(reportedVerb, group, version, resource, subresource, scope, component).Observe(sliLatency)
|
||||
}
|
||||
// We are only interested in response sizes of read requests.
|
||||
if verb == "GET" || verb == "LIST" {
|
||||
@@ -548,6 +582,20 @@ func InstrumentHandlerFunc(verb, group, version, resource, subresource, scope, c
|
||||
}
|
||||
}
|
||||
|
||||
// NormalizedVerb returns normalized verb
|
||||
func NormalizedVerb(req *http.Request) string {
|
||||
verb := req.Method
|
||||
if requestInfo, ok := request.RequestInfoFrom(req.Context()); ok {
|
||||
// If we can find a requestInfo, we can get a scope, and then
|
||||
// we can convert GETs to LISTs when needed.
|
||||
scope := CleanScope(requestInfo)
|
||||
verb = CanonicalVerb(strings.ToUpper(verb), scope)
|
||||
}
|
||||
|
||||
// mark APPLY requests and WATCH requests correctly.
|
||||
return CleanVerb(verb, req)
|
||||
}
|
||||
|
||||
// CleanScope returns the scope of the request.
|
||||
func CleanScope(requestInfo *request.RequestInfo) string {
|
||||
if requestInfo.Name != "" || requestInfo.Verb == "create" {
|
||||
@@ -588,7 +636,7 @@ func CleanVerb(verb string, request *http.Request) string {
|
||||
if verb == "WATCHLIST" {
|
||||
reportedVerb = "WATCH"
|
||||
}
|
||||
if verb == "PATCH" && request.Header.Get("Content-Type") == string(types.ApplyPatchType) && utilfeature.DefaultFeatureGate.Enabled(features.ServerSideApply) {
|
||||
if verb == "PATCH" && request.Header.Get("Content-Type") == string(types.ApplyPatchType) {
|
||||
reportedVerb = "APPLY"
|
||||
}
|
||||
return reportedVerb
|
||||
|
||||
65
vendor/k8s.io/apiserver/pkg/endpoints/request/auditid.go
generated
vendored
65
vendor/k8s.io/apiserver/pkg/endpoints/request/auditid.go
generated
vendored
@@ -1,65 +0,0 @@
|
||||
/*
|
||||
Copyright 2021 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 request
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"k8s.io/apimachinery/pkg/types"
|
||||
)
|
||||
|
||||
type auditIDKeyType int
|
||||
|
||||
// auditIDKey is the key to associate the Audit-ID value of a request.
|
||||
const auditIDKey auditIDKeyType = iota
|
||||
|
||||
// WithAuditID returns a copy of the parent context into which the Audit-ID
|
||||
// associated with the request is set.
|
||||
//
|
||||
// If the specified auditID is empty, no value is set and the parent context is returned as is.
|
||||
func WithAuditID(parent context.Context, auditID types.UID) context.Context {
|
||||
if auditID == "" {
|
||||
return parent
|
||||
}
|
||||
return WithValue(parent, auditIDKey, auditID)
|
||||
}
|
||||
|
||||
// AuditIDFrom returns the value of the audit ID from the request context.
|
||||
func AuditIDFrom(ctx context.Context) (types.UID, bool) {
|
||||
auditID, ok := ctx.Value(auditIDKey).(types.UID)
|
||||
return auditID, ok
|
||||
}
|
||||
|
||||
// GetAuditIDTruncated returns the audit ID (truncated) from the request context.
|
||||
// If the length of the Audit-ID value exceeds the limit, we truncate it to keep
|
||||
// the first N (maxAuditIDLength) characters.
|
||||
// This is intended to be used in logging only.
|
||||
func GetAuditIDTruncated(ctx context.Context) string {
|
||||
auditID, ok := AuditIDFrom(ctx)
|
||||
if !ok {
|
||||
return ""
|
||||
}
|
||||
|
||||
// if the user has specified a very long audit ID then we will use the first N characters
|
||||
// Note: assuming Audit-ID header is in ASCII
|
||||
const maxAuditIDLength = 64
|
||||
if len(auditID) > maxAuditIDLength {
|
||||
auditID = auditID[0:maxAuditIDLength]
|
||||
}
|
||||
|
||||
return string(auditID)
|
||||
}
|
||||
34
vendor/k8s.io/apiserver/pkg/features/kube_features.go
generated
vendored
34
vendor/k8s.io/apiserver/pkg/features/kube_features.go
generated
vendored
@@ -35,6 +35,13 @@ const (
|
||||
// of code conflicts because changes are more likely to be scattered
|
||||
// across the file.
|
||||
|
||||
// owner: @jefftree @alexzielenski
|
||||
// alpha: v1.26
|
||||
//
|
||||
// Enables an single HTTP endpoint /discovery/<version> which supports native HTTP
|
||||
// caching with ETags containing all APIResources known to the apiserver.
|
||||
AggregatedDiscoveryEndpoint featuregate.Feature = "AggregatedDiscoveryEndpoint"
|
||||
|
||||
// owner: @smarterclayton
|
||||
// alpha: v1.8
|
||||
// beta: v1.9
|
||||
@@ -81,8 +88,15 @@ const (
|
||||
// audited.
|
||||
AdvancedAuditing featuregate.Feature = "AdvancedAuditing"
|
||||
|
||||
// owner: @cici37 @jpbetz
|
||||
// kep: http://kep.k8s.io/3488
|
||||
// alpha: v1.26
|
||||
//
|
||||
// Enables expression validation in Admission Control
|
||||
ValidatingAdmissionPolicy featuregate.Feature = "ValidatingAdmissionPolicy"
|
||||
|
||||
// owner: @cici37
|
||||
// kep: http://kep.k8s.io/2876
|
||||
// kep: https://kep.k8s.io/2876
|
||||
// alpha: v1.23
|
||||
// beta: v1.25
|
||||
//
|
||||
@@ -108,14 +122,14 @@ const (
|
||||
EfficientWatchResumption featuregate.Feature = "EfficientWatchResumption"
|
||||
|
||||
// owner: @aramase
|
||||
// kep: http://kep.k8s.io/3299
|
||||
// kep: https://kep.k8s.io/3299
|
||||
// alpha: v1.25
|
||||
//
|
||||
// Enables KMS v2 API for encryption at rest.
|
||||
KMSv2 featuregate.Feature = "KMSv2"
|
||||
|
||||
// owner: @jiahuif
|
||||
// kep: http://kep.k8s.io/2887
|
||||
// kep: https://kep.k8s.io/2887
|
||||
// alpha: v1.23
|
||||
// beta: v1.24
|
||||
//
|
||||
@@ -124,7 +138,7 @@ const (
|
||||
OpenAPIEnums featuregate.Feature = "OpenAPIEnums"
|
||||
|
||||
// owner: @jefftree
|
||||
// kep: http://kep.k8s.io/2896
|
||||
// kep: https://kep.k8s.io/2896
|
||||
// alpha: v1.23
|
||||
// beta: v1.24
|
||||
//
|
||||
@@ -156,7 +170,7 @@ const (
|
||||
ServerSideApply featuregate.Feature = "ServerSideApply"
|
||||
|
||||
// owner: @kevindelgado
|
||||
// kep: http://kep.k8s.io/2885
|
||||
// kep: https://kep.k8s.io/2885
|
||||
// alpha: v1.23
|
||||
// beta: v1.24
|
||||
//
|
||||
@@ -194,21 +208,25 @@ func init() {
|
||||
// To add a new feature, define a key for it above and add it here. The features will be
|
||||
// available throughout Kubernetes binaries.
|
||||
var defaultKubernetesFeatureGates = map[featuregate.Feature]featuregate.FeatureSpec{
|
||||
AggregatedDiscoveryEndpoint: {Default: false, PreRelease: featuregate.Alpha},
|
||||
|
||||
APIListChunking: {Default: true, PreRelease: featuregate.Beta},
|
||||
|
||||
APIPriorityAndFairness: {Default: true, PreRelease: featuregate.Beta},
|
||||
|
||||
APIResponseCompression: {Default: true, PreRelease: featuregate.Beta},
|
||||
|
||||
APIServerIdentity: {Default: false, PreRelease: featuregate.Alpha},
|
||||
APIServerIdentity: {Default: true, PreRelease: featuregate.Beta},
|
||||
|
||||
APIServerTracing: {Default: false, PreRelease: featuregate.Alpha},
|
||||
|
||||
AdvancedAuditing: {Default: true, PreRelease: featuregate.GA},
|
||||
|
||||
ValidatingAdmissionPolicy: {Default: false, PreRelease: featuregate.Alpha},
|
||||
|
||||
CustomResourceValidationExpressions: {Default: true, PreRelease: featuregate.Beta},
|
||||
|
||||
DryRun: {Default: true, PreRelease: featuregate.GA},
|
||||
DryRun: {Default: true, PreRelease: featuregate.GA, LockToDefault: true}, // remove in 1.28
|
||||
|
||||
EfficientWatchResumption: {Default: true, PreRelease: featuregate.GA, LockToDefault: true},
|
||||
|
||||
@@ -222,7 +240,7 @@ var defaultKubernetesFeatureGates = map[featuregate.Feature]featuregate.FeatureS
|
||||
|
||||
RemoveSelfLink: {Default: true, PreRelease: featuregate.GA, LockToDefault: true},
|
||||
|
||||
ServerSideApply: {Default: true, PreRelease: featuregate.GA},
|
||||
ServerSideApply: {Default: true, PreRelease: featuregate.GA, LockToDefault: true}, // remove in 1.29
|
||||
|
||||
ServerSideFieldValidation: {Default: true, PreRelease: featuregate.Beta},
|
||||
|
||||
|
||||
20
vendor/k8s.io/apiserver/pkg/server/httplog/httplog.go
generated
vendored
20
vendor/k8s.io/apiserver/pkg/server/httplog/httplog.go
generated
vendored
@@ -27,6 +27,7 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"k8s.io/apiserver/pkg/audit"
|
||||
"k8s.io/apiserver/pkg/endpoints/metrics"
|
||||
"k8s.io/apiserver/pkg/endpoints/request"
|
||||
"k8s.io/apiserver/pkg/endpoints/responsewriter"
|
||||
@@ -59,7 +60,7 @@ type respLogger struct {
|
||||
statusRecorded bool
|
||||
status int
|
||||
statusStack string
|
||||
// mutex is used when accessing addedInfo and addedKeyValuePairs.
|
||||
// mutex is used when accessing addedInfo, addedKeyValuePairs and logStacktracePred.
|
||||
// They can be modified by other goroutine when logging happens (in case of request timeout)
|
||||
mutex sync.Mutex
|
||||
addedInfo strings.Builder
|
||||
@@ -181,6 +182,8 @@ func Unlogged(req *http.Request, w http.ResponseWriter) http.ResponseWriter {
|
||||
// StacktraceWhen sets the stacktrace logging predicate, which decides when to log a stacktrace.
|
||||
// There's a default, so you don't need to call this unless you don't like the default.
|
||||
func (rl *respLogger) StacktraceWhen(pred StacktracePred) *respLogger {
|
||||
rl.mutex.Lock()
|
||||
defer rl.mutex.Unlock()
|
||||
rl.logStacktracePred = pred
|
||||
return rl
|
||||
}
|
||||
@@ -239,17 +242,8 @@ func SetStacktracePredicate(ctx context.Context, pred StacktracePred) {
|
||||
// Log is intended to be called once at the end of your request handler, via defer
|
||||
func (rl *respLogger) Log() {
|
||||
latency := time.Since(rl.startTime)
|
||||
auditID := request.GetAuditIDTruncated(rl.req.Context())
|
||||
|
||||
verb := rl.req.Method
|
||||
if requestInfo, ok := request.RequestInfoFrom(rl.req.Context()); ok {
|
||||
// If we can find a requestInfo, we can get a scope, and then
|
||||
// we can convert GETs to LISTs when needed.
|
||||
scope := metrics.CleanScope(requestInfo)
|
||||
verb = metrics.CanonicalVerb(strings.ToUpper(verb), scope)
|
||||
}
|
||||
// mark APPLY requests and WATCH requests correctly.
|
||||
verb = metrics.CleanVerb(verb, rl.req)
|
||||
auditID := audit.GetAuditIDTruncated(rl.req.Context())
|
||||
verb := metrics.NormalizedVerb(rl.req)
|
||||
|
||||
keysAndValues := []interface{}{
|
||||
"verb", verb,
|
||||
@@ -316,6 +310,8 @@ func (rl *respLogger) Hijack() (net.Conn, *bufio.ReadWriter, error) {
|
||||
}
|
||||
|
||||
func (rl *respLogger) recordStatus(status int) {
|
||||
rl.mutex.Lock()
|
||||
defer rl.mutex.Unlock()
|
||||
rl.status = status
|
||||
rl.statusRecorded = true
|
||||
if rl.logStacktracePred(status) {
|
||||
|
||||
5
vendor/k8s.io/client-go/pkg/apis/clientauthentication/types.go
generated
vendored
5
vendor/k8s.io/client-go/pkg/apis/clientauthentication/types.go
generated
vendored
@@ -98,6 +98,11 @@ type Cluster struct {
|
||||
// cluster.
|
||||
// +optional
|
||||
ProxyURL string
|
||||
// DisableCompression allows client to opt-out of response compression for all requests to the server. This is useful
|
||||
// to speed up requests (specifically lists) when client-server network bandwidth is ample, by saving time on
|
||||
// compression (server-side) and decompression (client-side): https://github.com/kubernetes/kubernetes/issues/112296.
|
||||
// +optional
|
||||
DisableCompression bool
|
||||
// Config holds additional config data that is specific to the exec
|
||||
// plugin with regards to the cluster being authenticated to.
|
||||
//
|
||||
|
||||
5
vendor/k8s.io/client-go/pkg/apis/clientauthentication/v1/types.go
generated
vendored
5
vendor/k8s.io/client-go/pkg/apis/clientauthentication/v1/types.go
generated
vendored
@@ -96,6 +96,11 @@ type Cluster struct {
|
||||
// cluster.
|
||||
// +optional
|
||||
ProxyURL string `json:"proxy-url,omitempty"`
|
||||
// DisableCompression allows client to opt-out of response compression for all requests to the server. This is useful
|
||||
// to speed up requests (specifically lists) when client-server network bandwidth is ample, by saving time on
|
||||
// compression (server-side) and decompression (client-side): https://github.com/kubernetes/kubernetes/issues/112296.
|
||||
// +optional
|
||||
DisableCompression bool `json:"disable-compression,omitempty"`
|
||||
// Config holds additional config data that is specific to the exec
|
||||
// plugin with regards to the cluster being authenticated to.
|
||||
//
|
||||
|
||||
2
vendor/k8s.io/client-go/pkg/apis/clientauthentication/v1/zz_generated.conversion.go
generated
vendored
2
vendor/k8s.io/client-go/pkg/apis/clientauthentication/v1/zz_generated.conversion.go
generated
vendored
@@ -86,6 +86,7 @@ func autoConvert_v1_Cluster_To_clientauthentication_Cluster(in *Cluster, out *cl
|
||||
out.InsecureSkipTLSVerify = in.InsecureSkipTLSVerify
|
||||
out.CertificateAuthorityData = *(*[]byte)(unsafe.Pointer(&in.CertificateAuthorityData))
|
||||
out.ProxyURL = in.ProxyURL
|
||||
out.DisableCompression = in.DisableCompression
|
||||
if err := runtime.Convert_runtime_RawExtension_To_runtime_Object(&in.Config, &out.Config, s); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -103,6 +104,7 @@ func autoConvert_clientauthentication_Cluster_To_v1_Cluster(in *clientauthentica
|
||||
out.InsecureSkipTLSVerify = in.InsecureSkipTLSVerify
|
||||
out.CertificateAuthorityData = *(*[]byte)(unsafe.Pointer(&in.CertificateAuthorityData))
|
||||
out.ProxyURL = in.ProxyURL
|
||||
out.DisableCompression = in.DisableCompression
|
||||
if err := runtime.Convert_runtime_Object_To_runtime_RawExtension(&in.Config, &out.Config, s); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
5
vendor/k8s.io/client-go/pkg/apis/clientauthentication/v1beta1/types.go
generated
vendored
5
vendor/k8s.io/client-go/pkg/apis/clientauthentication/v1beta1/types.go
generated
vendored
@@ -96,6 +96,11 @@ type Cluster struct {
|
||||
// cluster.
|
||||
// +optional
|
||||
ProxyURL string `json:"proxy-url,omitempty"`
|
||||
// DisableCompression allows client to opt-out of response compression for all requests to the server. This is useful
|
||||
// to speed up requests (specifically lists) when client-server network bandwidth is ample, by saving time on
|
||||
// compression (server-side) and decompression (client-side): https://github.com/kubernetes/kubernetes/issues/112296.
|
||||
// +optional
|
||||
DisableCompression bool `json:"disable-compression,omitempty"`
|
||||
// Config holds additional config data that is specific to the exec
|
||||
// plugin with regards to the cluster being authenticated to.
|
||||
//
|
||||
|
||||
@@ -86,6 +86,7 @@ func autoConvert_v1beta1_Cluster_To_clientauthentication_Cluster(in *Cluster, ou
|
||||
out.InsecureSkipTLSVerify = in.InsecureSkipTLSVerify
|
||||
out.CertificateAuthorityData = *(*[]byte)(unsafe.Pointer(&in.CertificateAuthorityData))
|
||||
out.ProxyURL = in.ProxyURL
|
||||
out.DisableCompression = in.DisableCompression
|
||||
if err := runtime.Convert_runtime_RawExtension_To_runtime_Object(&in.Config, &out.Config, s); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -103,6 +104,7 @@ func autoConvert_clientauthentication_Cluster_To_v1beta1_Cluster(in *clientauthe
|
||||
out.InsecureSkipTLSVerify = in.InsecureSkipTLSVerify
|
||||
out.CertificateAuthorityData = *(*[]byte)(unsafe.Pointer(&in.CertificateAuthorityData))
|
||||
out.ProxyURL = in.ProxyURL
|
||||
out.DisableCompression = in.DisableCompression
|
||||
if err := runtime.Convert_runtime_Object_To_runtime_RawExtension(&in.Config, &out.Config, s); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
13
vendor/k8s.io/client-go/plugin/pkg/client/auth/exec/exec.go
generated
vendored
13
vendor/k8s.io/client-go/plugin/pkg/client/auth/exec/exec.go
generated
vendored
@@ -308,17 +308,18 @@ func (a *Authenticator) UpdateTransportConfig(c *transport.Config) error {
|
||||
if c.HasCertCallback() {
|
||||
return errors.New("can't add TLS certificate callback: transport.Config.TLS.GetCert already set")
|
||||
}
|
||||
c.TLS.GetCert = a.getCert.GetCert
|
||||
c.TLS.GetCertHolder = a.getCert // comparable for TLS config caching
|
||||
|
||||
if c.Dial != nil {
|
||||
if c.DialHolder != nil {
|
||||
if c.DialHolder.Dial == nil {
|
||||
return errors.New("invalid transport.Config.DialHolder: wrapped Dial function is nil")
|
||||
}
|
||||
|
||||
// if c has a custom dialer, we have to wrap it
|
||||
// TLS config caching is not supported for this config
|
||||
d := connrotation.NewDialerWithTracker(c.Dial, a.connTracker)
|
||||
c.Dial = d.DialContext
|
||||
c.DialHolder = nil
|
||||
d := connrotation.NewDialerWithTracker(c.DialHolder.Dial, a.connTracker)
|
||||
c.DialHolder = &transport.DialHolder{Dial: d.DialContext}
|
||||
} else {
|
||||
c.Dial = a.dial.Dial
|
||||
c.DialHolder = a.dial // comparable for TLS config caching
|
||||
}
|
||||
|
||||
|
||||
10
vendor/k8s.io/client-go/rest/config.go
generated
vendored
10
vendor/k8s.io/client-go/rest/config.go
generated
vendored
@@ -20,7 +20,6 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/url"
|
||||
@@ -519,7 +518,7 @@ func InClusterConfig() (*Config, error) {
|
||||
return nil, ErrNotInCluster
|
||||
}
|
||||
|
||||
token, err := ioutil.ReadFile(tokenFile)
|
||||
token, err := os.ReadFile(tokenFile)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -572,10 +571,7 @@ func LoadTLSFiles(c *Config) error {
|
||||
}
|
||||
|
||||
c.KeyData, err = dataFromSliceOrFile(c.KeyData, c.KeyFile)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
return err
|
||||
}
|
||||
|
||||
// dataFromSliceOrFile returns data from the slice (if non-empty), or from the file,
|
||||
@@ -585,7 +581,7 @@ func dataFromSliceOrFile(data []byte, file string) ([]byte, error) {
|
||||
return data, nil
|
||||
}
|
||||
if len(file) > 0 {
|
||||
fileData, err := ioutil.ReadFile(file)
|
||||
fileData, err := os.ReadFile(file)
|
||||
if err != nil {
|
||||
return []byte{}, err
|
||||
}
|
||||
|
||||
4
vendor/k8s.io/client-go/rest/exec.go
generated
vendored
4
vendor/k8s.io/client-go/rest/exec.go
generated
vendored
@@ -55,6 +55,7 @@ func ConfigToExecCluster(config *Config) (*clientauthenticationapi.Cluster, erro
|
||||
InsecureSkipTLSVerify: config.Insecure,
|
||||
CertificateAuthorityData: caData,
|
||||
ProxyURL: proxyURL,
|
||||
DisableCompression: config.DisableCompression,
|
||||
Config: config.ExecProvider.Config,
|
||||
}, nil
|
||||
}
|
||||
@@ -79,6 +80,7 @@ func ExecClusterToConfig(cluster *clientauthenticationapi.Cluster) (*Config, err
|
||||
ServerName: cluster.TLSServerName,
|
||||
CAData: cluster.CertificateAuthorityData,
|
||||
},
|
||||
Proxy: proxy,
|
||||
Proxy: proxy,
|
||||
DisableCompression: cluster.DisableCompression,
|
||||
}, nil
|
||||
}
|
||||
|
||||
53
vendor/k8s.io/client-go/rest/request.go
generated
vendored
53
vendor/k8s.io/client-go/rest/request.go
generated
vendored
@@ -22,10 +22,10 @@ import (
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"mime"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
"path"
|
||||
"reflect"
|
||||
"strconv"
|
||||
@@ -34,6 +34,7 @@ import (
|
||||
"time"
|
||||
|
||||
"golang.org/x/net/http2"
|
||||
|
||||
"k8s.io/apimachinery/pkg/api/errors"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
@@ -116,8 +117,11 @@ type Request struct {
|
||||
subresource string
|
||||
|
||||
// output
|
||||
err error
|
||||
body io.Reader
|
||||
err error
|
||||
|
||||
// only one of body / bodyBytes may be set. requests using body are not retriable.
|
||||
body io.Reader
|
||||
bodyBytes []byte
|
||||
|
||||
retryFn requestRetryFunc
|
||||
}
|
||||
@@ -437,18 +441,21 @@ func (r *Request) Body(obj interface{}) *Request {
|
||||
}
|
||||
switch t := obj.(type) {
|
||||
case string:
|
||||
data, err := ioutil.ReadFile(t)
|
||||
data, err := os.ReadFile(t)
|
||||
if err != nil {
|
||||
r.err = err
|
||||
return r
|
||||
}
|
||||
glogBody("Request Body", data)
|
||||
r.body = bytes.NewReader(data)
|
||||
r.body = nil
|
||||
r.bodyBytes = data
|
||||
case []byte:
|
||||
glogBody("Request Body", t)
|
||||
r.body = bytes.NewReader(t)
|
||||
r.body = nil
|
||||
r.bodyBytes = t
|
||||
case io.Reader:
|
||||
r.body = t
|
||||
r.bodyBytes = nil
|
||||
case runtime.Object:
|
||||
// callers may pass typed interface pointers, therefore we must check nil with reflection
|
||||
if reflect.ValueOf(t).IsNil() {
|
||||
@@ -465,7 +472,8 @@ func (r *Request) Body(obj interface{}) *Request {
|
||||
return r
|
||||
}
|
||||
glogBody("Request Body", data)
|
||||
r.body = bytes.NewReader(data)
|
||||
r.body = nil
|
||||
r.bodyBytes = data
|
||||
r.SetHeader("Content-Type", r.c.content.ContentType)
|
||||
default:
|
||||
r.err = fmt.Errorf("unknown type used for body: %+v", obj)
|
||||
@@ -825,9 +833,6 @@ func (r *Request) Stream(ctx context.Context) (io.ReadCloser, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if r.body != nil {
|
||||
req.Body = ioutil.NopCloser(r.body)
|
||||
}
|
||||
resp, err := client.Do(req)
|
||||
updateURLMetrics(ctx, r, resp, err)
|
||||
retry.After(ctx, r, resp, err)
|
||||
@@ -889,8 +894,20 @@ func (r *Request) requestPreflightCheck() error {
|
||||
}
|
||||
|
||||
func (r *Request) newHTTPRequest(ctx context.Context) (*http.Request, error) {
|
||||
var body io.Reader
|
||||
switch {
|
||||
case r.body != nil && r.bodyBytes != nil:
|
||||
return nil, fmt.Errorf("cannot set both body and bodyBytes")
|
||||
case r.body != nil:
|
||||
body = r.body
|
||||
case r.bodyBytes != nil:
|
||||
// Create a new reader specifically for this request.
|
||||
// Giving each request a dedicated reader allows retries to avoid races resetting the request body.
|
||||
body = bytes.NewReader(r.bodyBytes)
|
||||
}
|
||||
|
||||
url := r.URL().String()
|
||||
req, err := http.NewRequest(r.verb, url, r.body)
|
||||
req, err := http.NewRequest(r.verb, url, body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -1018,7 +1035,7 @@ func (r *Request) Do(ctx context.Context) Result {
|
||||
func (r *Request) DoRaw(ctx context.Context) ([]byte, error) {
|
||||
var result Result
|
||||
err := r.request(ctx, func(req *http.Request, resp *http.Response) {
|
||||
result.body, result.err = ioutil.ReadAll(resp.Body)
|
||||
result.body, result.err = io.ReadAll(resp.Body)
|
||||
glogBody("Response Body", result.body)
|
||||
if resp.StatusCode < http.StatusOK || resp.StatusCode > http.StatusPartialContent {
|
||||
result.err = r.transformUnstructuredResponseError(resp, req, result.body)
|
||||
@@ -1037,7 +1054,7 @@ func (r *Request) DoRaw(ctx context.Context) ([]byte, error) {
|
||||
func (r *Request) transformResponse(resp *http.Response, req *http.Request) Result {
|
||||
var body []byte
|
||||
if resp.Body != nil {
|
||||
data, err := ioutil.ReadAll(resp.Body)
|
||||
data, err := io.ReadAll(resp.Body)
|
||||
switch err.(type) {
|
||||
case nil:
|
||||
body = data
|
||||
@@ -1179,7 +1196,7 @@ const maxUnstructuredResponseTextBytes = 2048
|
||||
// TODO: introduce transformation of generic http.Client.Do() errors that separates 4.
|
||||
func (r *Request) transformUnstructuredResponseError(resp *http.Response, req *http.Request, body []byte) error {
|
||||
if body == nil && resp.Body != nil {
|
||||
if data, err := ioutil.ReadAll(&io.LimitedReader{R: resp.Body, N: maxUnstructuredResponseTextBytes}); err == nil {
|
||||
if data, err := io.ReadAll(&io.LimitedReader{R: resp.Body, N: maxUnstructuredResponseTextBytes}); err == nil {
|
||||
body = data
|
||||
}
|
||||
}
|
||||
@@ -1288,6 +1305,14 @@ func (r Result) StatusCode(statusCode *int) Result {
|
||||
return r
|
||||
}
|
||||
|
||||
// ContentType returns the "Content-Type" response header into the passed
|
||||
// string, returning the Result for possible chaining. (Only valid if no
|
||||
// error code was returned.)
|
||||
func (r Result) ContentType(contentType *string) Result {
|
||||
*contentType = r.contentType
|
||||
return r
|
||||
}
|
||||
|
||||
// Into stores the result into obj, if possible. If obj is nil it is ignored.
|
||||
// If the returned object is of type Status and has .Status != StatusSuccess, the
|
||||
// additional information in Status will be used to enrich the error.
|
||||
|
||||
5
vendor/k8s.io/client-go/rest/transport.go
generated
vendored
5
vendor/k8s.io/client-go/rest/transport.go
generated
vendored
@@ -108,10 +108,13 @@ func (c *Config) TransportConfig() (*transport.Config, error) {
|
||||
Groups: c.Impersonate.Groups,
|
||||
Extra: c.Impersonate.Extra,
|
||||
},
|
||||
Dial: c.Dial,
|
||||
Proxy: c.Proxy,
|
||||
}
|
||||
|
||||
if c.Dial != nil {
|
||||
conf.DialHolder = &transport.DialHolder{Dial: c.Dial}
|
||||
}
|
||||
|
||||
if c.ExecProvider != nil && c.AuthProvider != nil {
|
||||
return nil, errors.New("execProvider and authProvider cannot be used in combination")
|
||||
}
|
||||
|
||||
20
vendor/k8s.io/client-go/rest/with_retry.go
generated
vendored
20
vendor/k8s.io/client-go/rest/with_retry.go
generated
vendored
@@ -20,7 +20,6 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"time"
|
||||
@@ -154,6 +153,11 @@ func (r *withRetry) IsNextRetry(ctx context.Context, restReq *Request, httpReq *
|
||||
return false
|
||||
}
|
||||
|
||||
if restReq.body != nil {
|
||||
// we have an opaque reader, we can't safely reset it
|
||||
return false
|
||||
}
|
||||
|
||||
r.attempts++
|
||||
r.retryAfter = &RetryAfter{Attempt: r.attempts}
|
||||
if r.attempts > r.maxRetries {
|
||||
@@ -210,18 +214,6 @@ func (r *withRetry) Before(ctx context.Context, request *Request) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// At this point we've made atleast one attempt, post which the response
|
||||
// body should have been fully read and closed in order for it to be safe
|
||||
// to reset the request body before we reconnect, in order for us to reuse
|
||||
// the same TCP connection.
|
||||
if seeker, ok := request.body.(io.Seeker); ok && request.body != nil {
|
||||
if _, err := seeker.Seek(0, io.SeekStart); err != nil {
|
||||
err = fmt.Errorf("failed to reset the request body while retrying a request: %v", err)
|
||||
r.trackPreviousError(err)
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
// if we are here, we have made attempt(s) at least once before.
|
||||
if request.backoff != nil {
|
||||
delay := request.backoff.CalculateBackoff(url)
|
||||
@@ -345,7 +337,7 @@ func readAndCloseResponseBody(resp *http.Response) {
|
||||
defer resp.Body.Close()
|
||||
|
||||
if resp.ContentLength <= maxBodySlurpSize {
|
||||
io.Copy(ioutil.Discard, &io.LimitedReader{R: resp.Body, N: maxBodySlurpSize})
|
||||
io.Copy(io.Discard, &io.LimitedReader{R: resp.Body, N: maxBodySlurpSize})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
91
vendor/k8s.io/client-go/tools/clientcmd/api/helpers.go
generated
vendored
91
vendor/k8s.io/client-go/tools/clientcmd/api/helpers.go
generated
vendored
@@ -20,10 +20,11 @@ import (
|
||||
"encoding/base64"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func init() {
|
||||
@@ -82,21 +83,21 @@ func MinifyConfig(config *Config) error {
|
||||
}
|
||||
|
||||
var (
|
||||
redactedBytes []byte
|
||||
dataOmittedBytes []byte
|
||||
redactedBytes []byte
|
||||
)
|
||||
|
||||
// Flatten redacts raw data entries from the config object for a human-readable view.
|
||||
// ShortenConfig redacts raw data entries from the config object for a human-readable view.
|
||||
func ShortenConfig(config *Config) {
|
||||
// trick json encoder into printing a human readable string in the raw data
|
||||
// trick json encoder into printing a human-readable string in the raw data
|
||||
// by base64 decoding what we want to print. Relies on implementation of
|
||||
// http://golang.org/pkg/encoding/json/#Marshal using base64 to encode []byte
|
||||
for key, authInfo := range config.AuthInfos {
|
||||
if len(authInfo.ClientKeyData) > 0 {
|
||||
authInfo.ClientKeyData = redactedBytes
|
||||
authInfo.ClientKeyData = dataOmittedBytes
|
||||
}
|
||||
if len(authInfo.ClientCertificateData) > 0 {
|
||||
authInfo.ClientCertificateData = redactedBytes
|
||||
authInfo.ClientCertificateData = dataOmittedBytes
|
||||
}
|
||||
if len(authInfo.Token) > 0 {
|
||||
authInfo.Token = "REDACTED"
|
||||
@@ -111,7 +112,7 @@ func ShortenConfig(config *Config) {
|
||||
}
|
||||
}
|
||||
|
||||
// Flatten changes the config object into a self contained config (useful for making secrets)
|
||||
// FlattenConfig changes the config object into a self-contained config (useful for making secrets)
|
||||
func FlattenConfig(config *Config) error {
|
||||
for key, authInfo := range config.AuthInfos {
|
||||
baseDir, err := MakeAbs(path.Dir(authInfo.LocationOfOrigin), "")
|
||||
@@ -152,7 +153,7 @@ func FlattenContent(path *string, contents *[]byte, baseDir string) error {
|
||||
|
||||
var err error
|
||||
absPath := ResolvePath(*path, baseDir)
|
||||
*contents, err = ioutil.ReadFile(absPath)
|
||||
*contents, err = os.ReadFile(absPath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -189,3 +190,77 @@ func MakeAbs(path, base string) (string, error) {
|
||||
}
|
||||
return filepath.Join(base, path), nil
|
||||
}
|
||||
|
||||
// RedactSecrets replaces any sensitive values with REDACTED
|
||||
func RedactSecrets(config *Config) error {
|
||||
return redactSecrets(reflect.ValueOf(config), false)
|
||||
}
|
||||
|
||||
func redactSecrets(curr reflect.Value, redact bool) error {
|
||||
redactedBytes = []byte("REDACTED")
|
||||
if !curr.IsValid() {
|
||||
return nil
|
||||
}
|
||||
|
||||
actualCurrValue := curr
|
||||
if curr.Kind() == reflect.Ptr {
|
||||
actualCurrValue = curr.Elem()
|
||||
}
|
||||
|
||||
switch actualCurrValue.Kind() {
|
||||
case reflect.Map:
|
||||
for _, v := range actualCurrValue.MapKeys() {
|
||||
err := redactSecrets(actualCurrValue.MapIndex(v), false)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
|
||||
case reflect.String:
|
||||
if redact {
|
||||
if !actualCurrValue.IsZero() {
|
||||
actualCurrValue.SetString("REDACTED")
|
||||
}
|
||||
}
|
||||
return nil
|
||||
|
||||
case reflect.Slice:
|
||||
if actualCurrValue.Type() == reflect.TypeOf([]byte{}) && redact {
|
||||
if !actualCurrValue.IsNil() {
|
||||
actualCurrValue.SetBytes(redactedBytes)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
for i := 0; i < actualCurrValue.Len(); i++ {
|
||||
err := redactSecrets(actualCurrValue.Index(i), false)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
|
||||
case reflect.Struct:
|
||||
for fieldIndex := 0; fieldIndex < actualCurrValue.NumField(); fieldIndex++ {
|
||||
currFieldValue := actualCurrValue.Field(fieldIndex)
|
||||
currFieldType := actualCurrValue.Type().Field(fieldIndex)
|
||||
currYamlTag := currFieldType.Tag.Get("datapolicy")
|
||||
currFieldTypeYamlName := strings.Split(currYamlTag, ",")[0]
|
||||
if currFieldTypeYamlName != "" {
|
||||
err := redactSecrets(currFieldValue, true)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
err := redactSecrets(currFieldValue, false)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
5
vendor/k8s.io/client-go/tools/clientcmd/api/types.go
generated
vendored
5
vendor/k8s.io/client-go/tools/clientcmd/api/types.go
generated
vendored
@@ -93,6 +93,11 @@ type Cluster struct {
|
||||
// attach, port forward).
|
||||
// +optional
|
||||
ProxyURL string `json:"proxy-url,omitempty"`
|
||||
// DisableCompression allows client to opt-out of response compression for all requests to the server. This is useful
|
||||
// to speed up requests (specifically lists) when client-server network bandwidth is ample, by saving time on
|
||||
// compression (server-side) and decompression (client-side): https://github.com/kubernetes/kubernetes/issues/112296.
|
||||
// +optional
|
||||
DisableCompression bool `json:"disable-compression,omitempty"`
|
||||
// Extensions holds additional information. This is useful for extenders so that reads and writes don't clobber unknown fields
|
||||
// +optional
|
||||
Extensions map[string]runtime.Object `json:"extensions,omitempty"`
|
||||
|
||||
3
vendor/k8s.io/client-go/tools/remotecommand/errorstream.go
generated
vendored
3
vendor/k8s.io/client-go/tools/remotecommand/errorstream.go
generated
vendored
@@ -19,7 +19,6 @@ package remotecommand
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
|
||||
"k8s.io/apimachinery/pkg/util/runtime"
|
||||
)
|
||||
@@ -39,7 +38,7 @@ func watchErrorStream(errorStream io.Reader, d errorStreamDecoder) chan error {
|
||||
go func() {
|
||||
defer runtime.HandleCrash()
|
||||
|
||||
message, err := ioutil.ReadAll(errorStream)
|
||||
message, err := io.ReadAll(errorStream)
|
||||
switch {
|
||||
case err != nil && err != io.EOF:
|
||||
errorChan <- fmt.Errorf("error reading from error stream: %s", err)
|
||||
|
||||
60
vendor/k8s.io/client-go/tools/remotecommand/remotecommand.go
generated
vendored
60
vendor/k8s.io/client-go/tools/remotecommand/remotecommand.go
generated
vendored
@@ -17,6 +17,7 @@ limitations under the License.
|
||||
package remotecommand
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
@@ -27,7 +28,7 @@ import (
|
||||
"k8s.io/apimachinery/pkg/util/httpstream"
|
||||
"k8s.io/apimachinery/pkg/util/remotecommand"
|
||||
restclient "k8s.io/client-go/rest"
|
||||
spdy "k8s.io/client-go/transport/spdy"
|
||||
"k8s.io/client-go/transport/spdy"
|
||||
)
|
||||
|
||||
// StreamOptions holds information pertaining to the current streaming session:
|
||||
@@ -43,11 +44,16 @@ type StreamOptions struct {
|
||||
|
||||
// Executor is an interface for transporting shell-style streams.
|
||||
type Executor interface {
|
||||
// Stream initiates the transport of the standard shell streams. It will transport any
|
||||
// non-nil stream to a remote system, and return an error if a problem occurs. If tty
|
||||
// is set, the stderr stream is not used (raw TTY manages stdout and stderr over the
|
||||
// stdout stream).
|
||||
// Deprecated: use StreamWithContext instead to avoid possible resource leaks.
|
||||
// See https://github.com/kubernetes/kubernetes/pull/103177 for details.
|
||||
Stream(options StreamOptions) error
|
||||
|
||||
// StreamWithContext initiates the transport of the standard shell streams. It will
|
||||
// transport any non-nil stream to a remote system, and return an error if a problem
|
||||
// occurs. If tty is set, the stderr stream is not used (raw TTY manages stdout and
|
||||
// stderr over the stdout stream).
|
||||
// The context controls the entire lifetime of stream execution.
|
||||
StreamWithContext(ctx context.Context, options StreamOptions) error
|
||||
}
|
||||
|
||||
type streamCreator interface {
|
||||
@@ -106,9 +112,14 @@ func NewSPDYExecutorForProtocols(transport http.RoundTripper, upgrader spdy.Upgr
|
||||
// Stream opens a protocol streamer to the server and streams until a client closes
|
||||
// the connection or the server disconnects.
|
||||
func (e *streamExecutor) Stream(options StreamOptions) error {
|
||||
req, err := http.NewRequest(e.method, e.url.String(), nil)
|
||||
return e.StreamWithContext(context.Background(), options)
|
||||
}
|
||||
|
||||
// newConnectionAndStream creates a new SPDY connection and a stream protocol handler upon it.
|
||||
func (e *streamExecutor) newConnectionAndStream(ctx context.Context, options StreamOptions) (httpstream.Connection, streamProtocolHandler, error) {
|
||||
req, err := http.NewRequestWithContext(ctx, e.method, e.url.String(), nil)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error creating request: %v", err)
|
||||
return nil, nil, fmt.Errorf("error creating request: %v", err)
|
||||
}
|
||||
|
||||
conn, protocol, err := spdy.Negotiate(
|
||||
@@ -118,9 +129,8 @@ func (e *streamExecutor) Stream(options StreamOptions) error {
|
||||
e.protocols...,
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
return nil, nil, err
|
||||
}
|
||||
defer conn.Close()
|
||||
|
||||
var streamer streamProtocolHandler
|
||||
|
||||
@@ -138,5 +148,35 @@ func (e *streamExecutor) Stream(options StreamOptions) error {
|
||||
streamer = newStreamProtocolV1(options)
|
||||
}
|
||||
|
||||
return streamer.stream(conn)
|
||||
return conn, streamer, nil
|
||||
}
|
||||
|
||||
// StreamWithContext opens a protocol streamer to the server and streams until a client closes
|
||||
// the connection or the server disconnects or the context is done.
|
||||
func (e *streamExecutor) StreamWithContext(ctx context.Context, options StreamOptions) error {
|
||||
conn, streamer, err := e.newConnectionAndStream(ctx, options)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer conn.Close()
|
||||
|
||||
panicChan := make(chan any, 1)
|
||||
errorChan := make(chan error, 1)
|
||||
go func() {
|
||||
defer func() {
|
||||
if p := recover(); p != nil {
|
||||
panicChan <- p
|
||||
}
|
||||
}()
|
||||
errorChan <- streamer.stream(conn)
|
||||
}()
|
||||
|
||||
select {
|
||||
case p := <-panicChan:
|
||||
panic(p)
|
||||
case err := <-errorChan:
|
||||
return err
|
||||
case <-ctx.Done():
|
||||
return ctx.Err()
|
||||
}
|
||||
}
|
||||
|
||||
7
vendor/k8s.io/client-go/tools/remotecommand/v1.go
generated
vendored
7
vendor/k8s.io/client-go/tools/remotecommand/v1.go
generated
vendored
@@ -19,7 +19,6 @@ package remotecommand
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
|
||||
"k8s.io/api/core/v1"
|
||||
@@ -29,8 +28,8 @@ import (
|
||||
|
||||
// streamProtocolV1 implements the first version of the streaming exec & attach
|
||||
// protocol. This version has some bugs, such as not being able to detect when
|
||||
// non-interactive stdin data has ended. See http://issues.k8s.io/13394 and
|
||||
// http://issues.k8s.io/13395 for more details.
|
||||
// non-interactive stdin data has ended. See https://issues.k8s.io/13394 and
|
||||
// https://issues.k8s.io/13395 for more details.
|
||||
type streamProtocolV1 struct {
|
||||
StreamOptions
|
||||
|
||||
@@ -111,7 +110,7 @@ func (p *streamProtocolV1) stream(conn streamCreator) error {
|
||||
|
||||
// always read from errorStream
|
||||
go func() {
|
||||
message, err := ioutil.ReadAll(p.errorStream)
|
||||
message, err := io.ReadAll(p.errorStream)
|
||||
if err != nil && err != io.EOF {
|
||||
errorChan <- fmt.Errorf("Error reading from error stream: %s", err)
|
||||
return
|
||||
|
||||
7
vendor/k8s.io/client-go/tools/remotecommand/v2.go
generated
vendored
7
vendor/k8s.io/client-go/tools/remotecommand/v2.go
generated
vendored
@@ -19,7 +19,6 @@ package remotecommand
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"sync"
|
||||
|
||||
@@ -126,7 +125,7 @@ func (p *streamProtocolV2) copyStdin() {
|
||||
|
||||
// this "copy" doesn't actually read anything - it's just here to wait for
|
||||
// the server to close remoteStdin.
|
||||
if _, err := io.Copy(ioutil.Discard, p.remoteStdin); err != nil {
|
||||
if _, err := io.Copy(io.Discard, p.remoteStdin); err != nil {
|
||||
runtime.HandleError(err)
|
||||
}
|
||||
}()
|
||||
@@ -145,7 +144,7 @@ func (p *streamProtocolV2) copyStdout(wg *sync.WaitGroup) {
|
||||
// make sure, packet in queue can be consumed.
|
||||
// block in queue may lead to deadlock in conn.server
|
||||
// issue: https://github.com/kubernetes/kubernetes/issues/96339
|
||||
defer io.Copy(ioutil.Discard, p.remoteStdout)
|
||||
defer io.Copy(io.Discard, p.remoteStdout)
|
||||
|
||||
if _, err := io.Copy(p.Stdout, p.remoteStdout); err != nil {
|
||||
runtime.HandleError(err)
|
||||
@@ -162,7 +161,7 @@ func (p *streamProtocolV2) copyStderr(wg *sync.WaitGroup) {
|
||||
go func() {
|
||||
defer runtime.HandleCrash()
|
||||
defer wg.Done()
|
||||
defer io.Copy(ioutil.Discard, p.remoteStderr)
|
||||
defer io.Copy(io.Discard, p.remoteStderr)
|
||||
|
||||
if _, err := io.Copy(p.Stderr, p.remoteStderr); err != nil {
|
||||
runtime.HandleError(err)
|
||||
|
||||
16
vendor/k8s.io/client-go/transport/cache.go
generated
vendored
16
vendor/k8s.io/client-go/transport/cache.go
generated
vendored
@@ -93,13 +93,13 @@ func (c *tlsTransportCache) get(config *Config) (http.RoundTripper, error) {
|
||||
return nil, err
|
||||
}
|
||||
// The options didn't require a custom TLS config
|
||||
if tlsConfig == nil && config.Dial == nil && config.Proxy == nil {
|
||||
if tlsConfig == nil && config.DialHolder == nil && config.Proxy == nil {
|
||||
return http.DefaultTransport, nil
|
||||
}
|
||||
|
||||
var dial func(ctx context.Context, network, address string) (net.Conn, error)
|
||||
if config.Dial != nil {
|
||||
dial = config.Dial
|
||||
if config.DialHolder != nil {
|
||||
dial = config.DialHolder.Dial
|
||||
} else {
|
||||
dial = (&net.Dialer{
|
||||
Timeout: 30 * time.Second,
|
||||
@@ -109,7 +109,7 @@ func (c *tlsTransportCache) get(config *Config) (http.RoundTripper, error) {
|
||||
|
||||
// If we use are reloading files, we need to handle certificate rotation properly
|
||||
// TODO(jackkleeman): We can also add rotation here when config.HasCertCallback() is true
|
||||
if config.TLS.ReloadTLSFiles {
|
||||
if config.TLS.ReloadTLSFiles && tlsConfig != nil && tlsConfig.GetClientCertificate != nil {
|
||||
dynamicCertDialer := certRotatingDialer(tlsConfig.GetClientCertificate, dial)
|
||||
tlsConfig.GetClientCertificate = dynamicCertDialer.GetClientCertificate
|
||||
dial = dynamicCertDialer.connDialer.DialContext
|
||||
@@ -149,14 +149,6 @@ func tlsConfigKey(c *Config) (tlsCacheKey, bool, error) {
|
||||
// cannot determine equality for functions
|
||||
return tlsCacheKey{}, false, nil
|
||||
}
|
||||
if c.Dial != nil && c.DialHolder == nil {
|
||||
// cannot determine equality for dial function that doesn't have non-nil DialHolder set as well
|
||||
return tlsCacheKey{}, false, nil
|
||||
}
|
||||
if c.TLS.GetCert != nil && c.TLS.GetCertHolder == nil {
|
||||
// cannot determine equality for getCert function that doesn't have non-nil GetCertHolder set as well
|
||||
return tlsCacheKey{}, false, nil
|
||||
}
|
||||
|
||||
k := tlsCacheKey{
|
||||
insecure: c.TLS.Insecure,
|
||||
|
||||
24
vendor/k8s.io/client-go/transport/cache_go118.go
generated
vendored
Normal file
24
vendor/k8s.io/client-go/transport/cache_go118.go
generated
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
//go:build go1.18
|
||||
|
||||
/*
|
||||
Copyright 2022 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 transport
|
||||
|
||||
// assert at compile time that tlsCacheKey is comparable in a way that will never panic at runtime.
|
||||
var _ = isComparable[tlsCacheKey]
|
||||
|
||||
func isComparable[T comparable]() {}
|
||||
14
vendor/k8s.io/client-go/transport/config.go
generated
vendored
14
vendor/k8s.io/client-go/transport/config.go
generated
vendored
@@ -67,11 +67,8 @@ type Config struct {
|
||||
// instead of setting this value directly.
|
||||
WrapTransport WrapperFunc
|
||||
|
||||
// Dial specifies the dial function for creating unencrypted TCP connections.
|
||||
// If specified, this transport will be non-cacheable unless DialHolder is also set.
|
||||
Dial func(ctx context.Context, network, address string) (net.Conn, error)
|
||||
// DialHolder can be populated to make transport configs cacheable.
|
||||
// If specified, DialHolder.Dial must be equal to Dial.
|
||||
// DialHolder specifies the dial function for creating unencrypted TCP connections.
|
||||
// This struct indirection is used to make transport configs cacheable.
|
||||
DialHolder *DialHolder
|
||||
|
||||
// Proxy is the proxy func to be used for all requests made by this
|
||||
@@ -121,7 +118,7 @@ func (c *Config) HasCertAuth() bool {
|
||||
|
||||
// HasCertCallback returns whether the configuration has certificate callback or not.
|
||||
func (c *Config) HasCertCallback() bool {
|
||||
return c.TLS.GetCert != nil
|
||||
return c.TLS.GetCertHolder != nil
|
||||
}
|
||||
|
||||
// Wrap adds a transport middleware function that will give the caller
|
||||
@@ -153,10 +150,7 @@ type TLSConfig struct {
|
||||
NextProtos []string
|
||||
|
||||
// Callback that returns a TLS client certificate. CertData, CertFile, KeyData and KeyFile supercede this field.
|
||||
// If specified, this transport is non-cacheable unless CertHolder is populated.
|
||||
GetCert func() (*tls.Certificate, error)
|
||||
// CertHolder can be populated to make transport configs that set GetCert cacheable.
|
||||
// If set, CertHolder.GetCert must be equal to GetCert.
|
||||
// This struct indirection is used to make transport configs cacheable.
|
||||
GetCertHolder *GetCertHolder
|
||||
}
|
||||
|
||||
|
||||
4
vendor/k8s.io/client-go/transport/token_source.go
generated
vendored
4
vendor/k8s.io/client-go/transport/token_source.go
generated
vendored
@@ -18,8 +18,8 @@ package transport
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"os"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
@@ -132,7 +132,7 @@ type fileTokenSource struct {
|
||||
var _ = oauth2.TokenSource(&fileTokenSource{})
|
||||
|
||||
func (ts *fileTokenSource) Token() (*oauth2.Token, error) {
|
||||
tokb, err := ioutil.ReadFile(ts.path)
|
||||
tokb, err := os.ReadFile(ts.path)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to read token file %q: %v", ts.path, err)
|
||||
}
|
||||
|
||||
28
vendor/k8s.io/client-go/transport/transport.go
generated
vendored
28
vendor/k8s.io/client-go/transport/transport.go
generated
vendored
@@ -22,9 +22,8 @@ import (
|
||||
"crypto/x509"
|
||||
"encoding/pem"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"reflect"
|
||||
"os"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
@@ -62,20 +61,12 @@ func New(config *Config) (http.RoundTripper, error) {
|
||||
}
|
||||
|
||||
func isValidHolders(config *Config) bool {
|
||||
if config.TLS.GetCertHolder != nil {
|
||||
if config.TLS.GetCertHolder.GetCert == nil ||
|
||||
config.TLS.GetCert == nil ||
|
||||
reflect.ValueOf(config.TLS.GetCertHolder.GetCert).Pointer() != reflect.ValueOf(config.TLS.GetCert).Pointer() {
|
||||
return false
|
||||
}
|
||||
if config.TLS.GetCertHolder != nil && config.TLS.GetCertHolder.GetCert == nil {
|
||||
return false
|
||||
}
|
||||
|
||||
if config.DialHolder != nil {
|
||||
if config.DialHolder.Dial == nil ||
|
||||
config.Dial == nil ||
|
||||
reflect.ValueOf(config.DialHolder.Dial).Pointer() != reflect.ValueOf(config.Dial).Pointer() {
|
||||
return false
|
||||
}
|
||||
if config.DialHolder != nil && config.DialHolder.Dial == nil {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
@@ -141,7 +132,7 @@ func TLSConfigFor(c *Config) (*tls.Config, error) {
|
||||
return dynamicCertLoader()
|
||||
}
|
||||
if c.HasCertCallback() {
|
||||
cert, err := c.TLS.GetCert()
|
||||
cert, err := c.TLS.GetCertHolder.GetCert()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -182,10 +173,7 @@ func loadTLSFiles(c *Config) error {
|
||||
}
|
||||
|
||||
c.TLS.KeyData, err = dataFromSliceOrFile(c.TLS.KeyData, c.TLS.KeyFile)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
return err
|
||||
}
|
||||
|
||||
// dataFromSliceOrFile returns data from the slice (if non-empty), or from the file,
|
||||
@@ -195,7 +183,7 @@ func dataFromSliceOrFile(data []byte, file string) ([]byte, error) {
|
||||
return data, nil
|
||||
}
|
||||
if len(file) > 0 {
|
||||
fileData, err := ioutil.ReadFile(file)
|
||||
fileData, err := os.ReadFile(file)
|
||||
if err != nil {
|
||||
return []byte{}, err
|
||||
}
|
||||
|
||||
10
vendor/k8s.io/client-go/util/cert/cert.go
generated
vendored
10
vendor/k8s.io/client-go/util/cert/cert.go
generated
vendored
@@ -25,9 +25,9 @@ import (
|
||||
"crypto/x509/pkix"
|
||||
"encoding/pem"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"math/big"
|
||||
"net"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -101,9 +101,9 @@ func GenerateSelfSignedCertKeyWithFixtures(host string, alternateIPs []net.IP, a
|
||||
certFixturePath := filepath.Join(fixtureDirectory, baseName+".crt")
|
||||
keyFixturePath := filepath.Join(fixtureDirectory, baseName+".key")
|
||||
if len(fixtureDirectory) > 0 {
|
||||
cert, err := ioutil.ReadFile(certFixturePath)
|
||||
cert, err := os.ReadFile(certFixturePath)
|
||||
if err == nil {
|
||||
key, err := ioutil.ReadFile(keyFixturePath)
|
||||
key, err := os.ReadFile(keyFixturePath)
|
||||
if err == nil {
|
||||
return cert, key, nil
|
||||
}
|
||||
@@ -188,10 +188,10 @@ func GenerateSelfSignedCertKeyWithFixtures(host string, alternateIPs []net.IP, a
|
||||
}
|
||||
|
||||
if len(fixtureDirectory) > 0 {
|
||||
if err := ioutil.WriteFile(certFixturePath, certBuffer.Bytes(), 0644); err != nil {
|
||||
if err := os.WriteFile(certFixturePath, certBuffer.Bytes(), 0644); err != nil {
|
||||
return nil, nil, fmt.Errorf("failed to write cert fixture to %s: %v", certFixturePath, err)
|
||||
}
|
||||
if err := ioutil.WriteFile(keyFixturePath, keyBuffer.Bytes(), 0644); err != nil {
|
||||
if err := os.WriteFile(keyFixturePath, keyBuffer.Bytes(), 0644); err != nil {
|
||||
return nil, nil, fmt.Errorf("failed to write key fixture to %s: %v", certFixturePath, err)
|
||||
}
|
||||
}
|
||||
|
||||
7
vendor/k8s.io/client-go/util/cert/io.go
generated
vendored
7
vendor/k8s.io/client-go/util/cert/io.go
generated
vendored
@@ -19,7 +19,6 @@ package cert
|
||||
import (
|
||||
"crypto/x509"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
)
|
||||
@@ -66,13 +65,13 @@ func WriteCert(certPath string, data []byte) error {
|
||||
if err := os.MkdirAll(filepath.Dir(certPath), os.FileMode(0755)); err != nil {
|
||||
return err
|
||||
}
|
||||
return ioutil.WriteFile(certPath, data, os.FileMode(0644))
|
||||
return os.WriteFile(certPath, data, os.FileMode(0644))
|
||||
}
|
||||
|
||||
// NewPool returns an x509.CertPool containing the certificates in the given PEM-encoded file.
|
||||
// Returns an error if the file could not be read, a certificate could not be parsed, or if the file does not contain any certificates
|
||||
func NewPool(filename string) (*x509.CertPool, error) {
|
||||
pemBlock, err := ioutil.ReadFile(filename)
|
||||
pemBlock, err := os.ReadFile(filename)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -101,7 +100,7 @@ func NewPoolFromBytes(pemBlock []byte) (*x509.CertPool, error) {
|
||||
// CertsFromFile returns the x509.Certificates contained in the given PEM-encoded file.
|
||||
// Returns an error if the file could not be read, a certificate could not be parsed, or if the file does not contain any certificates
|
||||
func CertsFromFile(file string) ([]*x509.Certificate, error) {
|
||||
pemBlock, err := ioutil.ReadFile(file)
|
||||
pemBlock, err := os.ReadFile(file)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
9
vendor/k8s.io/client-go/util/keyutil/key.go
generated
vendored
9
vendor/k8s.io/client-go/util/keyutil/key.go
generated
vendored
@@ -26,7 +26,6 @@ import (
|
||||
"crypto/x509"
|
||||
"encoding/pem"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
)
|
||||
@@ -69,13 +68,13 @@ func WriteKey(keyPath string, data []byte) error {
|
||||
if err := os.MkdirAll(filepath.Dir(keyPath), os.FileMode(0755)); err != nil {
|
||||
return err
|
||||
}
|
||||
return ioutil.WriteFile(keyPath, data, os.FileMode(0600))
|
||||
return os.WriteFile(keyPath, data, os.FileMode(0600))
|
||||
}
|
||||
|
||||
// LoadOrGenerateKeyFile looks for a key in the file at the given path. If it
|
||||
// can't find one, it will generate a new key and store it there.
|
||||
func LoadOrGenerateKeyFile(keyPath string) (data []byte, wasGenerated bool, err error) {
|
||||
loadedData, err := ioutil.ReadFile(keyPath)
|
||||
loadedData, err := os.ReadFile(keyPath)
|
||||
// Call verifyKeyData to ensure the file wasn't empty/corrupt.
|
||||
if err == nil && verifyKeyData(loadedData) {
|
||||
return loadedData, false, err
|
||||
@@ -122,7 +121,7 @@ func MarshalPrivateKeyToPEM(privateKey crypto.PrivateKey) ([]byte, error) {
|
||||
// PrivateKeyFromFile returns the private key in rsa.PrivateKey or ecdsa.PrivateKey format from a given PEM-encoded file.
|
||||
// Returns an error if the file could not be read or if the private key could not be parsed.
|
||||
func PrivateKeyFromFile(file string) (interface{}, error) {
|
||||
data, err := ioutil.ReadFile(file)
|
||||
data, err := os.ReadFile(file)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -136,7 +135,7 @@ func PrivateKeyFromFile(file string) (interface{}, error) {
|
||||
// PublicKeysFromFile returns the public keys in rsa.PublicKey or ecdsa.PublicKey format from a given PEM-encoded file.
|
||||
// Reads public keys from both public and private key files.
|
||||
func PublicKeysFromFile(file string) ([]interface{}, error) {
|
||||
data, err := ioutil.ReadFile(file)
|
||||
data, err := os.ReadFile(file)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
10
vendor/k8s.io/component-base/featuregate/feature_gate.go
generated
vendored
10
vendor/k8s.io/component-base/featuregate/feature_gate.go
generated
vendored
@@ -17,6 +17,7 @@ limitations under the License.
|
||||
package featuregate
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"sort"
|
||||
"strconv"
|
||||
@@ -27,6 +28,7 @@ import (
|
||||
"github.com/spf13/pflag"
|
||||
|
||||
"k8s.io/apimachinery/pkg/util/naming"
|
||||
featuremetrics "k8s.io/component-base/metrics/prometheus/feature"
|
||||
"k8s.io/klog/v2"
|
||||
)
|
||||
|
||||
@@ -111,6 +113,8 @@ type MutableFeatureGate interface {
|
||||
Add(features map[Feature]FeatureSpec) error
|
||||
// GetAll returns a copy of the map of known feature names to feature specs.
|
||||
GetAll() map[Feature]FeatureSpec
|
||||
// AddMetrics adds feature enablement metrics
|
||||
AddMetrics()
|
||||
}
|
||||
|
||||
// featureGate implements FeatureGate as well as pflag.Value for flag parsing.
|
||||
@@ -329,6 +333,12 @@ func (f *featureGate) AddFlag(fs *pflag.FlagSet) {
|
||||
"Options are:\n"+strings.Join(known, "\n"))
|
||||
}
|
||||
|
||||
func (f *featureGate) AddMetrics() {
|
||||
for feature, featureSpec := range f.GetAll() {
|
||||
featuremetrics.RecordFeatureInfo(context.Background(), string(feature), string(featureSpec.PreRelease), f.Enabled(feature))
|
||||
}
|
||||
}
|
||||
|
||||
// KnownFeatures returns a slice of strings describing the FeatureGate's known features.
|
||||
// Deprecated and GA features are hidden from the list.
|
||||
func (f *featureGate) KnownFeatures() []string {
|
||||
|
||||
43
vendor/k8s.io/component-base/metrics/buckets.go
generated
vendored
Normal file
43
vendor/k8s.io/component-base/metrics/buckets.go
generated
vendored
Normal file
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
Copyright 2022 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 metrics
|
||||
|
||||
import (
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
)
|
||||
|
||||
// DefBuckets is a wrapper for prometheus.DefBuckets
|
||||
var DefBuckets = prometheus.DefBuckets
|
||||
|
||||
// LinearBuckets is a wrapper for prometheus.LinearBuckets.
|
||||
func LinearBuckets(start, width float64, count int) []float64 {
|
||||
return prometheus.LinearBuckets(start, width, count)
|
||||
}
|
||||
|
||||
// ExponentialBuckets is a wrapper for prometheus.ExponentialBuckets.
|
||||
func ExponentialBuckets(start, factor float64, count int) []float64 {
|
||||
return prometheus.ExponentialBuckets(start, factor, count)
|
||||
}
|
||||
|
||||
// MergeBuckets merges buckets together
|
||||
func MergeBuckets(buckets ...[]float64) []float64 {
|
||||
result := make([]float64, 1)
|
||||
for _, s := range buckets {
|
||||
result = append(result, s...)
|
||||
}
|
||||
return result
|
||||
}
|
||||
6
vendor/k8s.io/component-base/metrics/collector.go
generated
vendored
6
vendor/k8s.io/component-base/metrics/collector.go
generated
vendored
@@ -45,9 +45,9 @@ type StableCollector interface {
|
||||
HiddenMetrics() []string
|
||||
}
|
||||
|
||||
// BaseStableCollector which implements almost all of the methods defined by StableCollector
|
||||
// BaseStableCollector which implements almost all methods defined by StableCollector
|
||||
// is a convenient assistant for custom collectors.
|
||||
// It is recommend that inherit BaseStableCollector when implementing custom collectors.
|
||||
// It is recommended to inherit BaseStableCollector when implementing custom collectors.
|
||||
type BaseStableCollector struct {
|
||||
descriptors map[string]*Desc // stores all descriptors by pair<fqName, Desc>, these are collected from DescribeWithStability().
|
||||
registerable map[string]*Desc // stores registerable descriptors by pair<fqName, Desc>, is a subset of descriptors.
|
||||
@@ -62,7 +62,7 @@ func (bsc *BaseStableCollector) DescribeWithStability(ch chan<- *Desc) {
|
||||
}
|
||||
|
||||
// Describe sends all descriptors to the provided channel.
|
||||
// It intend to be called by prometheus registry.
|
||||
// It intended to be called by prometheus registry.
|
||||
func (bsc *BaseStableCollector) Describe(ch chan<- *prometheus.Desc) {
|
||||
for _, d := range bsc.registerable {
|
||||
ch <- d.toPrometheusDesc()
|
||||
|
||||
4
vendor/k8s.io/component-base/metrics/counter.go
generated
vendored
4
vendor/k8s.io/component-base/metrics/counter.go
generated
vendored
@@ -44,7 +44,7 @@ func NewCounter(opts *CounterOpts) *Counter {
|
||||
|
||||
kc := &Counter{
|
||||
CounterOpts: opts,
|
||||
lazyMetric: lazyMetric{},
|
||||
lazyMetric: lazyMetric{stabilityLevel: opts.StabilityLevel},
|
||||
}
|
||||
kc.setPrometheusCounter(noop)
|
||||
kc.lazyInit(kc, BuildFQName(opts.Namespace, opts.Subsystem, opts.Name))
|
||||
@@ -129,7 +129,7 @@ func NewCounterVec(opts *CounterOpts, labels []string) *CounterVec {
|
||||
CounterVec: noopCounterVec,
|
||||
CounterOpts: opts,
|
||||
originalLabels: labels,
|
||||
lazyMetric: lazyMetric{},
|
||||
lazyMetric: lazyMetric{stabilityLevel: opts.StabilityLevel},
|
||||
}
|
||||
cv.lazyInit(cv, fqName)
|
||||
return cv
|
||||
|
||||
4
vendor/k8s.io/component-base/metrics/gauge.go
generated
vendored
4
vendor/k8s.io/component-base/metrics/gauge.go
generated
vendored
@@ -46,7 +46,7 @@ func NewGauge(opts *GaugeOpts) *Gauge {
|
||||
|
||||
kc := &Gauge{
|
||||
GaugeOpts: opts,
|
||||
lazyMetric: lazyMetric{},
|
||||
lazyMetric: lazyMetric{stabilityLevel: opts.StabilityLevel},
|
||||
}
|
||||
kc.setPrometheusGauge(noop)
|
||||
kc.lazyInit(kc, BuildFQName(opts.Namespace, opts.Subsystem, opts.Name))
|
||||
@@ -115,7 +115,7 @@ func NewGaugeVec(opts *GaugeOpts, labels []string) *GaugeVec {
|
||||
GaugeVec: noopGaugeVec,
|
||||
GaugeOpts: opts,
|
||||
originalLabels: labels,
|
||||
lazyMetric: lazyMetric{},
|
||||
lazyMetric: lazyMetric{stabilityLevel: opts.StabilityLevel},
|
||||
}
|
||||
cv.lazyInit(cv, fqName)
|
||||
return cv
|
||||
|
||||
17
vendor/k8s.io/component-base/metrics/histogram.go
generated
vendored
17
vendor/k8s.io/component-base/metrics/histogram.go
generated
vendored
@@ -23,19 +23,6 @@ import (
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
)
|
||||
|
||||
// DefBuckets is a wrapper for prometheus.DefBuckets
|
||||
var DefBuckets = prometheus.DefBuckets
|
||||
|
||||
// LinearBuckets is a wrapper for prometheus.LinearBuckets.
|
||||
func LinearBuckets(start, width float64, count int) []float64 {
|
||||
return prometheus.LinearBuckets(start, width, count)
|
||||
}
|
||||
|
||||
// ExponentialBuckets is a wrapper for prometheus.ExponentialBuckets.
|
||||
func ExponentialBuckets(start, factor float64, count int) []float64 {
|
||||
return prometheus.ExponentialBuckets(start, factor, count)
|
||||
}
|
||||
|
||||
// Histogram is our internal representation for our wrapping struct around prometheus
|
||||
// histograms. Summary implements both kubeCollector and ObserverMetric
|
||||
type Histogram struct {
|
||||
@@ -52,7 +39,7 @@ func NewHistogram(opts *HistogramOpts) *Histogram {
|
||||
|
||||
h := &Histogram{
|
||||
HistogramOpts: opts,
|
||||
lazyMetric: lazyMetric{},
|
||||
lazyMetric: lazyMetric{stabilityLevel: opts.StabilityLevel},
|
||||
}
|
||||
h.setPrometheusHistogram(noopMetric{})
|
||||
h.lazyInit(h, BuildFQName(opts.Namespace, opts.Subsystem, opts.Name))
|
||||
@@ -119,7 +106,7 @@ func NewHistogramVec(opts *HistogramOpts, labels []string) *HistogramVec {
|
||||
HistogramVec: noopHistogramVec,
|
||||
HistogramOpts: opts,
|
||||
originalLabels: labels,
|
||||
lazyMetric: lazyMetric{},
|
||||
lazyMetric: lazyMetric{stabilityLevel: opts.StabilityLevel},
|
||||
}
|
||||
v.lazyInit(v, fqName)
|
||||
return v
|
||||
|
||||
11
vendor/k8s.io/component-base/metrics/legacyregistry/registry.go
generated
vendored
11
vendor/k8s.io/component-base/metrics/legacyregistry/registry.go
generated
vendored
@@ -20,6 +20,7 @@ import (
|
||||
"net/http"
|
||||
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/prometheus/client_golang/prometheus/collectors"
|
||||
"github.com/prometheus/client_golang/prometheus/promhttp"
|
||||
|
||||
"k8s.io/component-base/metrics"
|
||||
@@ -41,13 +42,15 @@ var (
|
||||
|
||||
// Register registers a collectable metric but uses the global registry
|
||||
Register = defaultRegistry.Register
|
||||
|
||||
// Registerer exposes the global registerer
|
||||
Registerer = defaultRegistry.Registerer
|
||||
)
|
||||
|
||||
func init() {
|
||||
//nolint:staticcheck // SA1019 - replacement function still calls prometheus.NewProcessCollector().
|
||||
RawMustRegister(prometheus.NewProcessCollector(prometheus.ProcessCollectorOpts{}))
|
||||
//nolint:staticcheck // SA1019 - replacement function still calls prometheus.NewGoCollector().
|
||||
RawMustRegister(prometheus.NewGoCollector())
|
||||
RawMustRegister(collectors.NewProcessCollector(collectors.ProcessCollectorOpts{}))
|
||||
RawMustRegister(collectors.NewGoCollector(collectors.WithGoCollectorRuntimeMetrics(collectors.MetricsAll)))
|
||||
defaultRegistry.RegisterMetaMetrics()
|
||||
}
|
||||
|
||||
// Handler returns an HTTP handler for the DefaultGatherer. It is
|
||||
|
||||
29
vendor/k8s.io/component-base/metrics/metric.go
generated
vendored
29
vendor/k8s.io/component-base/metrics/metric.go
generated
vendored
@@ -72,6 +72,7 @@ type lazyMetric struct {
|
||||
markDeprecationOnce sync.Once
|
||||
createOnce sync.Once
|
||||
self kubeCollector
|
||||
stabilityLevel StabilityLevel
|
||||
}
|
||||
|
||||
func (r *lazyMetric) IsCreated() bool {
|
||||
@@ -149,6 +150,7 @@ func (r *lazyMetric) Create(version *semver.Version) bool {
|
||||
if r.IsHidden() {
|
||||
return false
|
||||
}
|
||||
|
||||
r.createOnce.Do(func() {
|
||||
r.createLock.Lock()
|
||||
defer r.createLock.Unlock()
|
||||
@@ -159,6 +161,13 @@ func (r *lazyMetric) Create(version *semver.Version) bool {
|
||||
r.self.initializeMetric()
|
||||
}
|
||||
})
|
||||
sl := r.stabilityLevel
|
||||
deprecatedV := r.self.DeprecatedVersion()
|
||||
dv := ""
|
||||
if deprecatedV != nil {
|
||||
dv = deprecatedV.String()
|
||||
}
|
||||
registeredMetrics.WithLabelValues(string(sl), dv).Inc()
|
||||
return r.IsCreated()
|
||||
}
|
||||
|
||||
@@ -207,7 +216,6 @@ var noopCounterVec = &prometheus.CounterVec{}
|
||||
var noopHistogramVec = &prometheus.HistogramVec{}
|
||||
var noopTimingHistogramVec = &promext.TimingHistogramVec{}
|
||||
var noopGaugeVec = &prometheus.GaugeVec{}
|
||||
var noopObserverVec = &noopObserverVector{}
|
||||
|
||||
// just use a convenience struct for all the no-ops
|
||||
var noop = &noopMetric{}
|
||||
@@ -226,22 +234,3 @@ func (noopMetric) Desc() *prometheus.Desc { return nil }
|
||||
func (noopMetric) Write(*dto.Metric) error { return nil }
|
||||
func (noopMetric) Describe(chan<- *prometheus.Desc) {}
|
||||
func (noopMetric) Collect(chan<- prometheus.Metric) {}
|
||||
|
||||
type noopObserverVector struct{}
|
||||
|
||||
func (noopObserverVector) GetMetricWith(prometheus.Labels) (prometheus.Observer, error) {
|
||||
return noop, nil
|
||||
}
|
||||
func (noopObserverVector) GetMetricWithLabelValues(...string) (prometheus.Observer, error) {
|
||||
return noop, nil
|
||||
}
|
||||
func (noopObserverVector) With(prometheus.Labels) prometheus.Observer { return noop }
|
||||
func (noopObserverVector) WithLabelValues(...string) prometheus.Observer { return noop }
|
||||
func (noopObserverVector) CurryWith(prometheus.Labels) (prometheus.ObserverVec, error) {
|
||||
return noopObserverVec, nil
|
||||
}
|
||||
func (noopObserverVector) MustCurryWith(prometheus.Labels) prometheus.ObserverVec {
|
||||
return noopObserverVec
|
||||
}
|
||||
func (noopObserverVector) Describe(chan<- *prometheus.Desc) {}
|
||||
func (noopObserverVector) Collect(chan<- prometheus.Metric) {}
|
||||
|
||||
6
vendor/k8s.io/component-base/metrics/opts.go
generated
vendored
6
vendor/k8s.io/component-base/metrics/opts.go
generated
vendored
@@ -66,9 +66,15 @@ func BuildFQName(namespace, subsystem, name string) string {
|
||||
type StabilityLevel string
|
||||
|
||||
const (
|
||||
// INTERNAL metrics have no stability guarantees, as such, labels may
|
||||
// be arbitrarily added/removed and the metric may be deleted at any time.
|
||||
INTERNAL StabilityLevel = "INTERNAL"
|
||||
// ALPHA metrics have no stability guarantees, as such, labels may
|
||||
// be arbitrarily added/removed and the metric may be deleted at any time.
|
||||
ALPHA StabilityLevel = "ALPHA"
|
||||
// BETA metrics are governed by the deprecation policy outlined in by
|
||||
// the control plane metrics stability KEP.
|
||||
BETA StabilityLevel = "BETA"
|
||||
// STABLE metrics are guaranteed not be mutated and removal is governed by
|
||||
// the deprecation policy outlined in by the control plane metrics stability KEP.
|
||||
STABLE StabilityLevel = "STABLE"
|
||||
|
||||
53
vendor/k8s.io/component-base/metrics/prometheus/feature/metrics.go
generated
vendored
Normal file
53
vendor/k8s.io/component-base/metrics/prometheus/feature/metrics.go
generated
vendored
Normal file
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
Copyright 2022 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 feature
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
k8smetrics "k8s.io/component-base/metrics"
|
||||
"k8s.io/component-base/metrics/legacyregistry"
|
||||
)
|
||||
|
||||
var (
|
||||
// featureInfo is a Prometheus Gauge metrics used for recording the enablement of a k8s feature.
|
||||
featureInfo = k8smetrics.NewGaugeVec(
|
||||
&k8smetrics.GaugeOpts{
|
||||
Namespace: "kubernetes",
|
||||
Name: "feature_enabled",
|
||||
Help: "This metric records the data about the stage and enablement of a k8s feature.",
|
||||
StabilityLevel: k8smetrics.ALPHA,
|
||||
},
|
||||
[]string{"name", "stage"},
|
||||
)
|
||||
)
|
||||
|
||||
func init() {
|
||||
legacyregistry.MustRegister(featureInfo)
|
||||
}
|
||||
|
||||
func ResetFeatureInfoMetric() {
|
||||
featureInfo.Reset()
|
||||
}
|
||||
|
||||
func RecordFeatureInfo(ctx context.Context, name string, stage string, enabled bool) {
|
||||
value := 0.0
|
||||
if enabled {
|
||||
value = 1.0
|
||||
}
|
||||
featureInfo.WithContext(ctx).WithLabelValues(name, stage).Set(value)
|
||||
}
|
||||
56
vendor/k8s.io/component-base/metrics/registry.go
generated
vendored
56
vendor/k8s.io/component-base/metrics/registry.go
generated
vendored
@@ -32,10 +32,35 @@ import (
|
||||
var (
|
||||
showHiddenOnce sync.Once
|
||||
disabledMetricsLock sync.RWMutex
|
||||
showHidden atomic.Value
|
||||
showHidden atomic.Bool
|
||||
registries []*kubeRegistry // stores all registries created by NewKubeRegistry()
|
||||
registriesLock sync.RWMutex
|
||||
disabledMetrics = map[string]struct{}{}
|
||||
|
||||
registeredMetrics = NewCounterVec(
|
||||
&CounterOpts{
|
||||
Name: "registered_metric_total",
|
||||
Help: "The count of registered metrics broken by stability level and deprecation version.",
|
||||
StabilityLevel: ALPHA,
|
||||
},
|
||||
[]string{"stability_level", "deprecated_version"},
|
||||
)
|
||||
|
||||
disabledMetricsTotal = NewCounter(
|
||||
&CounterOpts{
|
||||
Name: "disabled_metric_total",
|
||||
Help: "The count of disabled metrics.",
|
||||
StabilityLevel: ALPHA,
|
||||
},
|
||||
)
|
||||
|
||||
hiddenMetricsTotal = NewCounter(
|
||||
&CounterOpts{
|
||||
Name: "hidden_metric_total",
|
||||
Help: "The count of hidden metrics.",
|
||||
StabilityLevel: ALPHA,
|
||||
},
|
||||
)
|
||||
)
|
||||
|
||||
// shouldHide be used to check if a specific metric with deprecated version should be hidden
|
||||
@@ -67,6 +92,7 @@ func SetDisabledMetric(name string) {
|
||||
disabledMetricsLock.Lock()
|
||||
defer disabledMetricsLock.Unlock()
|
||||
disabledMetrics[name] = struct{}{}
|
||||
disabledMetricsTotal.Inc()
|
||||
}
|
||||
|
||||
// SetShowHidden will enable showing hidden metrics. This will no-opt
|
||||
@@ -87,7 +113,7 @@ func SetShowHidden() {
|
||||
// is enabled. While the primary usecase for this is internal (to determine
|
||||
// registration behavior) this can also be used to introspect
|
||||
func ShouldShowHidden() bool {
|
||||
return showHidden.Load() != nil && showHidden.Load().(bool)
|
||||
return showHidden.Load()
|
||||
}
|
||||
|
||||
// Registerable is an interface for a collector metric which we
|
||||
@@ -129,6 +155,12 @@ type KubeRegistry interface {
|
||||
// Reset invokes the Reset() function on all items in the registry
|
||||
// which are added as resettables.
|
||||
Reset()
|
||||
// RegisterMetaMetrics registers metrics about the number of registered metrics.
|
||||
RegisterMetaMetrics()
|
||||
// Registerer exposes the underlying prometheus registerer
|
||||
Registerer() prometheus.Registerer
|
||||
// Gatherer exposes the underlying prometheus gatherer
|
||||
Gatherer() prometheus.Gatherer
|
||||
}
|
||||
|
||||
// kubeRegistry is a wrapper around a prometheus registry-type object. Upon initialization
|
||||
@@ -160,6 +192,16 @@ func (kr *kubeRegistry) Register(c Registerable) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Registerer exposes the underlying prometheus.Registerer
|
||||
func (kr *kubeRegistry) Registerer() prometheus.Registerer {
|
||||
return kr.PromRegistry
|
||||
}
|
||||
|
||||
// Gatherer exposes the underlying prometheus.Gatherer
|
||||
func (kr *kubeRegistry) Gatherer() prometheus.Gatherer {
|
||||
return kr.PromRegistry
|
||||
}
|
||||
|
||||
// MustRegister works like Register but registers any number of
|
||||
// Collectors and panics upon the first registration that causes an
|
||||
// error.
|
||||
@@ -250,6 +292,7 @@ func (kr *kubeRegistry) trackHiddenCollector(c Registerable) {
|
||||
defer kr.hiddenCollectorsLock.Unlock()
|
||||
|
||||
kr.hiddenCollectors[c.FQName()] = c
|
||||
hiddenMetricsTotal.Inc()
|
||||
}
|
||||
|
||||
// trackStableCollectors stores all custom collectors.
|
||||
@@ -329,9 +372,14 @@ func newKubeRegistry(v apimachineryversion.Info) *kubeRegistry {
|
||||
return r
|
||||
}
|
||||
|
||||
// NewKubeRegistry creates a new vanilla Registry without any Collectors
|
||||
// pre-registered.
|
||||
// NewKubeRegistry creates a new vanilla Registry
|
||||
func NewKubeRegistry() KubeRegistry {
|
||||
r := newKubeRegistry(BuildVersion())
|
||||
return r
|
||||
}
|
||||
|
||||
func (r *kubeRegistry) RegisterMetaMetrics() {
|
||||
r.MustRegister(registeredMetrics)
|
||||
r.MustRegister(disabledMetricsTotal)
|
||||
r.MustRegister(hiddenMetricsTotal)
|
||||
}
|
||||
|
||||
4
vendor/k8s.io/component-base/metrics/summary.go
generated
vendored
4
vendor/k8s.io/component-base/metrics/summary.go
generated
vendored
@@ -49,7 +49,7 @@ func NewSummary(opts *SummaryOpts) *Summary {
|
||||
|
||||
s := &Summary{
|
||||
SummaryOpts: opts,
|
||||
lazyMetric: lazyMetric{},
|
||||
lazyMetric: lazyMetric{stabilityLevel: opts.StabilityLevel},
|
||||
}
|
||||
s.setPrometheusSummary(noopMetric{})
|
||||
s.lazyInit(s, BuildFQName(opts.Namespace, opts.Subsystem, opts.Name))
|
||||
@@ -118,7 +118,7 @@ func NewSummaryVec(opts *SummaryOpts, labels []string) *SummaryVec {
|
||||
v := &SummaryVec{
|
||||
SummaryOpts: opts,
|
||||
originalLabels: labels,
|
||||
lazyMetric: lazyMetric{},
|
||||
lazyMetric: lazyMetric{stabilityLevel: opts.StabilityLevel},
|
||||
}
|
||||
v.lazyInit(v, fqName)
|
||||
return v
|
||||
|
||||
7
vendor/k8s.io/component-base/metrics/timing_histogram.go
generated
vendored
7
vendor/k8s.io/component-base/metrics/timing_histogram.go
generated
vendored
@@ -57,7 +57,7 @@ func NewTestableTimingHistogram(nowFunc func() time.Time, opts *TimingHistogramO
|
||||
h := &TimingHistogram{
|
||||
TimingHistogramOpts: opts,
|
||||
nowFunc: nowFunc,
|
||||
lazyMetric: lazyMetric{},
|
||||
lazyMetric: lazyMetric{stabilityLevel: opts.StabilityLevel},
|
||||
}
|
||||
h.setPrometheusHistogram(noopMetric{})
|
||||
h.lazyInit(h, BuildFQName(opts.Namespace, opts.Subsystem, opts.Name))
|
||||
@@ -136,7 +136,7 @@ func NewTestableTimingHistogramVec(nowFunc func() time.Time, opts *TimingHistogr
|
||||
TimingHistogramOpts: opts,
|
||||
nowFunc: nowFunc,
|
||||
originalLabels: labels,
|
||||
lazyMetric: lazyMetric{},
|
||||
lazyMetric: lazyMetric{stabilityLevel: opts.StabilityLevel},
|
||||
}
|
||||
v.lazyInit(v, fqName)
|
||||
return v
|
||||
@@ -177,6 +177,9 @@ func (v *TimingHistogramVec) WithLabelValuesChecked(lvs ...string) (GaugeMetric,
|
||||
v.LabelValueAllowLists.ConstrainToAllowedList(v.originalLabels, lvs)
|
||||
}
|
||||
ops, err := v.TimingHistogramVec.GetMetricWithLabelValues(lvs...)
|
||||
if err != nil {
|
||||
return noop, err
|
||||
}
|
||||
return ops.(GaugeMetric), err
|
||||
}
|
||||
|
||||
|
||||
10
vendor/k8s.io/component-base/metrics/value.go
generated
vendored
10
vendor/k8s.io/component-base/metrics/value.go
generated
vendored
@@ -47,6 +47,16 @@ func NewLazyConstMetric(desc *Desc, valueType ValueType, value float64, labelVal
|
||||
return prometheus.MustNewConstMetric(desc.toPrometheusDesc(), valueType.toPromValueType(), value, labelValues...)
|
||||
}
|
||||
|
||||
// NewConstMetric is a helper of NewConstMetric.
|
||||
//
|
||||
// Note: If the metrics described by the desc is hidden, the metrics will not be created.
|
||||
func NewConstMetric(desc *Desc, valueType ValueType, value float64, labelValues ...string) (Metric, error) {
|
||||
if desc.IsHidden() {
|
||||
return nil, nil
|
||||
}
|
||||
return prometheus.NewConstMetric(desc.toPrometheusDesc(), valueType.toPromValueType(), value, labelValues...)
|
||||
}
|
||||
|
||||
// NewLazyMetricWithTimestamp is a helper of NewMetricWithTimestamp.
|
||||
//
|
||||
// Warning: the Metric 'm' must be the one created by NewLazyConstMetric(),
|
||||
|
||||
6
vendor/k8s.io/component-base/metrics/wrappers.go
generated
vendored
6
vendor/k8s.io/component-base/metrics/wrappers.go
generated
vendored
@@ -145,6 +145,12 @@ type Gatherer interface {
|
||||
prometheus.Gatherer
|
||||
}
|
||||
|
||||
// Registerer is the interface for the part of a registry in charge of registering
|
||||
// the collected metrics.
|
||||
type Registerer interface {
|
||||
prometheus.Registerer
|
||||
}
|
||||
|
||||
// GaugeFunc is a Gauge whose value is determined at collect time by calling a
|
||||
// provided function.
|
||||
//
|
||||
|
||||
30
vendor/k8s.io/klog/v2/contextual.go
generated
vendored
30
vendor/k8s.io/klog/v2/contextual.go
generated
vendored
@@ -70,11 +70,14 @@ func SetLogger(logger logr.Logger) {
|
||||
// routing log entries through klogr into klog and then into the actual Logger
|
||||
// backend.
|
||||
func SetLoggerWithOptions(logger logr.Logger, opts ...LoggerOption) {
|
||||
logging.logger = &logger
|
||||
logging.loggerOptions = loggerOptions{}
|
||||
for _, opt := range opts {
|
||||
opt(&logging.loggerOptions)
|
||||
}
|
||||
logging.logger = &logWriter{
|
||||
Logger: logger,
|
||||
writeKlogBuffer: logging.loggerOptions.writeKlogBuffer,
|
||||
}
|
||||
}
|
||||
|
||||
// ContextualLogger determines whether the logger passed to
|
||||
@@ -93,6 +96,22 @@ func FlushLogger(flush func()) LoggerOption {
|
||||
}
|
||||
}
|
||||
|
||||
// WriteKlogBuffer sets a callback that will be invoked by klog to write output
|
||||
// produced by non-structured log calls like Infof.
|
||||
//
|
||||
// The buffer will contain exactly the same data that klog normally would write
|
||||
// into its own output stream(s). In particular this includes the header, if
|
||||
// klog is configured to write one. The callback then can divert that data into
|
||||
// its own output streams. The buffer may or may not end in a line break.
|
||||
//
|
||||
// Without such a callback, klog will call the logger's Info or Error method
|
||||
// with just the message string (i.e. no header).
|
||||
func WriteKlogBuffer(write func([]byte)) LoggerOption {
|
||||
return func(o *loggerOptions) {
|
||||
o.writeKlogBuffer = write
|
||||
}
|
||||
}
|
||||
|
||||
// LoggerOption implements the functional parameter paradigm for
|
||||
// SetLoggerWithOptions.
|
||||
type LoggerOption func(o *loggerOptions)
|
||||
@@ -100,6 +119,13 @@ type LoggerOption func(o *loggerOptions)
|
||||
type loggerOptions struct {
|
||||
contextualLogger bool
|
||||
flush func()
|
||||
writeKlogBuffer func([]byte)
|
||||
}
|
||||
|
||||
// logWriter combines a logger (always set) with a write callback (optional).
|
||||
type logWriter struct {
|
||||
Logger
|
||||
writeKlogBuffer func([]byte)
|
||||
}
|
||||
|
||||
// ClearLogger removes a backing Logger implementation if one was set earlier
|
||||
@@ -152,7 +178,7 @@ func Background() Logger {
|
||||
if logging.loggerOptions.contextualLogger {
|
||||
// Is non-nil because logging.loggerOptions.contextualLogger is
|
||||
// only true if a logger was set.
|
||||
return *logging.logger
|
||||
return logging.logger.Logger
|
||||
}
|
||||
|
||||
return klogLogger
|
||||
|
||||
75
vendor/k8s.io/klog/v2/internal/buffer/buffer.go
generated
vendored
75
vendor/k8s.io/klog/v2/internal/buffer/buffer.go
generated
vendored
@@ -40,44 +40,33 @@ type Buffer struct {
|
||||
next *Buffer
|
||||
}
|
||||
|
||||
// Buffers manages the reuse of individual buffer instances. It is thread-safe.
|
||||
type Buffers struct {
|
||||
// mu protects the free list. It is separate from the main mutex
|
||||
// so buffers can be grabbed and printed to without holding the main lock,
|
||||
// for better parallelization.
|
||||
mu sync.Mutex
|
||||
|
||||
// freeList is a list of byte buffers, maintained under mu.
|
||||
freeList *Buffer
|
||||
var buffers = sync.Pool{
|
||||
New: func() interface{} {
|
||||
return new(Buffer)
|
||||
},
|
||||
}
|
||||
|
||||
// GetBuffer returns a new, ready-to-use buffer.
|
||||
func (bl *Buffers) GetBuffer() *Buffer {
|
||||
bl.mu.Lock()
|
||||
b := bl.freeList
|
||||
if b != nil {
|
||||
bl.freeList = b.next
|
||||
}
|
||||
bl.mu.Unlock()
|
||||
if b == nil {
|
||||
b = new(Buffer)
|
||||
} else {
|
||||
b.next = nil
|
||||
b.Reset()
|
||||
}
|
||||
func GetBuffer() *Buffer {
|
||||
b := buffers.Get().(*Buffer)
|
||||
b.Reset()
|
||||
return b
|
||||
}
|
||||
|
||||
// PutBuffer returns a buffer to the free list.
|
||||
func (bl *Buffers) PutBuffer(b *Buffer) {
|
||||
func PutBuffer(b *Buffer) {
|
||||
if b.Len() >= 256 {
|
||||
// Let big buffers die a natural death.
|
||||
// Let big buffers die a natural death, without relying on
|
||||
// sync.Pool behavior. The documentation implies that items may
|
||||
// get deallocated while stored there ("If the Pool holds the
|
||||
// only reference when this [= be removed automatically]
|
||||
// happens, the item might be deallocated."), but
|
||||
// https://github.com/golang/go/issues/23199 leans more towards
|
||||
// having such a size limit.
|
||||
return
|
||||
}
|
||||
bl.mu.Lock()
|
||||
b.next = bl.freeList
|
||||
bl.freeList = b
|
||||
bl.mu.Unlock()
|
||||
|
||||
buffers.Put(b)
|
||||
}
|
||||
|
||||
// Some custom tiny helper functions to print the log header efficiently.
|
||||
@@ -121,7 +110,8 @@ func (buf *Buffer) someDigits(i, d int) int {
|
||||
return copy(buf.Tmp[i:], buf.Tmp[j:])
|
||||
}
|
||||
|
||||
// FormatHeader formats a log header using the provided file name and line number.
|
||||
// FormatHeader formats a log header using the provided file name and line number
|
||||
// and writes it into the buffer.
|
||||
func (buf *Buffer) FormatHeader(s severity.Severity, file string, line int, now time.Time) {
|
||||
if line < 0 {
|
||||
line = 0 // not a real line number, but acceptable to someDigits
|
||||
@@ -157,3 +147,30 @@ func (buf *Buffer) FormatHeader(s severity.Severity, file string, line int, now
|
||||
buf.Tmp[n+2] = ' '
|
||||
buf.Write(buf.Tmp[:n+3])
|
||||
}
|
||||
|
||||
// SprintHeader formats a log header and returns a string. This is a simpler
|
||||
// version of FormatHeader for use in ktesting.
|
||||
func (buf *Buffer) SprintHeader(s severity.Severity, now time.Time) string {
|
||||
if s > severity.FatalLog {
|
||||
s = severity.InfoLog // for safety.
|
||||
}
|
||||
|
||||
// Avoid Fprintf, for speed. The format is so simple that we can do it quickly by hand.
|
||||
// It's worth about 3X. Fprintf is hard.
|
||||
_, month, day := now.Date()
|
||||
hour, minute, second := now.Clock()
|
||||
// Lmmdd hh:mm:ss.uuuuuu threadid file:line]
|
||||
buf.Tmp[0] = severity.Char[s]
|
||||
buf.twoDigits(1, int(month))
|
||||
buf.twoDigits(3, day)
|
||||
buf.Tmp[5] = ' '
|
||||
buf.twoDigits(6, hour)
|
||||
buf.Tmp[8] = ':'
|
||||
buf.twoDigits(9, minute)
|
||||
buf.Tmp[11] = ':'
|
||||
buf.twoDigits(12, second)
|
||||
buf.Tmp[14] = '.'
|
||||
buf.nDigits(6, 15, now.Nanosecond()/1000, '0')
|
||||
buf.Tmp[21] = ']'
|
||||
return string(buf.Tmp[:22])
|
||||
}
|
||||
|
||||
215
vendor/k8s.io/klog/v2/internal/serialize/keyvalues.go
generated
vendored
215
vendor/k8s.io/klog/v2/internal/serialize/keyvalues.go
generated
vendored
@@ -24,6 +24,10 @@ import (
|
||||
"github.com/go-logr/logr"
|
||||
)
|
||||
|
||||
type textWriter interface {
|
||||
WriteText(*bytes.Buffer)
|
||||
}
|
||||
|
||||
// WithValues implements LogSink.WithValues. The old key/value pairs are
|
||||
// assumed to be well-formed, the new ones are checked and padded if
|
||||
// necessary. It returns a new slice.
|
||||
@@ -91,11 +95,66 @@ func MergeKVs(first, second []interface{}) []interface{} {
|
||||
return merged
|
||||
}
|
||||
|
||||
type Formatter struct {
|
||||
AnyToStringHook AnyToStringFunc
|
||||
}
|
||||
|
||||
type AnyToStringFunc func(v interface{}) string
|
||||
|
||||
// MergeKVsInto is a variant of MergeKVs which directly formats the key/value
|
||||
// pairs into a buffer.
|
||||
func (f Formatter) MergeAndFormatKVs(b *bytes.Buffer, first, second []interface{}) {
|
||||
if len(first) == 0 && len(second) == 0 {
|
||||
// Nothing to do at all.
|
||||
return
|
||||
}
|
||||
|
||||
if len(first) == 0 && len(second)%2 == 0 {
|
||||
// Nothing to be overridden, second slice is well-formed
|
||||
// and can be used directly.
|
||||
for i := 0; i < len(second); i += 2 {
|
||||
f.KVFormat(b, second[i], second[i+1])
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Determine which keys are in the second slice so that we can skip
|
||||
// them when iterating over the first one. The code intentionally
|
||||
// favors performance over completeness: we assume that keys are string
|
||||
// constants and thus compare equal when the string values are equal. A
|
||||
// string constant being overridden by, for example, a fmt.Stringer is
|
||||
// not handled.
|
||||
overrides := map[interface{}]bool{}
|
||||
for i := 0; i < len(second); i += 2 {
|
||||
overrides[second[i]] = true
|
||||
}
|
||||
for i := 0; i < len(first); i += 2 {
|
||||
key := first[i]
|
||||
if overrides[key] {
|
||||
continue
|
||||
}
|
||||
f.KVFormat(b, key, first[i+1])
|
||||
}
|
||||
// Round down.
|
||||
l := len(second)
|
||||
l = l / 2 * 2
|
||||
for i := 1; i < l; i += 2 {
|
||||
f.KVFormat(b, second[i-1], second[i])
|
||||
}
|
||||
if len(second)%2 == 1 {
|
||||
f.KVFormat(b, second[len(second)-1], missingValue)
|
||||
}
|
||||
}
|
||||
|
||||
func MergeAndFormatKVs(b *bytes.Buffer, first, second []interface{}) {
|
||||
Formatter{}.MergeAndFormatKVs(b, first, second)
|
||||
}
|
||||
|
||||
const missingValue = "(MISSING)"
|
||||
|
||||
// KVListFormat serializes all key/value pairs into the provided buffer.
|
||||
// A space gets inserted before the first pair and between each pair.
|
||||
func KVListFormat(b *bytes.Buffer, keysAndValues ...interface{}) {
|
||||
func (f Formatter) KVListFormat(b *bytes.Buffer, keysAndValues ...interface{}) {
|
||||
for i := 0; i < len(keysAndValues); i += 2 {
|
||||
var v interface{}
|
||||
k := keysAndValues[i]
|
||||
@@ -104,69 +163,93 @@ func KVListFormat(b *bytes.Buffer, keysAndValues ...interface{}) {
|
||||
} else {
|
||||
v = missingValue
|
||||
}
|
||||
b.WriteByte(' ')
|
||||
// Keys are assumed to be well-formed according to
|
||||
// https://github.com/kubernetes/community/blob/master/contributors/devel/sig-instrumentation/migration-to-structured-logging.md#name-arguments
|
||||
// for the sake of performance. Keys with spaces,
|
||||
// special characters, etc. will break parsing.
|
||||
if sK, ok := k.(string); ok {
|
||||
// Avoid one allocation when the key is a string, which
|
||||
// normally it should be.
|
||||
b.WriteString(sK)
|
||||
} else {
|
||||
b.WriteString(fmt.Sprintf("%s", k))
|
||||
}
|
||||
|
||||
// The type checks are sorted so that more frequently used ones
|
||||
// come first because that is then faster in the common
|
||||
// cases. In Kubernetes, ObjectRef (a Stringer) is more common
|
||||
// than plain strings
|
||||
// (https://github.com/kubernetes/kubernetes/pull/106594#issuecomment-975526235).
|
||||
switch v := v.(type) {
|
||||
case fmt.Stringer:
|
||||
writeStringValue(b, true, StringerToString(v))
|
||||
case string:
|
||||
writeStringValue(b, true, v)
|
||||
case error:
|
||||
writeStringValue(b, true, ErrorToString(v))
|
||||
case logr.Marshaler:
|
||||
value := MarshalerToValue(v)
|
||||
// A marshaler that returns a string is useful for
|
||||
// delayed formatting of complex values. We treat this
|
||||
// case like a normal string. This is useful for
|
||||
// multi-line support.
|
||||
//
|
||||
// We could do this by recursively formatting a value,
|
||||
// but that comes with the risk of infinite recursion
|
||||
// if a marshaler returns itself. Instead we call it
|
||||
// only once and rely on it returning the intended
|
||||
// value directly.
|
||||
switch value := value.(type) {
|
||||
case string:
|
||||
writeStringValue(b, true, value)
|
||||
default:
|
||||
writeStringValue(b, false, fmt.Sprintf("%+v", value))
|
||||
}
|
||||
case []byte:
|
||||
// In https://github.com/kubernetes/klog/pull/237 it was decided
|
||||
// to format byte slices with "%+q". The advantages of that are:
|
||||
// - readable output if the bytes happen to be printable
|
||||
// - non-printable bytes get represented as unicode escape
|
||||
// sequences (\uxxxx)
|
||||
//
|
||||
// The downsides are that we cannot use the faster
|
||||
// strconv.Quote here and that multi-line output is not
|
||||
// supported. If developers know that a byte array is
|
||||
// printable and they want multi-line output, they can
|
||||
// convert the value to string before logging it.
|
||||
b.WriteByte('=')
|
||||
b.WriteString(fmt.Sprintf("%+q", v))
|
||||
default:
|
||||
writeStringValue(b, false, fmt.Sprintf("%+v", v))
|
||||
}
|
||||
f.KVFormat(b, k, v)
|
||||
}
|
||||
}
|
||||
|
||||
func KVListFormat(b *bytes.Buffer, keysAndValues ...interface{}) {
|
||||
Formatter{}.KVListFormat(b, keysAndValues...)
|
||||
}
|
||||
|
||||
// KVFormat serializes one key/value pair into the provided buffer.
|
||||
// A space gets inserted before the pair.
|
||||
func (f Formatter) KVFormat(b *bytes.Buffer, k, v interface{}) {
|
||||
b.WriteByte(' ')
|
||||
// Keys are assumed to be well-formed according to
|
||||
// https://github.com/kubernetes/community/blob/master/contributors/devel/sig-instrumentation/migration-to-structured-logging.md#name-arguments
|
||||
// for the sake of performance. Keys with spaces,
|
||||
// special characters, etc. will break parsing.
|
||||
if sK, ok := k.(string); ok {
|
||||
// Avoid one allocation when the key is a string, which
|
||||
// normally it should be.
|
||||
b.WriteString(sK)
|
||||
} else {
|
||||
b.WriteString(fmt.Sprintf("%s", k))
|
||||
}
|
||||
|
||||
// The type checks are sorted so that more frequently used ones
|
||||
// come first because that is then faster in the common
|
||||
// cases. In Kubernetes, ObjectRef (a Stringer) is more common
|
||||
// than plain strings
|
||||
// (https://github.com/kubernetes/kubernetes/pull/106594#issuecomment-975526235).
|
||||
switch v := v.(type) {
|
||||
case textWriter:
|
||||
writeTextWriterValue(b, v)
|
||||
case fmt.Stringer:
|
||||
writeStringValue(b, true, StringerToString(v))
|
||||
case string:
|
||||
writeStringValue(b, true, v)
|
||||
case error:
|
||||
writeStringValue(b, true, ErrorToString(v))
|
||||
case logr.Marshaler:
|
||||
value := MarshalerToValue(v)
|
||||
// A marshaler that returns a string is useful for
|
||||
// delayed formatting of complex values. We treat this
|
||||
// case like a normal string. This is useful for
|
||||
// multi-line support.
|
||||
//
|
||||
// We could do this by recursively formatting a value,
|
||||
// but that comes with the risk of infinite recursion
|
||||
// if a marshaler returns itself. Instead we call it
|
||||
// only once and rely on it returning the intended
|
||||
// value directly.
|
||||
switch value := value.(type) {
|
||||
case string:
|
||||
writeStringValue(b, true, value)
|
||||
default:
|
||||
writeStringValue(b, false, f.AnyToString(value))
|
||||
}
|
||||
case []byte:
|
||||
// In https://github.com/kubernetes/klog/pull/237 it was decided
|
||||
// to format byte slices with "%+q". The advantages of that are:
|
||||
// - readable output if the bytes happen to be printable
|
||||
// - non-printable bytes get represented as unicode escape
|
||||
// sequences (\uxxxx)
|
||||
//
|
||||
// The downsides are that we cannot use the faster
|
||||
// strconv.Quote here and that multi-line output is not
|
||||
// supported. If developers know that a byte array is
|
||||
// printable and they want multi-line output, they can
|
||||
// convert the value to string before logging it.
|
||||
b.WriteByte('=')
|
||||
b.WriteString(fmt.Sprintf("%+q", v))
|
||||
default:
|
||||
writeStringValue(b, false, f.AnyToString(v))
|
||||
}
|
||||
}
|
||||
|
||||
func KVFormat(b *bytes.Buffer, k, v interface{}) {
|
||||
Formatter{}.KVFormat(b, k, v)
|
||||
}
|
||||
|
||||
// AnyToString is the historic fallback formatter.
|
||||
func (f Formatter) AnyToString(v interface{}) string {
|
||||
if f.AnyToStringHook != nil {
|
||||
return f.AnyToStringHook(v)
|
||||
}
|
||||
return fmt.Sprintf("%+v", v)
|
||||
}
|
||||
|
||||
// StringerToString converts a Stringer to a string,
|
||||
// handling panics if they occur.
|
||||
func StringerToString(s fmt.Stringer) (ret string) {
|
||||
@@ -203,6 +286,16 @@ func ErrorToString(err error) (ret string) {
|
||||
return
|
||||
}
|
||||
|
||||
func writeTextWriterValue(b *bytes.Buffer, v textWriter) {
|
||||
b.WriteRune('=')
|
||||
defer func() {
|
||||
if err := recover(); err != nil {
|
||||
fmt.Fprintf(b, `"<panic: %s>"`, err)
|
||||
}
|
||||
}()
|
||||
v.WriteText(b)
|
||||
}
|
||||
|
||||
func writeStringValue(b *bytes.Buffer, quote bool, v string) {
|
||||
data := []byte(v)
|
||||
index := bytes.IndexByte(data, '\n')
|
||||
|
||||
78
vendor/k8s.io/klog/v2/k8s_references.go
generated
vendored
78
vendor/k8s.io/klog/v2/k8s_references.go
generated
vendored
@@ -17,8 +17,10 @@ limitations under the License.
|
||||
package klog
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"strings"
|
||||
|
||||
"github.com/go-logr/logr"
|
||||
)
|
||||
@@ -31,11 +33,30 @@ type ObjectRef struct {
|
||||
|
||||
func (ref ObjectRef) String() string {
|
||||
if ref.Namespace != "" {
|
||||
return fmt.Sprintf("%s/%s", ref.Namespace, ref.Name)
|
||||
var builder strings.Builder
|
||||
builder.Grow(len(ref.Namespace) + len(ref.Name) + 1)
|
||||
builder.WriteString(ref.Namespace)
|
||||
builder.WriteRune('/')
|
||||
builder.WriteString(ref.Name)
|
||||
return builder.String()
|
||||
}
|
||||
return ref.Name
|
||||
}
|
||||
|
||||
func (ref ObjectRef) WriteText(out *bytes.Buffer) {
|
||||
out.WriteRune('"')
|
||||
ref.writeUnquoted(out)
|
||||
out.WriteRune('"')
|
||||
}
|
||||
|
||||
func (ref ObjectRef) writeUnquoted(out *bytes.Buffer) {
|
||||
if ref.Namespace != "" {
|
||||
out.WriteString(ref.Namespace)
|
||||
out.WriteRune('/')
|
||||
}
|
||||
out.WriteString(ref.Name)
|
||||
}
|
||||
|
||||
// MarshalLog ensures that loggers with support for structured output will log
|
||||
// as a struct by removing the String method via a custom type.
|
||||
func (ref ObjectRef) MarshalLog() interface{} {
|
||||
@@ -117,31 +138,31 @@ var _ fmt.Stringer = kobjSlice{}
|
||||
var _ logr.Marshaler = kobjSlice{}
|
||||
|
||||
func (ks kobjSlice) String() string {
|
||||
objectRefs, err := ks.process()
|
||||
if err != nil {
|
||||
return err.Error()
|
||||
objectRefs, errStr := ks.process()
|
||||
if errStr != "" {
|
||||
return errStr
|
||||
}
|
||||
return fmt.Sprintf("%v", objectRefs)
|
||||
}
|
||||
|
||||
func (ks kobjSlice) MarshalLog() interface{} {
|
||||
objectRefs, err := ks.process()
|
||||
if err != nil {
|
||||
return err.Error()
|
||||
objectRefs, errStr := ks.process()
|
||||
if errStr != "" {
|
||||
return errStr
|
||||
}
|
||||
return objectRefs
|
||||
}
|
||||
|
||||
func (ks kobjSlice) process() ([]interface{}, error) {
|
||||
func (ks kobjSlice) process() (objs []interface{}, err string) {
|
||||
s := reflect.ValueOf(ks.arg)
|
||||
switch s.Kind() {
|
||||
case reflect.Invalid:
|
||||
// nil parameter, print as nil.
|
||||
return nil, nil
|
||||
return nil, ""
|
||||
case reflect.Slice:
|
||||
// Okay, handle below.
|
||||
default:
|
||||
return nil, fmt.Errorf("<KObjSlice needs a slice, got type %T>", ks.arg)
|
||||
return nil, fmt.Sprintf("<KObjSlice needs a slice, got type %T>", ks.arg)
|
||||
}
|
||||
objectRefs := make([]interface{}, 0, s.Len())
|
||||
for i := 0; i < s.Len(); i++ {
|
||||
@@ -151,8 +172,41 @@ func (ks kobjSlice) process() ([]interface{}, error) {
|
||||
} else if v, ok := item.(KMetadata); ok {
|
||||
objectRefs = append(objectRefs, KObj(v))
|
||||
} else {
|
||||
return nil, fmt.Errorf("<KObjSlice needs a slice of values implementing KMetadata, got type %T>", item)
|
||||
return nil, fmt.Sprintf("<KObjSlice needs a slice of values implementing KMetadata, got type %T>", item)
|
||||
}
|
||||
}
|
||||
return objectRefs, ""
|
||||
}
|
||||
|
||||
var nilToken = []byte("<nil>")
|
||||
|
||||
func (ks kobjSlice) WriteText(out *bytes.Buffer) {
|
||||
s := reflect.ValueOf(ks.arg)
|
||||
switch s.Kind() {
|
||||
case reflect.Invalid:
|
||||
// nil parameter, print as empty slice.
|
||||
out.WriteString("[]")
|
||||
return
|
||||
case reflect.Slice:
|
||||
// Okay, handle below.
|
||||
default:
|
||||
fmt.Fprintf(out, `"<KObjSlice needs a slice, got type %T>"`, ks.arg)
|
||||
return
|
||||
}
|
||||
out.Write([]byte{'['})
|
||||
defer out.Write([]byte{']'})
|
||||
for i := 0; i < s.Len(); i++ {
|
||||
if i > 0 {
|
||||
out.Write([]byte{' '})
|
||||
}
|
||||
item := s.Index(i).Interface()
|
||||
if item == nil {
|
||||
out.Write(nilToken)
|
||||
} else if v, ok := item.(KMetadata); ok {
|
||||
KObj(v).writeUnquoted(out)
|
||||
} else {
|
||||
fmt.Fprintf(out, "<KObjSlice needs a slice of values implementing KMetadata, got type %T>", item)
|
||||
return
|
||||
}
|
||||
}
|
||||
return objectRefs, nil
|
||||
}
|
||||
|
||||
135
vendor/k8s.io/klog/v2/klog.go
generated
vendored
135
vendor/k8s.io/klog/v2/klog.go
generated
vendored
@@ -91,8 +91,6 @@ import (
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"github.com/go-logr/logr"
|
||||
|
||||
"k8s.io/klog/v2/internal/buffer"
|
||||
"k8s.io/klog/v2/internal/clock"
|
||||
"k8s.io/klog/v2/internal/dbg"
|
||||
@@ -453,7 +451,7 @@ type settings struct {
|
||||
|
||||
// logger is the global Logger chosen by users of klog, nil if
|
||||
// none is available.
|
||||
logger *Logger
|
||||
logger *logWriter
|
||||
|
||||
// loggerOptions contains the options that were supplied for
|
||||
// globalLogger.
|
||||
@@ -525,6 +523,11 @@ func (s settings) deepCopy() settings {
|
||||
}
|
||||
s.vmodule.filter = filter
|
||||
|
||||
if s.logger != nil {
|
||||
logger := *s.logger
|
||||
s.logger = &logger
|
||||
}
|
||||
|
||||
return s
|
||||
}
|
||||
|
||||
@@ -532,11 +535,6 @@ func (s settings) deepCopy() settings {
|
||||
type loggingT struct {
|
||||
settings
|
||||
|
||||
// bufferCache maintains the free list. It uses its own mutex
|
||||
// so buffers can be grabbed and printed to without holding the main lock,
|
||||
// for better parallelization.
|
||||
bufferCache buffer.Buffers
|
||||
|
||||
// flushD holds a flushDaemon that frequently flushes log file buffers.
|
||||
// Uses its own mutex.
|
||||
flushD *flushDaemon
|
||||
@@ -664,7 +662,7 @@ func (l *loggingT) header(s severity.Severity, depth int) (*buffer.Buffer, strin
|
||||
|
||||
// formatHeader formats a log header using the provided file name and line number.
|
||||
func (l *loggingT) formatHeader(s severity.Severity, file string, line int) *buffer.Buffer {
|
||||
buf := l.bufferCache.GetBuffer()
|
||||
buf := buffer.GetBuffer()
|
||||
if l.skipHeaders {
|
||||
return buf
|
||||
}
|
||||
@@ -673,17 +671,18 @@ func (l *loggingT) formatHeader(s severity.Severity, file string, line int) *buf
|
||||
return buf
|
||||
}
|
||||
|
||||
func (l *loggingT) println(s severity.Severity, logger *logr.Logger, filter LogFilter, args ...interface{}) {
|
||||
func (l *loggingT) println(s severity.Severity, logger *logWriter, filter LogFilter, args ...interface{}) {
|
||||
l.printlnDepth(s, logger, filter, 1, args...)
|
||||
}
|
||||
|
||||
func (l *loggingT) printlnDepth(s severity.Severity, logger *logr.Logger, filter LogFilter, depth int, args ...interface{}) {
|
||||
func (l *loggingT) printlnDepth(s severity.Severity, logger *logWriter, filter LogFilter, depth int, args ...interface{}) {
|
||||
buf, file, line := l.header(s, depth)
|
||||
// if logger is set, we clear the generated header as we rely on the backing
|
||||
// logger implementation to print headers
|
||||
if logger != nil {
|
||||
l.bufferCache.PutBuffer(buf)
|
||||
buf = l.bufferCache.GetBuffer()
|
||||
// If a logger is set and doesn't support writing a formatted buffer,
|
||||
// we clear the generated header as we rely on the backing
|
||||
// logger implementation to print headers.
|
||||
if logger != nil && logger.writeKlogBuffer == nil {
|
||||
buffer.PutBuffer(buf)
|
||||
buf = buffer.GetBuffer()
|
||||
}
|
||||
if filter != nil {
|
||||
args = filter.Filter(args)
|
||||
@@ -692,17 +691,18 @@ func (l *loggingT) printlnDepth(s severity.Severity, logger *logr.Logger, filter
|
||||
l.output(s, logger, buf, depth, file, line, false)
|
||||
}
|
||||
|
||||
func (l *loggingT) print(s severity.Severity, logger *logr.Logger, filter LogFilter, args ...interface{}) {
|
||||
func (l *loggingT) print(s severity.Severity, logger *logWriter, filter LogFilter, args ...interface{}) {
|
||||
l.printDepth(s, logger, filter, 1, args...)
|
||||
}
|
||||
|
||||
func (l *loggingT) printDepth(s severity.Severity, logger *logr.Logger, filter LogFilter, depth int, args ...interface{}) {
|
||||
func (l *loggingT) printDepth(s severity.Severity, logger *logWriter, filter LogFilter, depth int, args ...interface{}) {
|
||||
buf, file, line := l.header(s, depth)
|
||||
// if logr is set, we clear the generated header as we rely on the backing
|
||||
// logr implementation to print headers
|
||||
if logger != nil {
|
||||
l.bufferCache.PutBuffer(buf)
|
||||
buf = l.bufferCache.GetBuffer()
|
||||
// If a logger is set and doesn't support writing a formatted buffer,
|
||||
// we clear the generated header as we rely on the backing
|
||||
// logger implementation to print headers.
|
||||
if logger != nil && logger.writeKlogBuffer == nil {
|
||||
buffer.PutBuffer(buf)
|
||||
buf = buffer.GetBuffer()
|
||||
}
|
||||
if filter != nil {
|
||||
args = filter.Filter(args)
|
||||
@@ -714,17 +714,18 @@ func (l *loggingT) printDepth(s severity.Severity, logger *logr.Logger, filter L
|
||||
l.output(s, logger, buf, depth, file, line, false)
|
||||
}
|
||||
|
||||
func (l *loggingT) printf(s severity.Severity, logger *logr.Logger, filter LogFilter, format string, args ...interface{}) {
|
||||
func (l *loggingT) printf(s severity.Severity, logger *logWriter, filter LogFilter, format string, args ...interface{}) {
|
||||
l.printfDepth(s, logger, filter, 1, format, args...)
|
||||
}
|
||||
|
||||
func (l *loggingT) printfDepth(s severity.Severity, logger *logr.Logger, filter LogFilter, depth int, format string, args ...interface{}) {
|
||||
func (l *loggingT) printfDepth(s severity.Severity, logger *logWriter, filter LogFilter, depth int, format string, args ...interface{}) {
|
||||
buf, file, line := l.header(s, depth)
|
||||
// if logr is set, we clear the generated header as we rely on the backing
|
||||
// logr implementation to print headers
|
||||
if logger != nil {
|
||||
l.bufferCache.PutBuffer(buf)
|
||||
buf = l.bufferCache.GetBuffer()
|
||||
// If a logger is set and doesn't support writing a formatted buffer,
|
||||
// we clear the generated header as we rely on the backing
|
||||
// logger implementation to print headers.
|
||||
if logger != nil && logger.writeKlogBuffer == nil {
|
||||
buffer.PutBuffer(buf)
|
||||
buf = buffer.GetBuffer()
|
||||
}
|
||||
if filter != nil {
|
||||
format, args = filter.FilterF(format, args)
|
||||
@@ -739,13 +740,14 @@ func (l *loggingT) printfDepth(s severity.Severity, logger *logr.Logger, filter
|
||||
// printWithFileLine behaves like print but uses the provided file and line number. If
|
||||
// alsoLogToStderr is true, the log message always appears on standard error; it
|
||||
// will also appear in the log file unless --logtostderr is set.
|
||||
func (l *loggingT) printWithFileLine(s severity.Severity, logger *logr.Logger, filter LogFilter, file string, line int, alsoToStderr bool, args ...interface{}) {
|
||||
func (l *loggingT) printWithFileLine(s severity.Severity, logger *logWriter, filter LogFilter, file string, line int, alsoToStderr bool, args ...interface{}) {
|
||||
buf := l.formatHeader(s, file, line)
|
||||
// if logr is set, we clear the generated header as we rely on the backing
|
||||
// logr implementation to print headers
|
||||
if logger != nil {
|
||||
l.bufferCache.PutBuffer(buf)
|
||||
buf = l.bufferCache.GetBuffer()
|
||||
// If a logger is set and doesn't support writing a formatted buffer,
|
||||
// we clear the generated header as we rely on the backing
|
||||
// logger implementation to print headers.
|
||||
if logger != nil && logger.writeKlogBuffer == nil {
|
||||
buffer.PutBuffer(buf)
|
||||
buf = buffer.GetBuffer()
|
||||
}
|
||||
if filter != nil {
|
||||
args = filter.Filter(args)
|
||||
@@ -758,7 +760,7 @@ func (l *loggingT) printWithFileLine(s severity.Severity, logger *logr.Logger, f
|
||||
}
|
||||
|
||||
// if loggr is specified, will call loggr.Error, otherwise output with logging module.
|
||||
func (l *loggingT) errorS(err error, logger *logr.Logger, filter LogFilter, depth int, msg string, keysAndValues ...interface{}) {
|
||||
func (l *loggingT) errorS(err error, logger *logWriter, filter LogFilter, depth int, msg string, keysAndValues ...interface{}) {
|
||||
if filter != nil {
|
||||
msg, keysAndValues = filter.FilterS(msg, keysAndValues)
|
||||
}
|
||||
@@ -770,7 +772,7 @@ func (l *loggingT) errorS(err error, logger *logr.Logger, filter LogFilter, dept
|
||||
}
|
||||
|
||||
// if loggr is specified, will call loggr.Info, otherwise output with logging module.
|
||||
func (l *loggingT) infoS(logger *logr.Logger, filter LogFilter, depth int, msg string, keysAndValues ...interface{}) {
|
||||
func (l *loggingT) infoS(logger *logWriter, filter LogFilter, depth int, msg string, keysAndValues ...interface{}) {
|
||||
if filter != nil {
|
||||
msg, keysAndValues = filter.FilterS(msg, keysAndValues)
|
||||
}
|
||||
@@ -785,7 +787,7 @@ func (l *loggingT) infoS(logger *logr.Logger, filter LogFilter, depth int, msg s
|
||||
// set log severity by s
|
||||
func (l *loggingT) printS(err error, s severity.Severity, depth int, msg string, keysAndValues ...interface{}) {
|
||||
// Only create a new buffer if we don't have one cached.
|
||||
b := l.bufferCache.GetBuffer()
|
||||
b := buffer.GetBuffer()
|
||||
// The message is always quoted, even if it contains line breaks.
|
||||
// If developers want multi-line output, they should use a small, fixed
|
||||
// message and put the multi-line output into a value.
|
||||
@@ -796,7 +798,7 @@ func (l *loggingT) printS(err error, s severity.Severity, depth int, msg string,
|
||||
serialize.KVListFormat(&b.Buffer, keysAndValues...)
|
||||
l.printDepth(s, logging.logger, nil, depth+1, &b.Buffer)
|
||||
// Make the buffer available for reuse.
|
||||
l.bufferCache.PutBuffer(b)
|
||||
buffer.PutBuffer(b)
|
||||
}
|
||||
|
||||
// redirectBuffer is used to set an alternate destination for the logs
|
||||
@@ -851,7 +853,7 @@ func LogToStderr(stderr bool) {
|
||||
}
|
||||
|
||||
// output writes the data to the log files and releases the buffer.
|
||||
func (l *loggingT) output(s severity.Severity, log *logr.Logger, buf *buffer.Buffer, depth int, file string, line int, alsoToStderr bool) {
|
||||
func (l *loggingT) output(s severity.Severity, logger *logWriter, buf *buffer.Buffer, depth int, file string, line int, alsoToStderr bool) {
|
||||
var isLocked = true
|
||||
l.mu.Lock()
|
||||
defer func() {
|
||||
@@ -867,13 +869,17 @@ func (l *loggingT) output(s severity.Severity, log *logr.Logger, buf *buffer.Buf
|
||||
}
|
||||
}
|
||||
data := buf.Bytes()
|
||||
if log != nil {
|
||||
// TODO: set 'severity' and caller information as structured log info
|
||||
// keysAndValues := []interface{}{"severity", severityName[s], "file", file, "line", line}
|
||||
if s == severity.ErrorLog {
|
||||
logging.logger.WithCallDepth(depth+3).Error(nil, string(data))
|
||||
if logger != nil {
|
||||
if logger.writeKlogBuffer != nil {
|
||||
logger.writeKlogBuffer(data)
|
||||
} else {
|
||||
log.WithCallDepth(depth + 3).Info(string(data))
|
||||
// TODO: set 'severity' and caller information as structured log info
|
||||
// keysAndValues := []interface{}{"severity", severityName[s], "file", file, "line", line}
|
||||
if s == severity.ErrorLog {
|
||||
logger.WithCallDepth(depth+3).Error(nil, string(data))
|
||||
} else {
|
||||
logger.WithCallDepth(depth + 3).Info(string(data))
|
||||
}
|
||||
}
|
||||
} else if l.toStderr {
|
||||
os.Stderr.Write(data)
|
||||
@@ -948,7 +954,7 @@ func (l *loggingT) output(s severity.Severity, log *logr.Logger, buf *buffer.Buf
|
||||
timeoutFlush(ExitFlushTimeout)
|
||||
OsExit(255) // C++ uses -1, which is silly because it's anded with 255 anyway.
|
||||
}
|
||||
l.bufferCache.PutBuffer(buf)
|
||||
buffer.PutBuffer(buf)
|
||||
|
||||
if stats := severityStats[s]; stats != nil {
|
||||
atomic.AddInt64(&stats.lines, 1)
|
||||
@@ -1282,7 +1288,7 @@ func (l *loggingT) setV(pc uintptr) Level {
|
||||
// See the documentation of V for more information.
|
||||
type Verbose struct {
|
||||
enabled bool
|
||||
logr *logr.Logger
|
||||
logger *logWriter
|
||||
}
|
||||
|
||||
func newVerbose(level Level, b bool) Verbose {
|
||||
@@ -1290,7 +1296,7 @@ func newVerbose(level Level, b bool) Verbose {
|
||||
return Verbose{b, nil}
|
||||
}
|
||||
v := logging.logger.V(int(level))
|
||||
return Verbose{b, &v}
|
||||
return Verbose{b, &logWriter{Logger: v, writeKlogBuffer: logging.loggerOptions.writeKlogBuffer}}
|
||||
}
|
||||
|
||||
// V reports whether verbosity at the call site is at least the requested level.
|
||||
@@ -1313,6 +1319,13 @@ func newVerbose(level Level, b bool) Verbose {
|
||||
// less than or equal to the value of the -vmodule pattern matching the source file
|
||||
// containing the call.
|
||||
func V(level Level) Verbose {
|
||||
return VDepth(1, level)
|
||||
}
|
||||
|
||||
// VDepth is a variant of V that accepts a number of stack frames that will be
|
||||
// skipped when checking the -vmodule patterns. VDepth(0) is equivalent to
|
||||
// V().
|
||||
func VDepth(depth int, level Level) Verbose {
|
||||
// This function tries hard to be cheap unless there's work to do.
|
||||
// The fast path is two atomic loads and compares.
|
||||
|
||||
@@ -1329,7 +1342,7 @@ func V(level Level) Verbose {
|
||||
// but if V logging is enabled we're slow anyway.
|
||||
logging.mu.Lock()
|
||||
defer logging.mu.Unlock()
|
||||
if runtime.Callers(2, logging.pcs[:]) == 0 {
|
||||
if runtime.Callers(2+depth, logging.pcs[:]) == 0 {
|
||||
return newVerbose(level, false)
|
||||
}
|
||||
// runtime.Callers returns "return PCs", but we want
|
||||
@@ -1357,7 +1370,7 @@ func (v Verbose) Enabled() bool {
|
||||
// See the documentation of V for usage.
|
||||
func (v Verbose) Info(args ...interface{}) {
|
||||
if v.enabled {
|
||||
logging.print(severity.InfoLog, v.logr, logging.filter, args...)
|
||||
logging.print(severity.InfoLog, v.logger, logging.filter, args...)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1365,7 +1378,7 @@ func (v Verbose) Info(args ...interface{}) {
|
||||
// See the documentation of V for usage.
|
||||
func (v Verbose) InfoDepth(depth int, args ...interface{}) {
|
||||
if v.enabled {
|
||||
logging.printDepth(severity.InfoLog, v.logr, logging.filter, depth, args...)
|
||||
logging.printDepth(severity.InfoLog, v.logger, logging.filter, depth, args...)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1373,7 +1386,7 @@ func (v Verbose) InfoDepth(depth int, args ...interface{}) {
|
||||
// See the documentation of V for usage.
|
||||
func (v Verbose) Infoln(args ...interface{}) {
|
||||
if v.enabled {
|
||||
logging.println(severity.InfoLog, v.logr, logging.filter, args...)
|
||||
logging.println(severity.InfoLog, v.logger, logging.filter, args...)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1381,7 +1394,7 @@ func (v Verbose) Infoln(args ...interface{}) {
|
||||
// See the documentation of V for usage.
|
||||
func (v Verbose) InfolnDepth(depth int, args ...interface{}) {
|
||||
if v.enabled {
|
||||
logging.printlnDepth(severity.InfoLog, v.logr, logging.filter, depth, args...)
|
||||
logging.printlnDepth(severity.InfoLog, v.logger, logging.filter, depth, args...)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1389,7 +1402,7 @@ func (v Verbose) InfolnDepth(depth int, args ...interface{}) {
|
||||
// See the documentation of V for usage.
|
||||
func (v Verbose) Infof(format string, args ...interface{}) {
|
||||
if v.enabled {
|
||||
logging.printf(severity.InfoLog, v.logr, logging.filter, format, args...)
|
||||
logging.printf(severity.InfoLog, v.logger, logging.filter, format, args...)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1397,7 +1410,7 @@ func (v Verbose) Infof(format string, args ...interface{}) {
|
||||
// See the documentation of V for usage.
|
||||
func (v Verbose) InfofDepth(depth int, format string, args ...interface{}) {
|
||||
if v.enabled {
|
||||
logging.printfDepth(severity.InfoLog, v.logr, logging.filter, depth, format, args...)
|
||||
logging.printfDepth(severity.InfoLog, v.logger, logging.filter, depth, format, args...)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1405,7 +1418,7 @@ func (v Verbose) InfofDepth(depth int, format string, args ...interface{}) {
|
||||
// See the documentation of V for usage.
|
||||
func (v Verbose) InfoS(msg string, keysAndValues ...interface{}) {
|
||||
if v.enabled {
|
||||
logging.infoS(v.logr, logging.filter, 0, msg, keysAndValues...)
|
||||
logging.infoS(v.logger, logging.filter, 0, msg, keysAndValues...)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1419,14 +1432,14 @@ func InfoSDepth(depth int, msg string, keysAndValues ...interface{}) {
|
||||
// See the documentation of V for usage.
|
||||
func (v Verbose) InfoSDepth(depth int, msg string, keysAndValues ...interface{}) {
|
||||
if v.enabled {
|
||||
logging.infoS(v.logr, logging.filter, depth, msg, keysAndValues...)
|
||||
logging.infoS(v.logger, logging.filter, depth, msg, keysAndValues...)
|
||||
}
|
||||
}
|
||||
|
||||
// Deprecated: Use ErrorS instead.
|
||||
func (v Verbose) Error(err error, msg string, args ...interface{}) {
|
||||
if v.enabled {
|
||||
logging.errorS(err, v.logr, logging.filter, 0, msg, args...)
|
||||
logging.errorS(err, v.logger, logging.filter, 0, msg, args...)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1434,7 +1447,7 @@ func (v Verbose) Error(err error, msg string, args ...interface{}) {
|
||||
// See the documentation of V for usage.
|
||||
func (v Verbose) ErrorS(err error, msg string, keysAndValues ...interface{}) {
|
||||
if v.enabled {
|
||||
logging.errorS(err, v.logr, logging.filter, 0, msg, keysAndValues...)
|
||||
logging.errorS(err, v.logger, logging.filter, 0, msg, keysAndValues...)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
12
vendor/k8s.io/klog/v2/klogr.go
generated
vendored
12
vendor/k8s.io/klog/v2/klogr.go
generated
vendored
@@ -42,19 +42,21 @@ func (l *klogger) Init(info logr.RuntimeInfo) {
|
||||
l.callDepth += info.CallDepth
|
||||
}
|
||||
|
||||
func (l klogger) Info(level int, msg string, kvList ...interface{}) {
|
||||
func (l *klogger) Info(level int, msg string, kvList ...interface{}) {
|
||||
merged := serialize.MergeKVs(l.values, kvList)
|
||||
if l.prefix != "" {
|
||||
msg = l.prefix + ": " + msg
|
||||
}
|
||||
V(Level(level)).InfoSDepth(l.callDepth+1, msg, merged...)
|
||||
// Skip this function.
|
||||
VDepth(l.callDepth+1, Level(level)).InfoSDepth(l.callDepth+1, msg, merged...)
|
||||
}
|
||||
|
||||
func (l klogger) Enabled(level int) bool {
|
||||
return V(Level(level)).Enabled()
|
||||
func (l *klogger) Enabled(level int) bool {
|
||||
// Skip this function and logr.Logger.Info where Enabled is called.
|
||||
return VDepth(l.callDepth+2, Level(level)).Enabled()
|
||||
}
|
||||
|
||||
func (l klogger) Error(err error, msg string, kvList ...interface{}) {
|
||||
func (l *klogger) Error(err error, msg string, kvList ...interface{}) {
|
||||
merged := serialize.MergeKVs(l.values, kvList)
|
||||
if l.prefix != "" {
|
||||
msg = l.prefix + ": " + msg
|
||||
|
||||
181
vendor/k8s.io/utils/net/ipfamily.go
generated
vendored
Normal file
181
vendor/k8s.io/utils/net/ipfamily.go
generated
vendored
Normal file
@@ -0,0 +1,181 @@
|
||||
/*
|
||||
Copyright 2018 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 net
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
)
|
||||
|
||||
// IPFamily refers to a specific family if not empty, i.e. "4" or "6".
|
||||
type IPFamily string
|
||||
|
||||
// Constants for valid IPFamilys:
|
||||
const (
|
||||
IPFamilyUnknown IPFamily = ""
|
||||
|
||||
IPv4 IPFamily = "4"
|
||||
IPv6 IPFamily = "6"
|
||||
)
|
||||
|
||||
// IsDualStackIPs returns true if:
|
||||
// - all elements of ips are valid
|
||||
// - at least one IP from each family (v4 and v6) is present
|
||||
func IsDualStackIPs(ips []net.IP) (bool, error) {
|
||||
v4Found := false
|
||||
v6Found := false
|
||||
for i, ip := range ips {
|
||||
switch IPFamilyOf(ip) {
|
||||
case IPv4:
|
||||
v4Found = true
|
||||
case IPv6:
|
||||
v6Found = true
|
||||
default:
|
||||
return false, fmt.Errorf("invalid IP[%d]: %v", i, ip)
|
||||
}
|
||||
}
|
||||
|
||||
return (v4Found && v6Found), nil
|
||||
}
|
||||
|
||||
// IsDualStackIPStrings returns true if:
|
||||
// - all elements of ips can be parsed as IPs
|
||||
// - at least one IP from each family (v4 and v6) is present
|
||||
func IsDualStackIPStrings(ips []string) (bool, error) {
|
||||
parsedIPs := make([]net.IP, 0, len(ips))
|
||||
for i, ip := range ips {
|
||||
parsedIP := ParseIPSloppy(ip)
|
||||
if parsedIP == nil {
|
||||
return false, fmt.Errorf("invalid IP[%d]: %v", i, ip)
|
||||
}
|
||||
parsedIPs = append(parsedIPs, parsedIP)
|
||||
}
|
||||
return IsDualStackIPs(parsedIPs)
|
||||
}
|
||||
|
||||
// IsDualStackCIDRs returns true if:
|
||||
// - all elements of cidrs are non-nil
|
||||
// - at least one CIDR from each family (v4 and v6) is present
|
||||
func IsDualStackCIDRs(cidrs []*net.IPNet) (bool, error) {
|
||||
v4Found := false
|
||||
v6Found := false
|
||||
for i, cidr := range cidrs {
|
||||
switch IPFamilyOfCIDR(cidr) {
|
||||
case IPv4:
|
||||
v4Found = true
|
||||
case IPv6:
|
||||
v6Found = true
|
||||
default:
|
||||
return false, fmt.Errorf("invalid CIDR[%d]: %v", i, cidr)
|
||||
}
|
||||
}
|
||||
|
||||
return (v4Found && v6Found), nil
|
||||
}
|
||||
|
||||
// IsDualStackCIDRStrings returns if
|
||||
// - all elements of cidrs can be parsed as CIDRs
|
||||
// - at least one CIDR from each family (v4 and v6) is present
|
||||
func IsDualStackCIDRStrings(cidrs []string) (bool, error) {
|
||||
parsedCIDRs, err := ParseCIDRs(cidrs)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
return IsDualStackCIDRs(parsedCIDRs)
|
||||
}
|
||||
|
||||
// IPFamilyOf returns the IP family of ip, or IPFamilyUnknown if it is invalid.
|
||||
func IPFamilyOf(ip net.IP) IPFamily {
|
||||
switch {
|
||||
case ip.To4() != nil:
|
||||
return IPv4
|
||||
case ip.To16() != nil:
|
||||
return IPv6
|
||||
default:
|
||||
return IPFamilyUnknown
|
||||
}
|
||||
}
|
||||
|
||||
// IPFamilyOfString returns the IP family of ip, or IPFamilyUnknown if ip cannot
|
||||
// be parsed as an IP.
|
||||
func IPFamilyOfString(ip string) IPFamily {
|
||||
return IPFamilyOf(ParseIPSloppy(ip))
|
||||
}
|
||||
|
||||
// IPFamilyOfCIDR returns the IP family of cidr.
|
||||
func IPFamilyOfCIDR(cidr *net.IPNet) IPFamily {
|
||||
if cidr == nil {
|
||||
return IPFamilyUnknown
|
||||
}
|
||||
return IPFamilyOf(cidr.IP)
|
||||
}
|
||||
|
||||
// IPFamilyOfCIDRString returns the IP family of cidr.
|
||||
func IPFamilyOfCIDRString(cidr string) IPFamily {
|
||||
ip, _, _ := ParseCIDRSloppy(cidr)
|
||||
return IPFamilyOf(ip)
|
||||
}
|
||||
|
||||
// IsIPv6 returns true if netIP is IPv6 (and false if it is IPv4, nil, or invalid).
|
||||
func IsIPv6(netIP net.IP) bool {
|
||||
return IPFamilyOf(netIP) == IPv6
|
||||
}
|
||||
|
||||
// IsIPv6String returns true if ip contains a single IPv6 address and nothing else. It
|
||||
// returns false if ip is an empty string, an IPv4 address, or anything else that is not a
|
||||
// single IPv6 address.
|
||||
func IsIPv6String(ip string) bool {
|
||||
return IPFamilyOfString(ip) == IPv6
|
||||
}
|
||||
|
||||
// IsIPv6CIDR returns true if a cidr is a valid IPv6 CIDR. It returns false if cidr is
|
||||
// nil or an IPv4 CIDR. Its behavior is not defined if cidr is invalid.
|
||||
func IsIPv6CIDR(cidr *net.IPNet) bool {
|
||||
return IPFamilyOfCIDR(cidr) == IPv6
|
||||
}
|
||||
|
||||
// IsIPv6CIDRString returns true if cidr contains a single IPv6 CIDR and nothing else. It
|
||||
// returns false if cidr is an empty string, an IPv4 CIDR, or anything else that is not a
|
||||
// single valid IPv6 CIDR.
|
||||
func IsIPv6CIDRString(cidr string) bool {
|
||||
return IPFamilyOfCIDRString(cidr) == IPv6
|
||||
}
|
||||
|
||||
// IsIPv4 returns true if netIP is IPv4 (and false if it is IPv6, nil, or invalid).
|
||||
func IsIPv4(netIP net.IP) bool {
|
||||
return IPFamilyOf(netIP) == IPv4
|
||||
}
|
||||
|
||||
// IsIPv4String returns true if ip contains a single IPv4 address and nothing else. It
|
||||
// returns false if ip is an empty string, an IPv6 address, or anything else that is not a
|
||||
// single IPv4 address.
|
||||
func IsIPv4String(ip string) bool {
|
||||
return IPFamilyOfString(ip) == IPv4
|
||||
}
|
||||
|
||||
// IsIPv4CIDR returns true if cidr is a valid IPv4 CIDR. It returns false if cidr is nil
|
||||
// or an IPv6 CIDR. Its behavior is not defined if cidr is invalid.
|
||||
func IsIPv4CIDR(cidr *net.IPNet) bool {
|
||||
return IPFamilyOfCIDR(cidr) == IPv4
|
||||
}
|
||||
|
||||
// IsIPv4CIDRString returns true if cidr contains a single IPv4 CIDR and nothing else. It
|
||||
// returns false if cidr is an empty string, an IPv6 CIDR, or anything else that is not a
|
||||
// single valid IPv4 CIDR.
|
||||
func IsIPv4CIDRString(cidr string) bool {
|
||||
return IPFamilyOfCIDRString(cidr) == IPv4
|
||||
}
|
||||
126
vendor/k8s.io/utils/net/net.go
generated
vendored
126
vendor/k8s.io/utils/net/net.go
generated
vendored
@@ -29,138 +29,16 @@ import (
|
||||
// order is maintained
|
||||
func ParseCIDRs(cidrsString []string) ([]*net.IPNet, error) {
|
||||
cidrs := make([]*net.IPNet, 0, len(cidrsString))
|
||||
for _, cidrString := range cidrsString {
|
||||
for i, cidrString := range cidrsString {
|
||||
_, cidr, err := ParseCIDRSloppy(cidrString)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to parse cidr value:%q with error:%v", cidrString, err)
|
||||
return nil, fmt.Errorf("invalid CIDR[%d]: %v (%v)", i, cidr, err)
|
||||
}
|
||||
cidrs = append(cidrs, cidr)
|
||||
}
|
||||
return cidrs, nil
|
||||
}
|
||||
|
||||
// IsDualStackIPs returns if a slice of ips is:
|
||||
// - all are valid ips
|
||||
// - at least one ip from each family (v4 or v6)
|
||||
func IsDualStackIPs(ips []net.IP) (bool, error) {
|
||||
v4Found := false
|
||||
v6Found := false
|
||||
for _, ip := range ips {
|
||||
if ip == nil {
|
||||
return false, fmt.Errorf("ip %v is invalid", ip)
|
||||
}
|
||||
|
||||
if v4Found && v6Found {
|
||||
continue
|
||||
}
|
||||
|
||||
if IsIPv6(ip) {
|
||||
v6Found = true
|
||||
continue
|
||||
}
|
||||
|
||||
v4Found = true
|
||||
}
|
||||
|
||||
return (v4Found && v6Found), nil
|
||||
}
|
||||
|
||||
// IsDualStackIPStrings returns if
|
||||
// - all are valid ips
|
||||
// - at least one ip from each family (v4 or v6)
|
||||
func IsDualStackIPStrings(ips []string) (bool, error) {
|
||||
parsedIPs := make([]net.IP, 0, len(ips))
|
||||
for _, ip := range ips {
|
||||
parsedIP := ParseIPSloppy(ip)
|
||||
parsedIPs = append(parsedIPs, parsedIP)
|
||||
}
|
||||
return IsDualStackIPs(parsedIPs)
|
||||
}
|
||||
|
||||
// IsDualStackCIDRs returns if
|
||||
// - all are valid cidrs
|
||||
// - at least one cidr from each family (v4 or v6)
|
||||
func IsDualStackCIDRs(cidrs []*net.IPNet) (bool, error) {
|
||||
v4Found := false
|
||||
v6Found := false
|
||||
for _, cidr := range cidrs {
|
||||
if cidr == nil {
|
||||
return false, fmt.Errorf("cidr %v is invalid", cidr)
|
||||
}
|
||||
|
||||
if v4Found && v6Found {
|
||||
continue
|
||||
}
|
||||
|
||||
if IsIPv6(cidr.IP) {
|
||||
v6Found = true
|
||||
continue
|
||||
}
|
||||
v4Found = true
|
||||
}
|
||||
|
||||
return v4Found && v6Found, nil
|
||||
}
|
||||
|
||||
// IsDualStackCIDRStrings returns if
|
||||
// - all are valid cidrs
|
||||
// - at least one cidr from each family (v4 or v6)
|
||||
func IsDualStackCIDRStrings(cidrs []string) (bool, error) {
|
||||
parsedCIDRs, err := ParseCIDRs(cidrs)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
return IsDualStackCIDRs(parsedCIDRs)
|
||||
}
|
||||
|
||||
// IsIPv6 returns if netIP is IPv6.
|
||||
func IsIPv6(netIP net.IP) bool {
|
||||
return netIP != nil && netIP.To4() == nil
|
||||
}
|
||||
|
||||
// IsIPv6String returns if ip is IPv6.
|
||||
func IsIPv6String(ip string) bool {
|
||||
netIP := ParseIPSloppy(ip)
|
||||
return IsIPv6(netIP)
|
||||
}
|
||||
|
||||
// IsIPv6CIDRString returns if cidr is IPv6.
|
||||
// This assumes cidr is a valid CIDR.
|
||||
func IsIPv6CIDRString(cidr string) bool {
|
||||
ip, _, _ := ParseCIDRSloppy(cidr)
|
||||
return IsIPv6(ip)
|
||||
}
|
||||
|
||||
// IsIPv6CIDR returns if a cidr is ipv6
|
||||
func IsIPv6CIDR(cidr *net.IPNet) bool {
|
||||
ip := cidr.IP
|
||||
return IsIPv6(ip)
|
||||
}
|
||||
|
||||
// IsIPv4 returns if netIP is IPv4.
|
||||
func IsIPv4(netIP net.IP) bool {
|
||||
return netIP != nil && netIP.To4() != nil
|
||||
}
|
||||
|
||||
// IsIPv4String returns if ip is IPv4.
|
||||
func IsIPv4String(ip string) bool {
|
||||
netIP := ParseIPSloppy(ip)
|
||||
return IsIPv4(netIP)
|
||||
}
|
||||
|
||||
// IsIPv4CIDR returns if a cidr is ipv4
|
||||
func IsIPv4CIDR(cidr *net.IPNet) bool {
|
||||
ip := cidr.IP
|
||||
return IsIPv4(ip)
|
||||
}
|
||||
|
||||
// IsIPv4CIDRString returns if cidr is IPv4.
|
||||
// This assumes cidr is a valid CIDR.
|
||||
func IsIPv4CIDRString(cidr string) bool {
|
||||
ip, _, _ := ParseCIDRSloppy(cidr)
|
||||
return IsIPv4(ip)
|
||||
}
|
||||
|
||||
// ParsePort parses a string representing an IP port. If the string is not a
|
||||
// valid port number, this returns an error.
|
||||
func ParsePort(port string, allowZero bool) (int, error) {
|
||||
|
||||
18
vendor/k8s.io/utils/net/port.go
generated
vendored
18
vendor/k8s.io/utils/net/port.go
generated
vendored
@@ -23,15 +23,6 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
// IPFamily refers to a specific family if not empty, i.e. "4" or "6".
|
||||
type IPFamily string
|
||||
|
||||
// Constants for valid IPFamilys:
|
||||
const (
|
||||
IPv4 IPFamily = "4"
|
||||
IPv6 IPFamily = "6"
|
||||
)
|
||||
|
||||
// Protocol is a network protocol support by LocalPort.
|
||||
type Protocol string
|
||||
|
||||
@@ -67,7 +58,7 @@ func NewLocalPort(desc, ip string, ipFamily IPFamily, port int, protocol Protoco
|
||||
if protocol != TCP && protocol != UDP {
|
||||
return nil, fmt.Errorf("Unsupported protocol %s", protocol)
|
||||
}
|
||||
if ipFamily != "" && ipFamily != "4" && ipFamily != "6" {
|
||||
if ipFamily != IPFamilyUnknown && ipFamily != IPv4 && ipFamily != IPv6 {
|
||||
return nil, fmt.Errorf("Invalid IP family %s", ipFamily)
|
||||
}
|
||||
if ip != "" {
|
||||
@@ -75,9 +66,10 @@ func NewLocalPort(desc, ip string, ipFamily IPFamily, port int, protocol Protoco
|
||||
if parsedIP == nil {
|
||||
return nil, fmt.Errorf("invalid ip address %s", ip)
|
||||
}
|
||||
asIPv4 := parsedIP.To4()
|
||||
if asIPv4 == nil && ipFamily == IPv4 || asIPv4 != nil && ipFamily == IPv6 {
|
||||
return nil, fmt.Errorf("ip address and family mismatch %s, %s", ip, ipFamily)
|
||||
if ipFamily != IPFamilyUnknown {
|
||||
if IPFamily(parsedIP) != ipFamily {
|
||||
return nil, fmt.Errorf("ip address and family mismatch %s, %s", ip, ipFamily)
|
||||
}
|
||||
}
|
||||
}
|
||||
return &LocalPort{Description: desc, IP: ip, IPFamily: ipFamily, Port: port, Protocol: protocol}, nil
|
||||
|
||||
Reference in New Issue
Block a user