Merge pull request #633 from ibuildthecloud/wrangler

Update wrangler
pull/634/head v0.7.0-rc7
Erik Wilson 2019-07-12 11:11:36 -07:00 committed by GitHub
commit 403e73ab1c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
22 changed files with 141 additions and 82 deletions

View File

@ -23,12 +23,18 @@ import (
"time" "time"
clientset "github.com/rancher/k3s/pkg/generated/clientset/versioned" clientset "github.com/rancher/k3s/pkg/generated/clientset/versioned"
scheme "github.com/rancher/k3s/pkg/generated/clientset/versioned/scheme"
informers "github.com/rancher/k3s/pkg/generated/informers/externalversions" informers "github.com/rancher/k3s/pkg/generated/informers/externalversions"
"github.com/rancher/wrangler/pkg/generic" "github.com/rancher/wrangler/pkg/generic"
"github.com/rancher/wrangler/pkg/schemes"
"k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/client-go/rest" "k8s.io/client-go/rest"
) )
func init() {
scheme.AddToScheme(schemes.All)
}
type Factory struct { type Factory struct {
synced bool synced bool
informerFactory informers.SharedInformerFactory informerFactory informers.SharedInformerFactory

View File

@ -227,13 +227,13 @@ import:
- package: github.com/rancher/dynamiclistener - package: github.com/rancher/dynamiclistener
version: 4716ac2362986f28bede3f3caf5d1ce347da55b0 version: 4716ac2362986f28bede3f3caf5d1ce347da55b0
- package: github.com/rancher/helm-controller - package: github.com/rancher/helm-controller
version: d5f5c830231110722f14d446d3b2038e5cdf1532 version: v0.2.1
- package: github.com/rancher/remotedialer - package: github.com/rancher/remotedialer
version: 66218bc42b4fa27c34523c0d19a41a0e2b74983d version: 66218bc42b4fa27c34523c0d19a41a0e2b74983d
- package: github.com/rancher/wrangler - package: github.com/rancher/wrangler
version: 4202dbfa88013c19238bb004d82e013f0593493d version: 7737c167e16514a38229bc64c839cee8cd14e6d3
- package: github.com/rancher/wrangler-api - package: github.com/rancher/wrangler-api
version: efe26ac6a9d720e1bfa5a8cc5f8dce5ad598ce26 version: v0.1.4
- package: github.com/robfig/cron - package: github.com/robfig/cron
version: v1-53-gdf38d32658d878 version: v1-53-gdf38d32658d878
- package: github.com/rootless-containers/rootlesskit - package: github.com/rootless-containers/rootlesskit

View File

@ -11,11 +11,11 @@ package=github.com/opencontainers/runc/contrib/cmd/recvtty
k8s.io/kubernetes v1.14.3-k3s.2 https://github.com/rancher/k3s.git transitive=true,staging=true k8s.io/kubernetes v1.14.3-k3s.2 https://github.com/rancher/k3s.git transitive=true,staging=true
github.com/rancher/wrangler 4202dbfa88013c19238bb004d82e013f0593493d github.com/rancher/wrangler 7737c167e16514a38229bc64c839cee8cd14e6d3
github.com/rancher/wrangler-api efe26ac6a9d720e1bfa5a8cc5f8dce5ad598ce26 github.com/rancher/wrangler-api v0.1.4
github.com/rancher/dynamiclistener 4716ac2362986f28bede3f3caf5d1ce347da55b0 github.com/rancher/dynamiclistener 4716ac2362986f28bede3f3caf5d1ce347da55b0
github.com/rancher/remotedialer 66218bc42b4fa27c34523c0d19a41a0e2b74983d github.com/rancher/remotedialer 66218bc42b4fa27c34523c0d19a41a0e2b74983d
github.com/rancher/helm-controller d5f5c830231110722f14d446d3b2038e5cdf1532 github.com/rancher/helm-controller v0.2.1
github.com/matryer/moq ee5226d43009 https://github.com/rancher/moq.git github.com/matryer/moq ee5226d43009 https://github.com/rancher/moq.git
github.com/coreos/flannel 823afe66b2266bf71f5bec24e6e28b26d70cfc7c https://github.com/ibuildthecloud/flannel.git github.com/coreos/flannel 823afe66b2266bf71f5bec24e6e28b26d70cfc7c https://github.com/ibuildthecloud/flannel.git
github.com/natefinch/lumberjack aee4629129445bbdfb69aa565537dcfa16544311 github.com/natefinch/lumberjack aee4629129445bbdfb69aa565537dcfa16544311

View File

@ -3,8 +3,8 @@ module github.com/rancher/helm-controller
go 1.12 go 1.12
require ( require (
github.com/rancher/wrangler v0.1.3 github.com/rancher/wrangler v0.1.4
github.com/rancher/wrangler-api v0.1.3 github.com/rancher/wrangler-api v0.1.4
github.com/sirupsen/logrus v1.4.1 github.com/sirupsen/logrus v1.4.1
github.com/stretchr/testify v1.3.0 github.com/stretchr/testify v1.3.0
github.com/urfave/cli v1.20.0 github.com/urfave/cli v1.20.0

View File

@ -97,12 +97,16 @@ github.com/rancher/wrangler v0.1.2 h1:+oehkcBDInF6dcnG1ZWczL/tV/c7J8ILP3qEFCme7l
github.com/rancher/wrangler v0.1.2/go.mod h1:EYP7cqpg42YqElaCm+U9ieSrGQKAXxUH5xsr+XGpWyE= github.com/rancher/wrangler v0.1.2/go.mod h1:EYP7cqpg42YqElaCm+U9ieSrGQKAXxUH5xsr+XGpWyE=
github.com/rancher/wrangler v0.1.3 h1:WVMLj7kxTOx2pQyAnUKbbFhuFqhAuzkrsSvk37VaYwY= github.com/rancher/wrangler v0.1.3 h1:WVMLj7kxTOx2pQyAnUKbbFhuFqhAuzkrsSvk37VaYwY=
github.com/rancher/wrangler v0.1.3/go.mod h1:EYP7cqpg42YqElaCm+U9ieSrGQKAXxUH5xsr+XGpWyE= github.com/rancher/wrangler v0.1.3/go.mod h1:EYP7cqpg42YqElaCm+U9ieSrGQKAXxUH5xsr+XGpWyE=
github.com/rancher/wrangler v0.1.4 h1:bdzBw4H9JKQhXPBPNp4eHbmrkA24+VII865VLiVWcw8=
github.com/rancher/wrangler v0.1.4/go.mod h1:EYP7cqpg42YqElaCm+U9ieSrGQKAXxUH5xsr+XGpWyE=
github.com/rancher/wrangler-api v0.1.1 h1:qzIgDnURHTlJ31jMTy917L3y0tAjYRaHhMdmT+Z393s= github.com/rancher/wrangler-api v0.1.1 h1:qzIgDnURHTlJ31jMTy917L3y0tAjYRaHhMdmT+Z393s=
github.com/rancher/wrangler-api v0.1.1/go.mod h1:vholckBg588JqP3M3vyEDUz/ERaB1M3ilnCuV5XxPHM= github.com/rancher/wrangler-api v0.1.1/go.mod h1:vholckBg588JqP3M3vyEDUz/ERaB1M3ilnCuV5XxPHM=
github.com/rancher/wrangler-api v0.1.2 h1:PKWfgxQKNG5v2R7Uo+NYWk6wRXShV55WymiKAFk9eIU= github.com/rancher/wrangler-api v0.1.2 h1:PKWfgxQKNG5v2R7Uo+NYWk6wRXShV55WymiKAFk9eIU=
github.com/rancher/wrangler-api v0.1.2/go.mod h1:zD0Xy4pu2mTUE9pabkOwdzhwms8Yl9AGvDJzGW260Wk= github.com/rancher/wrangler-api v0.1.2/go.mod h1:zD0Xy4pu2mTUE9pabkOwdzhwms8Yl9AGvDJzGW260Wk=
github.com/rancher/wrangler-api v0.1.3 h1:W6FPEb9cGRNpidiw6S5mu+C6iZ4Ji+wBobjybPOdxQo= github.com/rancher/wrangler-api v0.1.3 h1:W6FPEb9cGRNpidiw6S5mu+C6iZ4Ji+wBobjybPOdxQo=
github.com/rancher/wrangler-api v0.1.3/go.mod h1:KPJcBpKwfzsfBL8BO+3fU17NBw8bAk3DUVnHIwE8BGE= github.com/rancher/wrangler-api v0.1.3/go.mod h1:KPJcBpKwfzsfBL8BO+3fU17NBw8bAk3DUVnHIwE8BGE=
github.com/rancher/wrangler-api v0.1.4 h1:2jkZBat27ZHR2RCWQacFEIMdkA1A5fbDE439s3gHLU8=
github.com/rancher/wrangler-api v0.1.4/go.mod h1:Mc8bNN5rNxpQ7am2orUbonahw4xJ6ztF+fUTSku8KnE=
github.com/remyoudompheng/bigfft v0.0.0-20170806203942-52369c62f446/go.mod h1:uYEyJGbgTkfkS4+E/PavXkNJcbFIpEtjt2B0KDQ5+9M= github.com/remyoudompheng/bigfft v0.0.0-20170806203942-52369c62f446/go.mod h1:uYEyJGbgTkfkS4+E/PavXkNJcbFIpEtjt2B0KDQ5+9M=
github.com/sirupsen/logrus v1.4.1 h1:GL2rEmy6nsikmW0r8opw9JIRScdMF5hA8cOYLH7In1k= github.com/sirupsen/logrus v1.4.1 h1:GL2rEmy6nsikmW0r8opw9JIRScdMF5hA8cOYLH7In1k=
github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q= github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q=

View File

@ -23,12 +23,18 @@ import (
"time" "time"
clientset "github.com/rancher/helm-controller/pkg/generated/clientset/versioned" clientset "github.com/rancher/helm-controller/pkg/generated/clientset/versioned"
scheme "github.com/rancher/helm-controller/pkg/generated/clientset/versioned/scheme"
informers "github.com/rancher/helm-controller/pkg/generated/informers/externalversions" informers "github.com/rancher/helm-controller/pkg/generated/informers/externalversions"
"github.com/rancher/wrangler/pkg/generic" "github.com/rancher/wrangler/pkg/generic"
"github.com/rancher/wrangler/pkg/schemes"
"k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/client-go/rest" "k8s.io/client-go/rest"
) )
func init() {
scheme.AddToScheme(schemes.All)
}
type Factory struct { type Factory struct {
synced bool synced bool
informerFactory informers.SharedInformerFactory informerFactory informers.SharedInformerFactory

View File

@ -13,7 +13,7 @@ require (
github.com/knative/build v0.6.0 github.com/knative/build v0.6.0
github.com/knative/pkg v0.0.0-20190514205332-5e4512dcb2ca github.com/knative/pkg v0.0.0-20190514205332-5e4512dcb2ca
github.com/mattbaird/jsonpatch v0.0.0-20171005235357-81af80346b1a // indirect github.com/mattbaird/jsonpatch v0.0.0-20171005235357-81af80346b1a // indirect
github.com/rancher/wrangler v0.1.3 github.com/rancher/wrangler v0.1.4
github.com/sirupsen/logrus v1.4.1 github.com/sirupsen/logrus v1.4.1
k8s.io/api v0.0.0-20190409021203-6e4e0e4f393b k8s.io/api v0.0.0-20190409021203-6e4e0e4f393b
k8s.io/apiextensions-apiserver v0.0.0-20190409022649-727a075fdec8 k8s.io/apiextensions-apiserver v0.0.0-20190409022649-727a075fdec8

View File

@ -81,6 +81,8 @@ github.com/rancher/wrangler v0.1.2 h1:+oehkcBDInF6dcnG1ZWczL/tV/c7J8ILP3qEFCme7l
github.com/rancher/wrangler v0.1.2/go.mod h1:EYP7cqpg42YqElaCm+U9ieSrGQKAXxUH5xsr+XGpWyE= github.com/rancher/wrangler v0.1.2/go.mod h1:EYP7cqpg42YqElaCm+U9ieSrGQKAXxUH5xsr+XGpWyE=
github.com/rancher/wrangler v0.1.3 h1:WVMLj7kxTOx2pQyAnUKbbFhuFqhAuzkrsSvk37VaYwY= github.com/rancher/wrangler v0.1.3 h1:WVMLj7kxTOx2pQyAnUKbbFhuFqhAuzkrsSvk37VaYwY=
github.com/rancher/wrangler v0.1.3/go.mod h1:EYP7cqpg42YqElaCm+U9ieSrGQKAXxUH5xsr+XGpWyE= github.com/rancher/wrangler v0.1.3/go.mod h1:EYP7cqpg42YqElaCm+U9ieSrGQKAXxUH5xsr+XGpWyE=
github.com/rancher/wrangler v0.1.4 h1:bdzBw4H9JKQhXPBPNp4eHbmrkA24+VII865VLiVWcw8=
github.com/rancher/wrangler v0.1.4/go.mod h1:EYP7cqpg42YqElaCm+U9ieSrGQKAXxUH5xsr+XGpWyE=
github.com/remyoudompheng/bigfft v0.0.0-20170806203942-52369c62f446/go.mod h1:uYEyJGbgTkfkS4+E/PavXkNJcbFIpEtjt2B0KDQ5+9M= github.com/remyoudompheng/bigfft v0.0.0-20170806203942-52369c62f446/go.mod h1:uYEyJGbgTkfkS4+E/PavXkNJcbFIpEtjt2B0KDQ5+9M=
github.com/sirupsen/logrus v1.4.1 h1:GL2rEmy6nsikmW0r8opw9JIRScdMF5hA8cOYLH7In1k= github.com/sirupsen/logrus v1.4.1 h1:GL2rEmy6nsikmW0r8opw9JIRScdMF5hA8cOYLH7In1k=
github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q= github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q=

View File

@ -23,12 +23,18 @@ import (
"time" "time"
"github.com/rancher/wrangler/pkg/generic" "github.com/rancher/wrangler/pkg/generic"
"github.com/rancher/wrangler/pkg/schemes"
"k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apimachinery/pkg/runtime/schema"
informers "k8s.io/client-go/informers" informers "k8s.io/client-go/informers"
clientset "k8s.io/client-go/kubernetes" clientset "k8s.io/client-go/kubernetes"
scheme "k8s.io/client-go/kubernetes/scheme"
"k8s.io/client-go/rest" "k8s.io/client-go/rest"
) )
func init() {
scheme.AddToScheme(schemes.All)
}
type Factory struct { type Factory struct {
synced bool synced bool
informerFactory informers.SharedInformerFactory informerFactory informers.SharedInformerFactory

View File

@ -23,12 +23,18 @@ import (
"time" "time"
"github.com/rancher/wrangler/pkg/generic" "github.com/rancher/wrangler/pkg/generic"
"github.com/rancher/wrangler/pkg/schemes"
"k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apimachinery/pkg/runtime/schema"
informers "k8s.io/client-go/informers" informers "k8s.io/client-go/informers"
clientset "k8s.io/client-go/kubernetes" clientset "k8s.io/client-go/kubernetes"
scheme "k8s.io/client-go/kubernetes/scheme"
"k8s.io/client-go/rest" "k8s.io/client-go/rest"
) )
func init() {
scheme.AddToScheme(schemes.All)
}
type Factory struct { type Factory struct {
synced bool synced bool
informerFactory informers.SharedInformerFactory informerFactory informers.SharedInformerFactory

View File

@ -23,12 +23,18 @@ import (
"time" "time"
"github.com/rancher/wrangler/pkg/generic" "github.com/rancher/wrangler/pkg/generic"
"github.com/rancher/wrangler/pkg/schemes"
"k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apimachinery/pkg/runtime/schema"
informers "k8s.io/client-go/informers" informers "k8s.io/client-go/informers"
clientset "k8s.io/client-go/kubernetes" clientset "k8s.io/client-go/kubernetes"
scheme "k8s.io/client-go/kubernetes/scheme"
"k8s.io/client-go/rest" "k8s.io/client-go/rest"
) )
func init() {
scheme.AddToScheme(schemes.All)
}
type Factory struct { type Factory struct {
synced bool synced bool
informerFactory informers.SharedInformerFactory informerFactory informers.SharedInformerFactory

View File

@ -23,12 +23,18 @@ import (
"time" "time"
"github.com/rancher/wrangler/pkg/generic" "github.com/rancher/wrangler/pkg/generic"
"github.com/rancher/wrangler/pkg/schemes"
"k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apimachinery/pkg/runtime/schema"
informers "k8s.io/client-go/informers" informers "k8s.io/client-go/informers"
clientset "k8s.io/client-go/kubernetes" clientset "k8s.io/client-go/kubernetes"
scheme "k8s.io/client-go/kubernetes/scheme"
"k8s.io/client-go/rest" "k8s.io/client-go/rest"
) )
func init() {
scheme.AddToScheme(schemes.All)
}
type Factory struct { type Factory struct {
synced bool synced bool
informerFactory informers.SharedInformerFactory informerFactory informers.SharedInformerFactory

View File

@ -6,6 +6,8 @@ import (
"fmt" "fmt"
"sync" "sync"
gvk2 "github.com/rancher/wrangler/pkg/gvk"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/rancher/wrangler/pkg/apply/injectors" "github.com/rancher/wrangler/pkg/apply/injectors"
"github.com/rancher/wrangler/pkg/objectset" "github.com/rancher/wrangler/pkg/objectset"
@ -165,10 +167,14 @@ func (o *desiredSet) getLabelsAndAnnotations() (map[string]string, map[string]st
} }
if o.owner != nil { if o.owner != nil {
annotations[LabelGVK] = o.owner.GetObjectKind().GroupVersionKind().String() gvk, err := gvk2.Get(o.owner)
if err != nil {
return nil, nil, err
}
annotations[LabelGVK] = gvk.String()
metadata, err := meta.Accessor(o.owner) metadata, err := meta.Accessor(o.owner)
if err != nil { if err != nil {
return nil, nil, fmt.Errorf("failed to get metadata for %s", o.owner.GetObjectKind().GroupVersionKind()) return nil, nil, fmt.Errorf("failed to get metadata for %s", gvk)
} }
annotations[LabelName] = metadata.GetName() annotations[LabelName] = metadata.GetName()
annotations[LabelNamespace] = metadata.GetNamespace() annotations[LabelNamespace] = metadata.GetNamespace()

View File

@ -208,15 +208,19 @@ func getOriginal(obj v1.Object) ([]byte, error) {
return []byte("{}"), nil return []byte("{}"), nil
} }
mapObj := &unstructured.Unstructured{} mapObj := map[string]interface{}{}
err := json.Unmarshal(original, mapObj) err := json.Unmarshal(original, &mapObj)
if err != nil { if err != nil {
return nil, err return nil, err
} }
removeCreationTimestamp(mapObj.Object) removeCreationTimestamp(mapObj)
objCopy, err := prepareObjectForCreate(mapObj) u := &unstructured.Unstructured{
Object: mapObj,
}
objCopy, err := prepareObjectForCreate(u)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -16,6 +16,7 @@ type Options struct {
OutputPackage string OutputPackage string
Groups map[string]Group Groups map[string]Group
Boilerplate string Boilerplate string
GenMocks bool
} }
type Group struct { type Group struct {

View File

@ -3,6 +3,7 @@ package generators
import ( import (
"fmt" "fmt"
"io" "io"
"path/filepath"
args2 "github.com/rancher/wrangler/pkg/controller-gen/args" args2 "github.com/rancher/wrangler/pkg/controller-gen/args"
"k8s.io/gengo/args" "k8s.io/gengo/args"
@ -38,7 +39,9 @@ func (f *factory) Imports(*generator.Context) []string {
"k8s.io/apimachinery/pkg/runtime/schema", "k8s.io/apimachinery/pkg/runtime/schema",
"k8s.io/client-go/rest", "k8s.io/client-go/rest",
GenericPackage, GenericPackage,
AllSchemes,
fmt.Sprintf("clientset \"%s\"", group.ClientSetPackage), fmt.Sprintf("clientset \"%s\"", group.ClientSetPackage),
fmt.Sprintf("scheme \"%s\"", filepath.Join(group.ClientSetPackage, "scheme")),
fmt.Sprintf("informers \"%s\"", group.InformersPackage), fmt.Sprintf("informers \"%s\"", group.InformersPackage),
} }
} }
@ -61,6 +64,10 @@ func (f *factory) Init(c *generator.Context, w io.Writer) error {
} }
var factoryBody = ` var factoryBody = `
func init() {
scheme.AddToScheme(schemes.All)
}
type Factory struct { type Factory struct {
synced bool synced bool
informerFactory informers.SharedInformerFactory informerFactory informers.SharedInformerFactory

View File

@ -8,6 +8,7 @@ import (
const ( const (
GenericPackage = "github.com/rancher/wrangler/pkg/generic" GenericPackage = "github.com/rancher/wrangler/pkg/generic"
AllSchemes = "github.com/rancher/wrangler/pkg/schemes"
) )
func groupPath(group string) string { func groupPath(group string) string {

View File

@ -104,9 +104,11 @@ func Run(opts cgargs.Options) {
logrus.Fatalf("go modules copy failed: %v", err) logrus.Fatalf("go modules copy failed: %v", err)
} }
if err := clientGen.GenerateMocks(); err != nil { if opts.GenMocks {
logrus.Errorf("mocks failed: %v", err) if err := clientGen.GenerateMocks(); err != nil {
return logrus.Errorf("mocks failed: %v", err)
return
}
} }
} }

View File

@ -56,7 +56,6 @@ func NewController(name string, informer cache.SharedIndexInformer, workqueue wo
workqueue: workqueue, workqueue: workqueue,
} }
logrus.Info("Setting up event handlers")
informer.AddEventHandler(cache.ResourceEventHandlerFuncs{ informer.AddEventHandler(cache.ResourceEventHandlerFuncs{
AddFunc: controller.handleObject, AddFunc: controller.handleObject,
UpdateFunc: func(old, new interface{}) { UpdateFunc: func(old, new interface{}) {

27
vendor/github.com/rancher/wrangler/pkg/gvk/get.go generated vendored Normal file
View File

@ -0,0 +1,27 @@
package gvk
import (
"fmt"
"github.com/rancher/wrangler/pkg/schemes"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
)
func Get(obj runtime.Object) (schema.GroupVersionKind, error) {
gvk := obj.GetObjectKind().GroupVersionKind()
if gvk.Kind != "" {
return gvk, nil
}
gvks, _, err := schemes.All.ObjectKinds(obj)
if err != nil {
return schema.GroupVersionKind{}, err
}
if len(gvks) == 0 {
return schema.GroupVersionKind{}, fmt.Errorf("failed to find gvk for %v", obj.GetObjectKind())
}
return gvks[0], nil
}

View File

@ -5,6 +5,8 @@ import (
"reflect" "reflect"
"sort" "sort"
"github.com/rancher/wrangler/pkg/gvk"
"github.com/rancher/wrangler/pkg/merr" "github.com/rancher/wrangler/pkg/merr"
"k8s.io/apimachinery/pkg/api/meta" "k8s.io/apimachinery/pkg/api/meta"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1" v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@ -33,16 +35,21 @@ func (o ObjectKey) String() string {
type ObjectByGVK map[schema.GroupVersionKind]map[ObjectKey]runtime.Object type ObjectByGVK map[schema.GroupVersionKind]map[ObjectKey]runtime.Object
func (o ObjectByGVK) Add(obj runtime.Object) error { func (o ObjectByGVK) Add(obj runtime.Object) (schema.GroupVersionKind, error) {
metadata, err := meta.Accessor(obj) metadata, err := meta.Accessor(obj)
if err != nil { if err != nil {
return err return schema.GroupVersionKind{}, err
} }
objs := o[obj.GetObjectKind().GroupVersionKind()] gvk, err := gvk.Get(obj)
if err != nil {
return schema.GroupVersionKind{}, err
}
objs := o[gvk]
if objs == nil { if objs == nil {
objs = map[ObjectKey]runtime.Object{} objs = map[ObjectKey]runtime.Object{}
o[obj.GetObjectKind().GroupVersionKind()] = objs o[gvk] = objs
} }
objs[ObjectKey{ objs[ObjectKey{
@ -50,42 +57,28 @@ func (o ObjectByGVK) Add(obj runtime.Object) error {
Name: metadata.GetName(), Name: metadata.GetName(),
}] = obj }] = obj
return nil return gvk, nil
} }
type ObjectSet struct { type ObjectSet struct {
errs []error errs []error
objects ObjectByGVK objects ObjectByGVK
nsed map[schema.GroupVersionKind]bool order []runtime.Object
inputs []runtime.Object gvkOrder []schema.GroupVersionKind
order []runtime.Object gvkSeen map[schema.GroupVersionKind]bool
} }
func NewObjectSet() *ObjectSet { func NewObjectSet() *ObjectSet {
return &ObjectSet{ return &ObjectSet{
nsed: map[schema.GroupVersionKind]bool{},
objects: ObjectByGVK{}, objects: ObjectByGVK{},
gvkSeen: map[schema.GroupVersionKind]bool{},
} }
} }
func (o *ObjectSet) Inputs() []runtime.Object {
return o.inputs
}
func (o *ObjectSet) ObjectsByGVK() ObjectByGVK { func (o *ObjectSet) ObjectsByGVK() ObjectByGVK {
return o.objects return o.objects
} }
func (o *ObjectSet) AddInput(objs ...runtime.Object) *ObjectSet {
for _, obj := range objs {
if obj == nil || reflect.ValueOf(obj).IsNil() {
continue
}
o.inputs = append(o.inputs, obj)
}
return o
}
func (o *ObjectSet) Add(objs ...runtime.Object) *ObjectSet { func (o *ObjectSet) Add(objs ...runtime.Object) *ObjectSet {
for _, obj := range objs { for _, obj := range objs {
o.add(obj) o.add(obj)
@ -98,34 +91,17 @@ func (o *ObjectSet) add(obj runtime.Object) {
return return
} }
gvk := obj.GetObjectKind().GroupVersionKind() gvk, err := o.objects.Add(obj)
metadata, err := meta.Accessor(obj)
if err != nil { if err != nil {
o.err(fmt.Errorf("failed to get metadata for %s", gvk)) o.err(fmt.Errorf("failed to add %v", obj))
return
}
name := metadata.GetName()
if name == "" {
o.err(fmt.Errorf("%s is missing name", gvk))
return
}
namespace := metadata.GetNamespace()
nsed, ok := o.nsed[gvk]
if ok && nsed != (namespace != "") {
o.err(fmt.Errorf("got %s objects that are both namespaced and not namespaced", gvk))
return
}
o.nsed[gvk] = namespace != ""
if err := o.objects.Add(obj); err != nil {
o.err(fmt.Errorf("failed to get metadata for %s", gvk))
return return
} }
o.order = append(o.order, obj) o.order = append(o.order, obj)
if !o.gvkSeen[gvk] {
o.gvkSeen[gvk] = true
o.gvkOrder = append(o.gvkOrder, gvk)
}
} }
func (o *ObjectSet) err(err error) error { func (o *ObjectSet) err(err error) error {
@ -146,25 +122,12 @@ func (o *ObjectSet) Len() int {
} }
func (o *ObjectSet) GVKOrder(known ...schema.GroupVersionKind) []schema.GroupVersionKind { func (o *ObjectSet) GVKOrder(known ...schema.GroupVersionKind) []schema.GroupVersionKind {
seen := map[schema.GroupVersionKind]bool{}
var gvkOrder []schema.GroupVersionKind
for _, obj := range o.order {
if seen[obj.GetObjectKind().GroupVersionKind()] {
continue
}
seen[obj.GetObjectKind().GroupVersionKind()] = true
gvkOrder = append(gvkOrder, obj.GetObjectKind().GroupVersionKind())
}
var rest []schema.GroupVersionKind var rest []schema.GroupVersionKind
for _, gvk := range known { for _, gvk := range known {
if seen[gvk] { if o.gvkSeen[gvk] {
continue continue
} }
seen[gvk] = true
rest = append(rest, gvk) rest = append(rest, gvk)
} }
@ -172,5 +135,5 @@ func (o *ObjectSet) GVKOrder(known ...schema.GroupVersionKind) []schema.GroupVer
return rest[i].String() < rest[j].String() return rest[i].String() < rest[j].String()
}) })
return append(gvkOrder, rest...) return append(o.gvkOrder, rest...)
} }

View File

@ -0,0 +1,7 @@
package schemes
import (
"k8s.io/apimachinery/pkg/runtime"
)
var All = runtime.NewScheme()