From c4ab29f721fe48fca67eeb89e3f7ff17d3960333 Mon Sep 17 00:00:00 2001 From: lgtm <1gtm@users.noreply.github.com> Date: Sat, 23 Jan 2021 06:45:18 -0800 Subject: [PATCH] [cherry-pick] Update Kubernetes v1.18.9 dependencies (#291) (#294) /cherry-pick Signed-off-by: 1gtm <1gtm@appscode.com> --- go.mod | 4 +- go.sum | 12 +- .../license-verifier/kubernetes/Makefile | 4 +- .../license-verifier/kubernetes/go.mod | 2 +- .../license-verifier/kubernetes/go.sum | 4 +- .../license-verifier/lib.go | 32 +++-- 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 | 6 +- 12 files changed, 228 insertions(+), 26 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 f6c4488c..ad260560 100644 --- a/go.mod +++ b/go.mod @@ -6,12 +6,12 @@ require ( github.com/codeskyblue/go-sh v0.0.0-20200712050446-30169cf553fe github.com/google/gofuzz v1.1.0 github.com/spf13/cobra v1.1.1 - go.bytebuilders.dev/license-verifier/kubernetes v0.5.1 + go.bytebuilders.dev/license-verifier/kubernetes v0.6.1 gomodules.xyz/x v0.0.0-20201105065653-91c568df6331 k8s.io/api v0.18.9 k8s.io/apimachinery v0.18.9 k8s.io/client-go 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/offshoot-api v0.0.0-20201105074700-8675f5f686f2 kmodules.xyz/schema-checker v0.1.0 diff --git a/go.sum b/go.sum index f9c1e1da..8617c404 100644 --- a/go.sum +++ b/go.sum @@ -129,6 +129,7 @@ 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/go.mod h1:4abs/jPXcmJzYoYGF91JF9Uq9s/KL5n1jvFDix8KcqY= github.com/cyphar/filepath-securejoin v0.2.2/go.mod h1:FpkQEhXnPnOthhzymB7CGsFk2G9VLXONKD9G7QGMM+4= 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= @@ -171,6 +172,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/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= github.com/gliderlabs/ssh v0.1.1/go.mod h1:U7qILu1NlMHj9FlMhZLlkCdDnU1DBEAqr0aevW3Awn0= @@ -642,10 +644,10 @@ github.com/yudai/golcs v0.0.0-20170316035057-ecda9a501e82/go.mod h1:lgjkn3NuSvDf github.com/yudai/pp v2.0.1+incompatible h1:Q4//iY4pNF6yPLZIigmvcl7k/bPgrcTPIFIcmawg5bI= github.com/yudai/pp v2.0.1+incompatible/go.mod h1:PuxR/8QJ7cyCkFp/aUDS+JY727OFEZkTdatxwunjIkc= github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= -go.bytebuilders.dev/license-verifier v0.5.1 h1:GfYRI8rhGO98FmanlzPoOzDfthoY8ATNY3xDdRKs5jQ= -go.bytebuilders.dev/license-verifier v0.5.1/go.mod h1:SNXpEKh3gg2ljHzh6Dxa7qMZS6hM6L9eQ+U0vaGyfFQ= -go.bytebuilders.dev/license-verifier/kubernetes v0.5.1 h1:X6arsotN7dT5UHNL4cpwBmOJTR16fsQGACIB1IKepYQ= -go.bytebuilders.dev/license-verifier/kubernetes v0.5.1/go.mod h1:WXm+QeT10DcIJu6S4e2WmN2pP/QG+X/h4rKnM5bivkE= +go.bytebuilders.dev/license-verifier v0.6.1 h1:HhtVt+K4TBlOwUNhE4HJWBm5S7nsAizOLuirLmIz2ZA= +go.bytebuilders.dev/license-verifier v0.6.1/go.mod h1:SNXpEKh3gg2ljHzh6Dxa7qMZS6hM6L9eQ+U0vaGyfFQ= +go.bytebuilders.dev/license-verifier/kubernetes v0.6.1 h1:WTT81asc7ykKI6E9BzeV0EFkaTniqaghKsybvHQlaGc= +go.bytebuilders.dev/license-verifier/kubernetes v0.6.1/go.mod h1:YyvxUrqALordUC9554S2J93ozJ6PK4GVEyUCmUgUSbo= go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= go.etcd.io/bbolt v1.3.3 h1:MUGmc65QhB3pIlaQ5bB4LwqSj6GIonVJXpZiaKNyaKk= go.etcd.io/bbolt v1.3.3/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= @@ -987,6 +989,8 @@ kmodules.xyz/client-go v0.0.0-20201105071625-0b277310b9b8 h1:zs2+yI/Ola5HjdtfP29 kmodules.xyz/client-go v0.0.0-20201105071625-0b277310b9b8/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 h1:NWWv+Qju8xzHZT9hIk1+BbgQtIytNOoCU4g4vqUmh3M= kmodules.xyz/crd-schema-fuzz v0.0.0-20200922204806-c1426cd7fcf4/go.mod h1:WrO3fryNyFCgqqyWnwI89lnzWA7kN072Ehya7ELGfzE= diff --git a/vendor/go.bytebuilders.dev/license-verifier/kubernetes/Makefile b/vendor/go.bytebuilders.dev/license-verifier/kubernetes/Makefile index f6752aaa..4f05f624 100644 --- a/vendor/go.bytebuilders.dev/license-verifier/kubernetes/Makefile +++ b/vendor/go.bytebuilders.dev/license-verifier/kubernetes/Makefile @@ -25,7 +25,7 @@ CODE_GENERATOR_IMAGE ?= appscode/gengo:release-1.18 API_GROUPS ?= licenses:v1alpha1 # Where to push the docker image. -REGISTRY ?= kubeshield +REGISTRY ?= bytebuilders # This version-strategy uses git tags to set the version string git_branch := $(shell git rev-parse --abbrev-ref HEAD) @@ -64,7 +64,7 @@ ARCH := $(if $(GOARCH),$(GOARCH),$(shell go env GOARCH)) BASEIMAGE_PROD ?= gcr.io/distroless/static BASEIMAGE_DBG ?= debian:stretch -GO_VERSION ?= 1.14 +GO_VERSION ?= 1.15 BUILD_IMAGE ?= appscode/golang-dev:$(GO_VERSION) OUTBIN = bin/$(OS)_$(ARCH)/$(BIN) diff --git a/vendor/go.bytebuilders.dev/license-verifier/kubernetes/go.mod b/vendor/go.bytebuilders.dev/license-verifier/kubernetes/go.mod index 624a96a4..22a23ead 100644 --- a/vendor/go.bytebuilders.dev/license-verifier/kubernetes/go.mod +++ b/vendor/go.bytebuilders.dev/license-verifier/kubernetes/go.mod @@ -4,7 +4,7 @@ go 1.14 require ( github.com/gogo/protobuf v1.3.1 - go.bytebuilders.dev/license-verifier v0.5.1 + go.bytebuilders.dev/license-verifier v0.6.1 golang.org/x/net v0.0.0-20200625001655-4c5254603344 // indirect k8s.io/api v0.18.9 k8s.io/apimachinery v0.18.9 diff --git a/vendor/go.bytebuilders.dev/license-verifier/kubernetes/go.sum b/vendor/go.bytebuilders.dev/license-verifier/kubernetes/go.sum index 4c708c5d..75941f71 100644 --- a/vendor/go.bytebuilders.dev/license-verifier/kubernetes/go.sum +++ b/vendor/go.bytebuilders.dev/license-verifier/kubernetes/go.sum @@ -379,8 +379,8 @@ github.com/yudai/golcs v0.0.0-20170316035057-ecda9a501e82 h1:BHyfKlQyqbsFN5p3Ifn github.com/yudai/golcs v0.0.0-20170316035057-ecda9a501e82/go.mod h1:lgjkn3NuSvDfVJdfcVVdX+jpBxNmX4rDAzaS45IcYoM= github.com/yudai/pp v2.0.1+incompatible h1:Q4//iY4pNF6yPLZIigmvcl7k/bPgrcTPIFIcmawg5bI= github.com/yudai/pp v2.0.1+incompatible/go.mod h1:PuxR/8QJ7cyCkFp/aUDS+JY727OFEZkTdatxwunjIkc= -go.bytebuilders.dev/license-verifier v0.5.1 h1:GfYRI8rhGO98FmanlzPoOzDfthoY8ATNY3xDdRKs5jQ= -go.bytebuilders.dev/license-verifier v0.5.1/go.mod h1:SNXpEKh3gg2ljHzh6Dxa7qMZS6hM6L9eQ+U0vaGyfFQ= +go.bytebuilders.dev/license-verifier v0.6.1 h1:HhtVt+K4TBlOwUNhE4HJWBm5S7nsAizOLuirLmIz2ZA= +go.bytebuilders.dev/license-verifier v0.6.1/go.mod h1:SNXpEKh3gg2ljHzh6Dxa7qMZS6hM6L9eQ+U0vaGyfFQ= go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= go.etcd.io/bbolt v1.3.3/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= go.etcd.io/etcd v0.0.0-20191023171146-3cf2f69b5738/go.mod h1:dnLIgRNXwCJa5e+c6mIZCrds/GIG4ncV9HhK5PX7jPg= diff --git a/vendor/go.bytebuilders.dev/license-verifier/lib.go b/vendor/go.bytebuilders.dev/license-verifier/lib.go index ebbe371f..1973fb12 100644 --- a/vendor/go.bytebuilders.dev/license-verifier/lib.go +++ b/vendor/go.bytebuilders.dev/license-verifier/lib.go @@ -20,6 +20,8 @@ import ( "crypto/x509" "encoding/pem" "fmt" + "strings" + "github.com/pkg/errors" "gomodules.xyz/sets" ) @@ -35,14 +37,9 @@ func VerifyLicense(opts *Options) error { if opts == nil { return fmt.Errorf("missing license") } - block, _ := pem.Decode(opts.License) - if block == nil { - // This probably is a JWT token, should be check for that when ready - return errors.New("failed to parse certificate PEM") - } - cert, err := x509.ParseCertificate(block.Bytes) + cert, err := parseCertificate(opts.License) if err != nil { - return errors.Wrap(err, "failed to parse certificate") + return err } // First, create the set of root certificates. For this example we only @@ -61,6 +58,18 @@ func VerifyLicense(opts *Options) error { x509.ExtKeyUsageClientAuth, }, } + + // wildcard certificate + if strings.HasPrefix(cert.Subject.CommonName, "*.") { + caCert, err := parseCertificate(opts.CACert) + if err != nil { + return err + } + if len(caCert.Subject.Organization) > 0 { + crtopts.DNSName = "*." + caCert.Subject.Organization[0] + } + } + if _, err := cert.Verify(crtopts); err != nil { return errors.Wrap(err, "failed to verify certificate") } @@ -69,3 +78,12 @@ func VerifyLicense(opts *Options) error { } return nil } + +func parseCertificate(data []byte) (*x509.Certificate, error) { + block, _ := pem.Decode(data) + if block == nil { + // This probably is a JWT token, should be check for that when ready + return nil, errors.New("failed to parse certificate PEM") + } + return x509.ParseCertificate(block.Bytes) +} diff --git a/vendor/kmodules.xyz/client-go/core/v1/pod.go b/vendor/kmodules.xyz/client-go/core/v1/pod.go index ae1c8dfc..c9743305 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 00000000..eab9e766 --- /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 6fe46069..6275badf 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 f0ad5471..24e47052 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 00000000..d773da94 --- /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 a90bf8e5..c31b5ade 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -135,10 +135,10 @@ github.com/yudai/gojsondiff github.com/yudai/gojsondiff/formatter # github.com/yudai/golcs v0.0.0-20170316035057-ecda9a501e82 github.com/yudai/golcs -# go.bytebuilders.dev/license-verifier v0.5.1 +# go.bytebuilders.dev/license-verifier v0.6.1 go.bytebuilders.dev/license-verifier go.bytebuilders.dev/license-verifier/info -# go.bytebuilders.dev/license-verifier/kubernetes v0.5.1 +# go.bytebuilders.dev/license-verifier/kubernetes v0.6.1 go.bytebuilders.dev/license-verifier/kubernetes go.bytebuilders.dev/license-verifier/kubernetes/apis/licenses go.bytebuilders.dev/license-verifier/kubernetes/apis/licenses/v1alpha1 @@ -442,7 +442,7 @@ k8s.io/utils/buffer 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