Merge pull request #81754 from apelisse/version-fields
Add FieldsType field to ManagedFields to track content format Kubernetes-commit: 61e2f52e38ff73f0704b12a0edfa94c8a6619a45
This commit is contained in:
commit
5e753bafc7
|
@ -452,11 +452,11 @@
|
|||
},
|
||||
{
|
||||
"ImportPath": "k8s.io/api",
|
||||
"Rev": "9f642ccb7a30"
|
||||
"Rev": "01690931d7e8"
|
||||
},
|
||||
{
|
||||
"ImportPath": "k8s.io/apimachinery",
|
||||
"Rev": "103e7d66058c"
|
||||
"Rev": "0b92ed95b061"
|
||||
},
|
||||
{
|
||||
"ImportPath": "k8s.io/client-go",
|
||||
|
|
8
go.mod
8
go.mod
|
@ -48,8 +48,8 @@ require (
|
|||
gopkg.in/square/go-jose.v2 v2.2.2
|
||||
gopkg.in/yaml.v2 v2.2.2
|
||||
gotest.tools v2.2.0+incompatible // indirect
|
||||
k8s.io/api v0.0.0-20190826194732-9f642ccb7a30
|
||||
k8s.io/apimachinery v0.0.0-20190828074610-103e7d66058c
|
||||
k8s.io/api v0.0.0-20190828114744-01690931d7e8
|
||||
k8s.io/apimachinery v0.0.0-20190828114619-0b92ed95b061
|
||||
k8s.io/client-go v0.0.0-20190827114928-15739c3f8076
|
||||
k8s.io/component-base v0.0.0-20190823013255-e3d4ac5c99fb
|
||||
k8s.io/klog v0.4.0
|
||||
|
@ -65,8 +65,8 @@ replace (
|
|||
golang.org/x/sync => golang.org/x/sync v0.0.0-20181108010431-42b317875d0f
|
||||
golang.org/x/sys => golang.org/x/sys v0.0.0-20190209173611-3b5209105503
|
||||
golang.org/x/text => golang.org/x/text v0.3.1-0.20181227161524-e6919f6577db
|
||||
k8s.io/api => k8s.io/api v0.0.0-20190826194732-9f642ccb7a30
|
||||
k8s.io/apimachinery => k8s.io/apimachinery v0.0.0-20190828074610-103e7d66058c
|
||||
k8s.io/api => k8s.io/api v0.0.0-20190828114744-01690931d7e8
|
||||
k8s.io/apimachinery => k8s.io/apimachinery v0.0.0-20190828114619-0b92ed95b061
|
||||
k8s.io/client-go => k8s.io/client-go v0.0.0-20190827114928-15739c3f8076
|
||||
k8s.io/component-base => k8s.io/component-base v0.0.0-20190823013255-e3d4ac5c99fb
|
||||
)
|
||||
|
|
4
go.sum
4
go.sum
|
@ -250,8 +250,8 @@ gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
|||
gotest.tools v2.2.0+incompatible h1:VsBPFP1AI068pPrMxtb/S8Zkgf9xEmTLJjfM+P5UIEo=
|
||||
gotest.tools v2.2.0+incompatible/go.mod h1:DsYFclhRJ6vuDpmuTbkuFWG+y2sxOXAzmJt81HFBacw=
|
||||
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||
k8s.io/api v0.0.0-20190826194732-9f642ccb7a30/go.mod h1:wKwR91YLONtsDxeJMXqvshPVeRU6ek8/1MfKoDBFqU0=
|
||||
k8s.io/apimachinery v0.0.0-20190828074610-103e7d66058c/go.mod h1:EZoIMuAgG/4v58YL+bz0kqnivqupk28fKYxFCa5e6X8=
|
||||
k8s.io/api v0.0.0-20190828114744-01690931d7e8/go.mod h1:yNyDyPAgJCDAULxYK6BTtmVdL5iZNcC5HUEpeDyRyN4=
|
||||
k8s.io/apimachinery v0.0.0-20190828114619-0b92ed95b061/go.mod h1:EZoIMuAgG/4v58YL+bz0kqnivqupk28fKYxFCa5e6X8=
|
||||
k8s.io/client-go v0.0.0-20190827114928-15739c3f8076/go.mod h1:ELXkYq8RZfSxYigoVWjPU8VmykoDq6DH0DQqG49jakE=
|
||||
k8s.io/component-base v0.0.0-20190823013255-e3d4ac5c99fb/go.mod h1:JjVKThITdppqBfoB0Spaj0MZg9uIoTq4VI9VNyW0lqQ=
|
||||
k8s.io/gengo v0.0.0-20190128074634-0689ccc1d7d6/go.mod h1:ezvh/TsK7cY6rbqRK0oQQ8IAqLxYwwyPxAX1Pzy0ii0=
|
||||
|
|
|
@ -26,7 +26,7 @@ import (
|
|||
|
||||
// EmptyFields represents a set with no paths
|
||||
// It looks like metav1.Fields{Raw: []byte("{}")}
|
||||
var EmptyFields metav1.Fields = func() metav1.Fields {
|
||||
var EmptyFields metav1.FieldsV1 = func() metav1.FieldsV1 {
|
||||
f, err := SetToFields(*fieldpath.NewSet())
|
||||
if err != nil {
|
||||
panic("should never happen")
|
||||
|
@ -35,13 +35,13 @@ var EmptyFields metav1.Fields = func() metav1.Fields {
|
|||
}()
|
||||
|
||||
// FieldsToSet creates a set paths from an input trie of fields
|
||||
func FieldsToSet(f metav1.Fields) (s fieldpath.Set, err error) {
|
||||
func FieldsToSet(f metav1.FieldsV1) (s fieldpath.Set, err error) {
|
||||
err = s.FromJSON(bytes.NewReader(f.Raw))
|
||||
return s, err
|
||||
}
|
||||
|
||||
// SetToFields creates a trie of fields from an input set of paths
|
||||
func SetToFields(s fieldpath.Set) (f metav1.Fields, err error) {
|
||||
func SetToFields(s fieldpath.Set) (f metav1.FieldsV1, err error) {
|
||||
f.Raw, err = s.ToJSON()
|
||||
return f, err
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ import (
|
|||
|
||||
// TestFieldsRoundTrip tests that a fields trie can be round tripped as a path set
|
||||
func TestFieldsRoundTrip(t *testing.T) {
|
||||
tests := []metav1.Fields{
|
||||
tests := []metav1.FieldsV1{
|
||||
{
|
||||
Raw: []byte(`{"f:metadata":{"f:name":{},".":{}}}`),
|
||||
},
|
||||
|
@ -54,11 +54,11 @@ func TestFieldsRoundTrip(t *testing.T) {
|
|||
// TestFieldsToSetError tests that errors are picked up by FieldsToSet
|
||||
func TestFieldsToSetError(t *testing.T) {
|
||||
tests := []struct {
|
||||
fields metav1.Fields
|
||||
fields metav1.FieldsV1
|
||||
errString string
|
||||
}{
|
||||
{
|
||||
fields: metav1.Fields{
|
||||
fields: metav1.FieldsV1{
|
||||
Raw: []byte(`{"k:{invalid json}":{"f:name":{},".":{}}}`),
|
||||
},
|
||||
errString: "ReadObjectCB",
|
||||
|
|
|
@ -101,8 +101,11 @@ func decodeManagedFields(encodedManagedFields []metav1.ManagedFieldsEntry) (mana
|
|||
func BuildManagerIdentifier(encodedManager *metav1.ManagedFieldsEntry) (manager string, err error) {
|
||||
encodedManagerCopy := *encodedManager
|
||||
|
||||
// Never include fields type in the manager identifier
|
||||
encodedManagerCopy.FieldsType = ""
|
||||
|
||||
// Never include the fields in the manager identifier
|
||||
encodedManagerCopy.Fields = nil
|
||||
encodedManagerCopy.FieldsV1 = nil
|
||||
|
||||
// Never include the time in the manager identifier
|
||||
encodedManagerCopy.Time = nil
|
||||
|
@ -124,8 +127,8 @@ func BuildManagerIdentifier(encodedManager *metav1.ManagedFieldsEntry) (manager
|
|||
|
||||
func decodeVersionedSet(encodedVersionedSet *metav1.ManagedFieldsEntry) (versionedSet fieldpath.VersionedSet, err error) {
|
||||
fields := EmptyFields
|
||||
if encodedVersionedSet.Fields != nil {
|
||||
fields = *encodedVersionedSet.Fields
|
||||
if encodedVersionedSet.FieldsV1 != nil {
|
||||
fields = *encodedVersionedSet.FieldsV1
|
||||
}
|
||||
set, err := FieldsToSet(fields)
|
||||
if err != nil {
|
||||
|
@ -191,11 +194,12 @@ func encodeManagerVersionedSet(manager string, versionedSet fieldpath.VersionedS
|
|||
if versionedSet.Applied() {
|
||||
encodedVersionedSet.Operation = metav1.ManagedFieldsOperationApply
|
||||
}
|
||||
encodedVersionedSet.FieldsType = "FieldsV1"
|
||||
fields, err := SetToFields(*versionedSet.Set())
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error encoding set: %v", err)
|
||||
}
|
||||
encodedVersionedSet.Fields = &fields
|
||||
encodedVersionedSet.FieldsV1 = &fields
|
||||
|
||||
return encodedVersionedSet, nil
|
||||
}
|
||||
|
|
|
@ -32,7 +32,8 @@ import (
|
|||
func TestRoundTripManagedFields(t *testing.T) {
|
||||
tests := []string{
|
||||
`- apiVersion: v1
|
||||
fields:
|
||||
fieldsType: FieldsV1
|
||||
fieldsV1:
|
||||
v:3:
|
||||
f:alsoPi: {}
|
||||
v:3.1415:
|
||||
|
@ -43,7 +44,8 @@ func TestRoundTripManagedFields(t *testing.T) {
|
|||
operation: Update
|
||||
time: "2001-02-03T04:05:06Z"
|
||||
- apiVersion: v1beta1
|
||||
fields:
|
||||
fieldsType: FieldsV1
|
||||
fieldsV1:
|
||||
i:5:
|
||||
f:i: {}
|
||||
manager: foo
|
||||
|
@ -51,7 +53,8 @@ func TestRoundTripManagedFields(t *testing.T) {
|
|||
time: "2011-12-13T14:15:16Z"
|
||||
`,
|
||||
`- apiVersion: v1
|
||||
fields:
|
||||
fieldsType: FieldsV1
|
||||
fieldsV1:
|
||||
f:spec:
|
||||
f:containers:
|
||||
k:{"name":"c"}:
|
||||
|
@ -61,7 +64,8 @@ func TestRoundTripManagedFields(t *testing.T) {
|
|||
operation: Apply
|
||||
`,
|
||||
`- apiVersion: v1
|
||||
fields:
|
||||
fieldsType: FieldsV1
|
||||
fieldsV1:
|
||||
f:apiVersion: {}
|
||||
f:kind: {}
|
||||
f:metadata:
|
||||
|
@ -90,7 +94,8 @@ func TestRoundTripManagedFields(t *testing.T) {
|
|||
operation: Update
|
||||
`,
|
||||
`- apiVersion: v1
|
||||
fields:
|
||||
fieldsType: FieldsV1
|
||||
fieldsV1:
|
||||
f:allowVolumeExpansion: {}
|
||||
f:apiVersion: {}
|
||||
f:kind: {}
|
||||
|
@ -106,7 +111,8 @@ func TestRoundTripManagedFields(t *testing.T) {
|
|||
operation: Apply
|
||||
`,
|
||||
`- apiVersion: v1
|
||||
fields:
|
||||
fieldsType: FieldsV1
|
||||
fieldsV1:
|
||||
f:apiVersion: {}
|
||||
f:kind: {}
|
||||
f:metadata:
|
||||
|
@ -163,7 +169,7 @@ func TestBuildManagerIdentifier(t *testing.T) {
|
|||
{
|
||||
managedFieldsEntry: `
|
||||
apiVersion: v1
|
||||
fields:
|
||||
fieldsV1:
|
||||
f:apiVersion: {}
|
||||
manager: foo
|
||||
operation: Update
|
||||
|
@ -174,7 +180,7 @@ time: "2001-02-03T04:05:06Z"
|
|||
{
|
||||
managedFieldsEntry: `
|
||||
apiVersion: v1
|
||||
fields:
|
||||
fieldsV1:
|
||||
f:apiVersion: {}
|
||||
manager: foo
|
||||
operation: Apply
|
||||
|
|
Loading…
Reference in New Issue