mirror of
https://github.com/ceph/ceph-csi.git
synced 2025-06-13 18:43:34 +00:00
rebase: update K8s packages to v0.32.1
Update K8s packages in go.mod to v0.32.1 Signed-off-by: Praveen M <m.praveen@ibm.com>
This commit is contained in:
8
vendor/k8s.io/kubernetes/pkg/util/kernel/OWNERS
generated
vendored
Normal file
8
vendor/k8s.io/kubernetes/pkg/util/kernel/OWNERS
generated
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
# See the OWNERS docs at https://go.k8s.io/owners
|
||||
|
||||
reviewers:
|
||||
- sig-network-reviewers
|
||||
- sig-node-reviewers
|
||||
approvers:
|
||||
- sig-network-approvers
|
||||
- sig-node-approvers
|
64
vendor/k8s.io/kubernetes/pkg/util/kernel/constants.go
generated
vendored
Normal file
64
vendor/k8s.io/kubernetes/pkg/util/kernel/constants.go
generated
vendored
Normal file
@ -0,0 +1,64 @@
|
||||
/*
|
||||
Copyright 2023 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 kernel
|
||||
|
||||
// IPLocalReservedPortsNamespacedKernelVersion is the kernel version in which net.ipv4.ip_local_reserved_ports was namespaced(netns).
|
||||
// (ref: https://github.com/torvalds/linux/commit/122ff243f5f104194750ecbc76d5946dd1eec934)
|
||||
const IPLocalReservedPortsNamespacedKernelVersion = "3.16"
|
||||
|
||||
// IPVSConnReuseModeMinSupportedKernelVersion is the minium kernel version supporting net.ipv4.vs.conn_reuse_mode.
|
||||
// (ref: https://github.com/torvalds/linux/commit/d752c364571743d696c2a54a449ce77550c35ac5)
|
||||
const IPVSConnReuseModeMinSupportedKernelVersion = "4.1"
|
||||
|
||||
// TCPKeepAliveTimeNamespacedKernelVersion is the kernel version in which net.ipv4.tcp_keepalive_time was namespaced(netns).
|
||||
// (ref: https://github.com/torvalds/linux/commit/13b287e8d1cad951634389f85b8c9b816bd3bb1e)
|
||||
const TCPKeepAliveTimeNamespacedKernelVersion = "4.5"
|
||||
|
||||
// TCPKeepAliveIntervalNamespacedKernelVersion is the kernel version in which net.ipv4.tcp_keepalive_intvl was namespaced(netns).
|
||||
// (ref: https://github.com/torvalds/linux/commit/b840d15d39128d08ed4486085e5507d2617b9ae1)
|
||||
const TCPKeepAliveIntervalNamespacedKernelVersion = "4.5"
|
||||
|
||||
// TCPKeepAliveProbesNamespacedKernelVersion is the kernel version in which net.ipv4.tcp_keepalive_probes was namespaced(netns).
|
||||
// (ref: https://github.com/torvalds/linux/commit/9bd6861bd4326e3afd3f14a9ec8a723771fb20bb)
|
||||
const TCPKeepAliveProbesNamespacedKernelVersion = "4.5"
|
||||
|
||||
// TCPFinTimeoutNamespacedKernelVersion is the kernel version in which net.ipv4.tcp_fin_timeout was namespaced(netns).
|
||||
// (ref: https://github.com/torvalds/linux/commit/1e579caa18b96f9eb18f4f5416658cd15f37c062)
|
||||
const TCPFinTimeoutNamespacedKernelVersion = "4.6"
|
||||
|
||||
// IPVSConnReuseModeFixedKernelVersion is the kernel version in which net.ipv4.vs.conn_reuse_mode was fixed.
|
||||
// (ref: https://github.com/torvalds/linux/commit/35dfb013149f74c2be1ff9c78f14e6a3cd1539d1)
|
||||
const IPVSConnReuseModeFixedKernelVersion = "5.9"
|
||||
|
||||
// UserNamespacesSupportKernelVersion is the kernel version where idmap for tmpfs support was added
|
||||
// (ref: https://github.com/torvalds/linux/commit/05e6295f7b5e05f09e369a3eb2882ec5b40fff20)
|
||||
const UserNamespacesSupportKernelVersion = "6.3"
|
||||
|
||||
const TmpfsNoswapSupportKernelVersion = "6.4"
|
||||
|
||||
// NFTablesKubeProxyKernelVersion is the lowest kernel version kube-proxy supports using
|
||||
// nftables mode with by default. This is not directly related to any specific kernel
|
||||
// commit; see https://issues.k8s.io/122743#issuecomment-1893922424
|
||||
const NFTablesKubeProxyKernelVersion = "5.13"
|
||||
|
||||
// TCPReceiveMemoryNamespacedKernelVersion is the kernel version in which net.ipv4.tcp_rmem was namespaced(netns).
|
||||
// (ref: https://github.com/torvalds/linux/commit/356d1833b638bd465672aefeb71def3ab93fc17d)
|
||||
const TCPReceiveMemoryNamespacedKernelVersion = "4.15"
|
||||
|
||||
// TCPTransmitMemoryNamespacedKernelVersion is the kernel version in which net.ipv4.tcp_wmem was namespaced(netns).
|
||||
// (ref: https://github.com/torvalds/linux/commit/356d1833b638bd465672aefeb71def3ab93fc17d)
|
||||
const TCPTransmitMemoryNamespacedKernelVersion = "4.15"
|
48
vendor/k8s.io/kubernetes/pkg/util/kernel/version.go
generated
vendored
Normal file
48
vendor/k8s.io/kubernetes/pkg/util/kernel/version.go
generated
vendored
Normal file
@ -0,0 +1,48 @@
|
||||
/*
|
||||
Copyright 2023 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 kernel
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"k8s.io/apimachinery/pkg/util/version"
|
||||
)
|
||||
|
||||
type readFileFunc func(string) ([]byte, error)
|
||||
|
||||
// GetVersion returns currently running kernel version.
|
||||
func GetVersion() (*version.Version, error) {
|
||||
return getVersion(os.ReadFile)
|
||||
}
|
||||
|
||||
// getVersion reads os release file from the give readFile function.
|
||||
func getVersion(readFile readFileFunc) (*version.Version, error) {
|
||||
kernelVersionFile := "/proc/sys/kernel/osrelease"
|
||||
fileContent, err := readFile(kernelVersionFile)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to read os-release file: %s", err.Error())
|
||||
}
|
||||
|
||||
kernelVersion, err := version.ParseGeneric(strings.TrimSpace(string(fileContent)))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to parse kernel version: %s", err.Error())
|
||||
}
|
||||
|
||||
return kernelVersion, nil
|
||||
}
|
18
vendor/k8s.io/kubernetes/pkg/util/oom/doc.go
generated
vendored
Normal file
18
vendor/k8s.io/kubernetes/pkg/util/oom/doc.go
generated
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
/*
|
||||
Copyright 2015 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 oom implements utility functions relating to out of memory management.
|
||||
package oom // import "k8s.io/kubernetes/pkg/util/oom"
|
26
vendor/k8s.io/kubernetes/pkg/util/oom/oom.go
generated
vendored
Normal file
26
vendor/k8s.io/kubernetes/pkg/util/oom/oom.go
generated
vendored
Normal file
@ -0,0 +1,26 @@
|
||||
/*
|
||||
Copyright 2015 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 oom
|
||||
|
||||
// This is a struct instead of an interface to allow injection of process ID listers and
|
||||
// applying OOM score in tests.
|
||||
// TODO: make this an interface, and inject a mock ioutil struct for testing.
|
||||
type OOMAdjuster struct {
|
||||
pidLister func(cgroupName string) ([]int, error)
|
||||
ApplyOOMScoreAdj func(pid int, oomScoreAdj int) error
|
||||
ApplyOOMScoreAdjContainer func(cgroupName string, oomScoreAdj, maxTries int) error
|
||||
}
|
35
vendor/k8s.io/kubernetes/pkg/util/oom/oom_fake.go
generated
vendored
Normal file
35
vendor/k8s.io/kubernetes/pkg/util/oom/oom_fake.go
generated
vendored
Normal file
@ -0,0 +1,35 @@
|
||||
/*
|
||||
Copyright 2015 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 oom
|
||||
|
||||
type FakeOOMAdjuster struct{}
|
||||
|
||||
func NewFakeOOMAdjuster() *OOMAdjuster {
|
||||
return &OOMAdjuster{
|
||||
pidLister: func(cgroupName string) ([]int, error) { return make([]int, 0), nil },
|
||||
ApplyOOMScoreAdj: fakeApplyOOMScoreAdj,
|
||||
ApplyOOMScoreAdjContainer: fakeApplyOOMScoreAdjContainer,
|
||||
}
|
||||
}
|
||||
|
||||
func fakeApplyOOMScoreAdj(pid int, oomScoreAdj int) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func fakeApplyOOMScoreAdjContainer(cgroupName string, oomScoreAdj, maxTries int) error {
|
||||
return nil
|
||||
}
|
130
vendor/k8s.io/kubernetes/pkg/util/oom/oom_linux.go
generated
vendored
Normal file
130
vendor/k8s.io/kubernetes/pkg/util/oom/oom_linux.go
generated
vendored
Normal file
@ -0,0 +1,130 @@
|
||||
//go:build linux
|
||||
// +build linux
|
||||
|
||||
/*
|
||||
Copyright 2015 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 oom
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
cmutil "k8s.io/kubernetes/pkg/kubelet/cm/util"
|
||||
|
||||
"k8s.io/klog/v2"
|
||||
)
|
||||
|
||||
func NewOOMAdjuster() *OOMAdjuster {
|
||||
oomAdjuster := &OOMAdjuster{
|
||||
pidLister: getPids,
|
||||
ApplyOOMScoreAdj: applyOOMScoreAdj,
|
||||
}
|
||||
oomAdjuster.ApplyOOMScoreAdjContainer = oomAdjuster.applyOOMScoreAdjContainer
|
||||
return oomAdjuster
|
||||
}
|
||||
|
||||
func getPids(cgroupName string) ([]int, error) {
|
||||
return cmutil.GetPids(filepath.Join("/", cgroupName))
|
||||
}
|
||||
|
||||
// Writes 'value' to /proc/<pid>/oom_score_adj. PID = 0 means self
|
||||
// Returns os.ErrNotExist if the `pid` does not exist.
|
||||
func applyOOMScoreAdj(pid int, oomScoreAdj int) error {
|
||||
if pid < 0 {
|
||||
return fmt.Errorf("invalid PID %d specified for oom_score_adj", pid)
|
||||
}
|
||||
|
||||
var pidStr string
|
||||
if pid == 0 {
|
||||
pidStr = "self"
|
||||
} else {
|
||||
pidStr = strconv.Itoa(pid)
|
||||
}
|
||||
|
||||
maxTries := 2
|
||||
oomScoreAdjPath := path.Join("/proc", pidStr, "oom_score_adj")
|
||||
value := strconv.Itoa(oomScoreAdj)
|
||||
klog.V(4).Infof("attempting to set %q to %q", oomScoreAdjPath, value)
|
||||
var err error
|
||||
for i := 0; i < maxTries; i++ {
|
||||
err = os.WriteFile(oomScoreAdjPath, []byte(value), 0700)
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
klog.V(2).Infof("%q does not exist", oomScoreAdjPath)
|
||||
return os.ErrNotExist
|
||||
}
|
||||
|
||||
klog.V(3).Info(err)
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
continue
|
||||
}
|
||||
return nil
|
||||
}
|
||||
if err != nil {
|
||||
klog.V(2).Infof("failed to set %q to %q: %v", oomScoreAdjPath, value, err)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
// Writes 'value' to /proc/<pid>/oom_score_adj for all processes in cgroup cgroupName.
|
||||
// Keeps trying to write until the process list of the cgroup stabilizes, or until maxTries tries.
|
||||
func (oomAdjuster *OOMAdjuster) applyOOMScoreAdjContainer(cgroupName string, oomScoreAdj, maxTries int) error {
|
||||
adjustedProcessSet := make(map[int]bool)
|
||||
for i := 0; i < maxTries; i++ {
|
||||
continueAdjusting := false
|
||||
pidList, err := oomAdjuster.pidLister(cgroupName)
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
// Nothing to do since the container doesn't exist anymore.
|
||||
return os.ErrNotExist
|
||||
}
|
||||
continueAdjusting = true
|
||||
klog.V(10).Infof("Error getting process list for cgroup %s: %+v", cgroupName, err)
|
||||
} else if len(pidList) == 0 {
|
||||
klog.V(10).Infof("Pid list is empty")
|
||||
continueAdjusting = true
|
||||
} else {
|
||||
for _, pid := range pidList {
|
||||
if !adjustedProcessSet[pid] {
|
||||
klog.V(10).Infof("pid %d needs to be set", pid)
|
||||
if err = oomAdjuster.ApplyOOMScoreAdj(pid, oomScoreAdj); err == nil {
|
||||
adjustedProcessSet[pid] = true
|
||||
} else if err == os.ErrNotExist {
|
||||
continue
|
||||
} else {
|
||||
klog.V(10).Infof("cannot adjust oom score for pid %d - %v", pid, err)
|
||||
continueAdjusting = true
|
||||
}
|
||||
// Processes can come and go while we try to apply oom score adjust value. So ignore errors here.
|
||||
}
|
||||
}
|
||||
}
|
||||
if !continueAdjusting {
|
||||
return nil
|
||||
}
|
||||
// There's a slight race. A process might have forked just before we write its OOM score adjust.
|
||||
// The fork might copy the parent process's old OOM score, then this function might execute and
|
||||
// update the parent's OOM score, but the forked process id might not be reflected in cgroup.procs
|
||||
// for a short amount of time. So this function might return without changing the forked process's
|
||||
// OOM score. Very unlikely race, so ignoring this for now.
|
||||
}
|
||||
return fmt.Errorf("exceeded maxTries, some processes might not have desired OOM score")
|
||||
}
|
41
vendor/k8s.io/kubernetes/pkg/util/oom/oom_unsupported.go
generated
vendored
Normal file
41
vendor/k8s.io/kubernetes/pkg/util/oom/oom_unsupported.go
generated
vendored
Normal file
@ -0,0 +1,41 @@
|
||||
//go:build !linux
|
||||
// +build !linux
|
||||
|
||||
/*
|
||||
Copyright 2015 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 oom
|
||||
|
||||
import (
|
||||
"errors"
|
||||
)
|
||||
|
||||
var unsupportedErr = errors.New("setting OOM scores is unsupported in this build")
|
||||
|
||||
func NewOOMAdjuster() *OOMAdjuster {
|
||||
return &OOMAdjuster{
|
||||
ApplyOOMScoreAdj: unsupportedApplyOOMScoreAdj,
|
||||
ApplyOOMScoreAdjContainer: unsupportedApplyOOMScoreAdjContainer,
|
||||
}
|
||||
}
|
||||
|
||||
func unsupportedApplyOOMScoreAdj(pid int, oomScoreAdj int) error {
|
||||
return unsupportedErr
|
||||
}
|
||||
|
||||
func unsupportedApplyOOMScoreAdjContainer(cgroupName string, oomScoreAdj, maxTries int) error {
|
||||
return unsupportedErr
|
||||
}
|
81
vendor/k8s.io/kubernetes/pkg/util/pod/pod.go
generated
vendored
Normal file
81
vendor/k8s.io/kubernetes/pkg/util/pod/pod.go
generated
vendored
Normal file
@ -0,0 +1,81 @@
|
||||
/*
|
||||
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 pod
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
v1 "k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/types"
|
||||
"k8s.io/apimachinery/pkg/util/strategicpatch"
|
||||
clientset "k8s.io/client-go/kubernetes"
|
||||
podutil "k8s.io/kubernetes/pkg/api/v1/pod"
|
||||
)
|
||||
|
||||
// PatchPodStatus patches pod status. It returns true and avoids an update if the patch contains no changes.
|
||||
func PatchPodStatus(ctx context.Context, c clientset.Interface, namespace, name string, uid types.UID, oldPodStatus, newPodStatus v1.PodStatus) (*v1.Pod, []byte, bool, error) {
|
||||
patchBytes, unchanged, err := preparePatchBytesForPodStatus(namespace, name, uid, oldPodStatus, newPodStatus)
|
||||
if err != nil {
|
||||
return nil, nil, false, err
|
||||
}
|
||||
if unchanged {
|
||||
return nil, patchBytes, true, nil
|
||||
}
|
||||
|
||||
updatedPod, err := c.CoreV1().Pods(namespace).Patch(ctx, name, types.StrategicMergePatchType, patchBytes, metav1.PatchOptions{}, "status")
|
||||
if err != nil {
|
||||
return nil, nil, false, fmt.Errorf("failed to patch status %q for pod %q/%q: %v", patchBytes, namespace, name, err)
|
||||
}
|
||||
return updatedPod, patchBytes, false, nil
|
||||
}
|
||||
|
||||
func preparePatchBytesForPodStatus(namespace, name string, uid types.UID, oldPodStatus, newPodStatus v1.PodStatus) ([]byte, bool, error) {
|
||||
oldData, err := json.Marshal(v1.Pod{
|
||||
Status: oldPodStatus,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, false, fmt.Errorf("failed to Marshal oldData for pod %q/%q: %v", namespace, name, err)
|
||||
}
|
||||
|
||||
newData, err := json.Marshal(v1.Pod{
|
||||
ObjectMeta: metav1.ObjectMeta{UID: uid}, // only put the uid in the new object to ensure it appears in the patch as a precondition
|
||||
Status: newPodStatus,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, false, fmt.Errorf("failed to Marshal newData for pod %q/%q: %v", namespace, name, err)
|
||||
}
|
||||
|
||||
patchBytes, err := strategicpatch.CreateTwoWayMergePatch(oldData, newData, v1.Pod{})
|
||||
if err != nil {
|
||||
return nil, false, fmt.Errorf("failed to CreateTwoWayMergePatch for pod %q/%q: %v", namespace, name, err)
|
||||
}
|
||||
return patchBytes, bytes.Equal(patchBytes, []byte(fmt.Sprintf(`{"metadata":{"uid":%q}}`, uid))), nil
|
||||
}
|
||||
|
||||
// ReplaceOrAppendPodCondition replaces the first pod condition with equal type or appends if there is none
|
||||
func ReplaceOrAppendPodCondition(conditions []v1.PodCondition, condition *v1.PodCondition) []v1.PodCondition {
|
||||
if i, _ := podutil.GetPodConditionFromList(conditions, condition.Type); i >= 0 {
|
||||
conditions[i] = *condition
|
||||
} else {
|
||||
conditions = append(conditions, *condition)
|
||||
}
|
||||
return conditions
|
||||
}
|
75
vendor/k8s.io/kubernetes/pkg/util/slice/slice.go
generated
vendored
Normal file
75
vendor/k8s.io/kubernetes/pkg/util/slice/slice.go
generated
vendored
Normal file
@ -0,0 +1,75 @@
|
||||
/*
|
||||
Copyright 2015 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 slice provides utility methods for common operations on slices.
|
||||
package slice
|
||||
|
||||
import (
|
||||
"sort"
|
||||
)
|
||||
|
||||
// CopyStrings copies the contents of the specified string slice
|
||||
// into a new slice.
|
||||
func CopyStrings(s []string) []string {
|
||||
if s == nil {
|
||||
return nil
|
||||
}
|
||||
c := make([]string, len(s))
|
||||
copy(c, s)
|
||||
return c
|
||||
}
|
||||
|
||||
// SortStrings sorts the specified string slice in place. It returns the same
|
||||
// slice that was provided in order to facilitate method chaining.
|
||||
func SortStrings(s []string) []string {
|
||||
sort.Strings(s)
|
||||
return s
|
||||
}
|
||||
|
||||
// ContainsString checks if a given slice of strings contains the provided string.
|
||||
// If a modifier func is provided, it is called with the slice item before the comparation.
|
||||
func ContainsString(slice []string, s string, modifier func(s string) string) bool {
|
||||
for _, item := range slice {
|
||||
if item == s {
|
||||
return true
|
||||
}
|
||||
if modifier != nil && modifier(item) == s {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// RemoveString returns a newly created []string that contains all items from slice that
|
||||
// are not equal to s and modifier(s) in case modifier func is provided.
|
||||
func RemoveString(slice []string, s string, modifier func(s string) string) []string {
|
||||
newSlice := make([]string, 0)
|
||||
for _, item := range slice {
|
||||
if item == s {
|
||||
continue
|
||||
}
|
||||
if modifier != nil && modifier(item) == s {
|
||||
continue
|
||||
}
|
||||
newSlice = append(newSlice, item)
|
||||
}
|
||||
if len(newSlice) == 0 {
|
||||
// Sanitize for unit tests so we don't need to distinguish empty array
|
||||
// and nil.
|
||||
newSlice = nil
|
||||
}
|
||||
return newSlice
|
||||
}
|
Reference in New Issue
Block a user