Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
4372d62f
Unverified
Commit
4372d62f
authored
Nov 29, 2018
by
k8s-ci-robot
Committed by
GitHub
Nov 29, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #71211 from jsafrane/meta-status-reset
Refactor status PrepareForUpdate into standalone method
parents
05fe21fa
787611a6
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
55 additions
and
10 deletions
+55
-10
BUILD
pkg/registry/storage/volumeattachment/BUILD
+1
-0
strategy.go
pkg/registry/storage/volumeattachment/strategy.go
+2
-10
BUILD
staging/src/k8s.io/apimachinery/pkg/apis/meta/v1/BUILD
+3
-0
helpers.go
staging/src/k8s.io/apimachinery/pkg/apis/meta/v1/helpers.go
+12
-0
helpers_test.go
.../src/k8s.io/apimachinery/pkg/apis/meta/v1/helpers_test.go
+37
-0
No files found.
pkg/registry/storage/volumeattachment/BUILD
View file @
4372d62f
...
...
@@ -13,6 +13,7 @@ go_library(
"//pkg/apis/storage:go_default_library",
"//pkg/apis/storage/validation:go_default_library",
"//staging/src/k8s.io/api/storage/v1beta1:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/runtime:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/runtime/schema:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/util/validation/field:go_default_library",
...
...
pkg/registry/storage/volumeattachment/strategy.go
View file @
4372d62f
...
...
@@ -20,6 +20,7 @@ import (
"context"
storageapiv1beta1
"k8s.io/api/storage/v1beta1"
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/util/validation/field"
...
...
@@ -134,14 +135,5 @@ func (volumeAttachmentStatusStrategy) PrepareForUpdate(ctx context.Context, obj,
oldVolumeAttachment
:=
old
.
(
*
storage
.
VolumeAttachment
)
newVolumeAttachment
.
Spec
=
oldVolumeAttachment
.
Spec
oldMeta
:=
oldVolumeAttachment
.
ObjectMeta
newMeta
:=
&
newVolumeAttachment
.
ObjectMeta
newMeta
.
SetDeletionTimestamp
(
oldMeta
.
GetDeletionTimestamp
())
newMeta
.
SetGeneration
(
oldMeta
.
GetGeneration
())
newMeta
.
SetSelfLink
(
oldMeta
.
GetSelfLink
())
newMeta
.
SetLabels
(
oldMeta
.
GetLabels
())
newMeta
.
SetAnnotations
(
oldMeta
.
GetAnnotations
())
newMeta
.
SetFinalizers
(
oldMeta
.
GetFinalizers
())
newMeta
.
SetOwnerReferences
(
oldMeta
.
GetOwnerReferences
())
metav1
.
ResetObjectMetaForStatus
(
&
newVolumeAttachment
.
ObjectMeta
,
&
oldVolumeAttachment
.
ObjectMeta
)
}
staging/src/k8s.io/apimachinery/pkg/apis/meta/v1/BUILD
View file @
4372d62f
...
...
@@ -25,6 +25,9 @@ go_test(
"//staging/src/k8s.io/apimachinery/pkg/labels:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/runtime/schema:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/runtime/serializer/json:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/types:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/util/diff:go_default_library",
"//vendor/github.com/google/gofuzz:go_default_library",
"//vendor/sigs.k8s.io/yaml:go_default_library",
],
)
...
...
staging/src/k8s.io/apimachinery/pkg/apis/meta/v1/helpers.go
View file @
4372d62f
...
...
@@ -232,3 +232,15 @@ func HasObjectMetaSystemFieldValues(meta Object) bool {
return
!
meta
.
GetCreationTimestamp
()
.
Time
.
IsZero
()
||
len
(
meta
.
GetUID
())
!=
0
}
// ResetObjectMetaForStatus forces the meta fields for a status update to match the meta fields
// for a pre-existing object. This is opt-in for new objects with Status subresource.
func
ResetObjectMetaForStatus
(
meta
,
existingMeta
Object
)
{
meta
.
SetDeletionTimestamp
(
existingMeta
.
GetDeletionTimestamp
())
meta
.
SetGeneration
(
existingMeta
.
GetGeneration
())
meta
.
SetSelfLink
(
existingMeta
.
GetSelfLink
())
meta
.
SetLabels
(
existingMeta
.
GetLabels
())
meta
.
SetAnnotations
(
existingMeta
.
GetAnnotations
())
meta
.
SetFinalizers
(
existingMeta
.
GetFinalizers
())
meta
.
SetOwnerReferences
(
existingMeta
.
GetOwnerReferences
())
}
staging/src/k8s.io/apimachinery/pkg/apis/meta/v1/helpers_test.go
View file @
4372d62f
...
...
@@ -22,7 +22,11 @@ import (
"strings"
"testing"
"github.com/google/gofuzz"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/diff"
)
func
TestLabelSelectorAsSelector
(
t
*
testing
.
T
)
{
...
...
@@ -159,3 +163,36 @@ func TestLabelSelectorAsMap(t *testing.T) {
}
}
}
func
TestResetObjectMetaForStatus
(
t
*
testing
.
T
)
{
meta
:=
&
ObjectMeta
{}
existingMeta
:=
&
ObjectMeta
{}
// fuzz the existingMeta to set every field, no nils
f
:=
fuzz
.
New
()
.
NilChance
(
0
)
.
NumElements
(
1
,
1
)
f
.
Fuzz
(
existingMeta
)
ResetObjectMetaForStatus
(
meta
,
existingMeta
)
// not all fields are stomped during the reset. These fields should not have been set. False
// set them all to their zero values. Before you add anything to this list, consider whether or not
// you're enforcing immutability (those are fine) and whether /status should be able to update
// these values (these are usually not fine).
// generateName doesn't do anything after create
existingMeta
.
SetGenerateName
(
""
)
// resourceVersion is enforced in validation and used during the storage update
existingMeta
.
SetResourceVersion
(
""
)
// fields made immutable in validation
existingMeta
.
SetUID
(
types
.
UID
(
""
))
existingMeta
.
SetName
(
""
)
existingMeta
.
SetNamespace
(
""
)
existingMeta
.
SetClusterName
(
""
)
existingMeta
.
SetCreationTimestamp
(
Time
{})
existingMeta
.
SetDeletionTimestamp
(
nil
)
existingMeta
.
SetDeletionGracePeriodSeconds
(
nil
)
existingMeta
.
SetInitializers
(
nil
)
if
!
reflect
.
DeepEqual
(
meta
,
existingMeta
)
{
t
.
Error
(
diff
.
ObjectDiff
(
meta
,
existingMeta
))
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment