From ff1a7aacd2e43891b29e1bee9cbd6d65d625d831 Mon Sep 17 00:00:00 2001 From: lgtm <1gtm@users.noreply.github.com> Date: Sat, 23 Jan 2021 05:16:41 -0800 Subject: [PATCH] Update Kubernetes v1.18.9 dependencies (#583) Signed-off-by: 1gtm <1gtm@appscode.com> --- go.mod | 2 +- go.sum | 4 + vendor/kmodules.xyz/client-go/core/v1/pod.go | 24 +++- .../client-go/core/v1/pod_status.go | 110 ++++++++++++++++++ vendor/kmodules.xyz/client-go/go.mod | 2 + vendor/kmodules.xyz/client-go/go.sum | 4 + .../kmodules.xyz/client-go/meta/dataformat.go | 50 ++++++++ vendor/modules.txt | 2 +- 8 files changed, 191 insertions(+), 7 deletions(-) create mode 100644 vendor/kmodules.xyz/client-go/core/v1/pod_status.go create mode 100644 vendor/kmodules.xyz/client-go/meta/dataformat.go diff --git a/go.mod b/go.mod index d4ce40679..1244234fa 100644 --- a/go.mod +++ b/go.mod @@ -15,7 +15,7 @@ require ( k8s.io/client-go v0.18.9 k8s.io/component-base v0.18.9 k8s.io/kubectl v0.18.9 - kmodules.xyz/client-go v0.0.0-20210108092221-c3812eb92bd0 + kmodules.xyz/client-go v0.0.0-20210118094617-273ba20ad7ca kmodules.xyz/custom-resources v0.0.0-20201124062543-bd8d35c21b0c kmodules.xyz/monitoring-agent-api v0.0.0-20201105074044-be7a1044891a kmodules.xyz/objectstore-api v0.0.0-20201105133858-cbb2af88d50a diff --git a/go.sum b/go.sum index 9e0857468..af2a1be51 100644 --- a/go.sum +++ b/go.sum @@ -179,6 +179,7 @@ github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:ma github.com/cpuguy83/go-md2man/v2 v2.0.0 h1:EoUDS0afbrsXAZ9YQ9jdu/mZ2sXgT1/2yyNng4PGlyM= github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY= +github.com/cubewise-code/go-mime v0.0.0-20200519001935-8c5762b177d8/go.mod h1:4abs/jPXcmJzYoYGF91JF9Uq9s/KL5n1jvFDix8KcqY= github.com/cyphar/filepath-securejoin v0.2.2/go.mod h1:FpkQEhXnPnOthhzymB7CGsFk2G9VLXONKD9G7QGMM+4= github.com/dave/jennifer v1.2.0/go.mod h1:fIb+770HOpJ2fmN9EPPKOqm1vMGhB+TwXKMZhrIygKg= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -246,6 +247,7 @@ github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMo github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4= github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= github.com/gabriel-vasile/mimetype v1.1.1/go.mod h1:6CDPel/o/3/s4+bp6kIbsWATq8pmgOisOPG40CJa6To= +github.com/gabriel-vasile/mimetype v1.1.2/go.mod h1:6CDPel/o/3/s4+bp6kIbsWATq8pmgOisOPG40CJa6To= github.com/ghodss/yaml v0.0.0-20150909031657-73d445a93680/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= @@ -1386,6 +1388,8 @@ kmodules.xyz/client-go v0.0.0-20201230092550-8ca15cfcbefa h1:1a6/yWhBhxAXzvPsPXW kmodules.xyz/client-go v0.0.0-20201230092550-8ca15cfcbefa/go.mod h1:WXDwZBmvrcLgGcuO9iZpI9jcfPuDFfWbxA4EnhAFtGw= kmodules.xyz/client-go v0.0.0-20210108092221-c3812eb92bd0 h1:VHpZt3cG/yY6UrA3vjoUc4pJtc/jVbjt2A3OPuMXBOQ= kmodules.xyz/client-go v0.0.0-20210108092221-c3812eb92bd0/go.mod h1:WXDwZBmvrcLgGcuO9iZpI9jcfPuDFfWbxA4EnhAFtGw= +kmodules.xyz/client-go v0.0.0-20210118094617-273ba20ad7ca h1:w2vMnu71zJf8RB0qAMV3yt7zHnwg456u6B0S9OHz2lc= +kmodules.xyz/client-go v0.0.0-20210118094617-273ba20ad7ca/go.mod h1:GdX1CHOpjL4F8P9O/7dE9m0fIOs05BNHKVT+kM51rk8= kmodules.xyz/constants v0.0.0-20200923054614-6b87dbbae4d6/go.mod h1:DbiFk1bJ1KEO94t1SlAn7tzc+Zz95rSXgyUKa2nzPmY= kmodules.xyz/crd-schema-fuzz v0.0.0-20200922204806-c1426cd7fcf4/go.mod h1:WrO3fryNyFCgqqyWnwI89lnzWA7kN072Ehya7ELGfzE= kmodules.xyz/custom-resources v0.0.0-20201124062543-bd8d35c21b0c h1:OIAnTI2yik4i1DSe23kO+89RMw/Eu6WUG/IQ++ivYNo= diff --git a/vendor/kmodules.xyz/client-go/core/v1/pod.go b/vendor/kmodules.xyz/client-go/core/v1/pod.go index ae1c8dfc4..c9743305a 100644 --- a/vendor/kmodules.xyz/client-go/core/v1/pod.go +++ b/vendor/kmodules.xyz/client-go/core/v1/pod.go @@ -100,6 +100,23 @@ func TryUpdatePod(ctx context.Context, c kubernetes.Interface, meta metav1.Objec return } +// IsPodReady returns true if a pod is ready considering readiness gates; false otherwise. +func IsPodReady(pod *core.Pod) bool { + conditions := []core.PodConditionType{ + core.PodReady, + } + for _, gate := range pod.Spec.ReadinessGates { + conditions = append(conditions, gate.ConditionType) + } + + for _, condition := range conditions { + if !IsPodConditionTrue(pod.Status.Conditions, condition) { + return false + } + } + return true +} + // ref: https://github.com/coreos/prometheus-operator/blob/c79166fcff3dae7bb8bc1e6bddc81837c2d97c04/pkg/k8sutil/k8sutil.go#L64 // PodRunningAndReady returns whether a pod is running and each container has // passed it's ready state. @@ -108,11 +125,8 @@ func PodRunningAndReady(pod core.Pod) (bool, error) { case core.PodFailed, core.PodSucceeded: return false, errors.New("pod completed") case core.PodRunning: - for _, cond := range pod.Status.Conditions { - if cond.Type != core.PodReady { - continue - } - return cond.Status == core.ConditionTrue, nil + if IsPodReady(&pod) { + return true, nil } return false, errors.New("pod ready condition not found") } diff --git a/vendor/kmodules.xyz/client-go/core/v1/pod_status.go b/vendor/kmodules.xyz/client-go/core/v1/pod_status.go new file mode 100644 index 000000000..eab9e7664 --- /dev/null +++ b/vendor/kmodules.xyz/client-go/core/v1/pod_status.go @@ -0,0 +1,110 @@ +/* +Copyright AppsCode Inc. and Contributors + +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 v1 + +import ( + core "k8s.io/api/core/v1" +) + +const ( + PodConditionTypeReady = core.PodConditionType("kubedb.com/Ready") +) + +// HasCondition returns "true" if the desired condition provided in "condType" is present in the condition list. +// Otherwise, it returns "false". +func HasPodCondition(conditions []core.PodCondition, condType core.PodConditionType) bool { + for i := range conditions { + if conditions[i].Type == condType { + return true + } + } + return false +} + +// GetPodCondition returns a pointer to the desired condition referred by "condType". Otherwise, it returns nil. +func GetPodCondition(conditions []core.PodCondition, condType core.PodConditionType) (int, *core.PodCondition) { + for i := range conditions { + c := conditions[i] + if c.Type == condType { + return i, &c + } + } + return -1, nil +} + +// SetPodCondition add/update the desired condition to the condition list. It does nothing if the condition is already in +// its desired state. +func SetPodCondition(conditions []core.PodCondition, newCondition core.PodCondition) []core.PodCondition { + idx, curCond := GetPodCondition(conditions, newCondition.Type) + // The desired conditions is not in the condition list or is not in its desired state. + // If the current condition status is in its desired state, we have nothing to do. Just return the original condition list. + // Update it if present in the condition list, or append the new condition if it does not present. + if curCond == nil || idx == -1 { + return append(conditions, newCondition) + } else if curCond.Status == newCondition.Status { + return conditions + } else if curCond.Status != newCondition.Status { + conditions[idx].Status = newCondition.Status + conditions[idx].LastTransitionTime = newCondition.LastTransitionTime + conditions[idx].Reason = newCondition.Reason + conditions[idx].Message = newCondition.Message + } + return conditions +} + +// RemovePodCondition remove a condition from the condition list referred by "condType" parameter. +func RemovePodCondition(conditions []core.PodCondition, condType core.PodConditionType) []core.PodCondition { + idx, _ := GetPodCondition(conditions, condType) + if idx == -1 { + // The desired condition is not present in the condition list. So, nothing to do. + return conditions + } + return append(conditions[:idx], conditions[idx+1:]...) +} + +// IsPodConditionTrue returns "true" if the desired condition is in true state. +// It returns "false" if the desired condition is not in "true" state or is not in the condition list. +func IsPodConditionTrue(conditions []core.PodCondition, condType core.PodConditionType) bool { + for i := range conditions { + if conditions[i].Type == condType && conditions[i].Status == core.ConditionTrue { + return true + } + } + return false +} + +// IsPodConditionFalse returns "true" if the desired condition is in false state. +// It returns "false" if the desired condition is not in "false" state or is not in the condition list. +func IsPodConditionFalse(conditions []core.PodCondition, condType core.PodConditionType) bool { + for i := range conditions { + if conditions[i].Type == condType && conditions[i].Status == core.ConditionFalse { + return true + } + } + return false +} + +func UpsertPodReadinessGateConditionType(readinessGates []core.PodReadinessGate, conditionType core.PodConditionType) []core.PodReadinessGate { + for i := range readinessGates { + if readinessGates[i].ConditionType == conditionType { + return readinessGates + } + } + return append(readinessGates, core.PodReadinessGate{ + ConditionType: conditionType, + }) +} diff --git a/vendor/kmodules.xyz/client-go/go.mod b/vendor/kmodules.xyz/client-go/go.mod index 6fe46069a..6275badf4 100644 --- a/vendor/kmodules.xyz/client-go/go.mod +++ b/vendor/kmodules.xyz/client-go/go.mod @@ -3,10 +3,12 @@ module kmodules.xyz/client-go go 1.12 require ( + github.com/cubewise-code/go-mime v0.0.0-20200519001935-8c5762b177d8 github.com/davecgh/go-spew v1.1.1 github.com/evanphx/json-patch v4.9.0+incompatible github.com/fatih/structs v1.1.0 github.com/fsnotify/fsnotify v1.4.9 + github.com/gabriel-vasile/mimetype v1.1.2 github.com/go-openapi/spec v0.19.3 github.com/gogo/protobuf v1.3.1 github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b diff --git a/vendor/kmodules.xyz/client-go/go.sum b/vendor/kmodules.xyz/client-go/go.sum index f0ad5471c..24e470527 100644 --- a/vendor/kmodules.xyz/client-go/go.sum +++ b/vendor/kmodules.xyz/client-go/go.sum @@ -74,6 +74,8 @@ github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfc github.com/cpuguy83/go-md2man v1.0.10/go.mod h1:SmD6nW6nTyfqj6ABTjUi3V3JVMnlJmwcJI5acqYI6dE= github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY= +github.com/cubewise-code/go-mime v0.0.0-20200519001935-8c5762b177d8 h1:Z9lwXumT5ACSmJ7WGnFl+OMLLjpz5uR2fyz7dC255FI= +github.com/cubewise-code/go-mime v0.0.0-20200519001935-8c5762b177d8/go.mod h1:4abs/jPXcmJzYoYGF91JF9Uq9s/KL5n1jvFDix8KcqY= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -105,6 +107,8 @@ github.com/fatih/structs v1.1.0/go.mod h1:9NiDSp5zOcgEDl+j00MP/WkGVPOlPRLejGD8Ga github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4= github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= +github.com/gabriel-vasile/mimetype v1.1.2 h1:gaPnPcNor5aZSVCJVSGipcpbgMWiAAj9z182ocSGbHU= +github.com/gabriel-vasile/mimetype v1.1.2/go.mod h1:6CDPel/o/3/s4+bp6kIbsWATq8pmgOisOPG40CJa6To= github.com/ghodss/yaml v0.0.0-20150909031657-73d445a93680/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= diff --git a/vendor/kmodules.xyz/client-go/meta/dataformat.go b/vendor/kmodules.xyz/client-go/meta/dataformat.go new file mode 100644 index 000000000..d773da945 --- /dev/null +++ b/vendor/kmodules.xyz/client-go/meta/dataformat.go @@ -0,0 +1,50 @@ +package meta + +import ( + "fmt" + + "github.com/mitchellh/mapstructure" + "sigs.k8s.io/yaml" +) + +func DecodeObject(in map[string]interface{}, out interface{}) error { + config := &mapstructure.DecoderConfig{ + Metadata: nil, + TagName: "json", + Result: out, + } + decoder, err := mapstructure.NewDecoder(config) + if err != nil { + return err + } + return decoder.Decode(in) +} + +type DataFormat string + +const ( + // Do not change format + KeepFormat DataFormat = "" + JsonFormat DataFormat = "json" + YAMLFormat DataFormat = "yaml" +) + +func NewDataFormat(format string, def DataFormat) DataFormat { + switch format { + case string(YAMLFormat): + return YAMLFormat + case string(JsonFormat): + return JsonFormat + default: + return def + } +} + +func Marshal(v interface{}, format DataFormat) ([]byte, error) { + if format == JsonFormat { + return json.Marshal(v) + } else if format == YAMLFormat { + return yaml.Marshal(v) + } + return nil, fmt.Errorf("unknonw format: %v", format) +} diff --git a/vendor/modules.txt b/vendor/modules.txt index 0293ccb85..b5e14da12 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -461,7 +461,7 @@ k8s.io/utils/exec k8s.io/utils/integer k8s.io/utils/pointer k8s.io/utils/trace -# kmodules.xyz/client-go v0.0.0-20210108092221-c3812eb92bd0 +# kmodules.xyz/client-go v0.0.0-20210118094617-273ba20ad7ca kmodules.xyz/client-go kmodules.xyz/client-go/api/v1 kmodules.xyz/client-go/apiextensions