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
441e2066
Commit
441e2066
authored
May 04, 2016
by
jianhuiz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
move server client shared annotations to new api/annotations package
parent
e973b5d2
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
81 additions
and
42 deletions
+81
-42
annotations.go
pkg/api/annotations/annotations.go
+23
-0
doc.go
pkg/api/annotations/doc.go
+18
-0
deployment_controller.go
pkg/controller/deployment/deployment_controller.go
+2
-2
apply.go
pkg/kubectl/apply.go
+29
-32
apply_test.go
pkg/kubectl/cmd/apply_test.go
+3
-3
deployment.go
test/e2e/deployment.go
+4
-3
kubectl.go
test/e2e/kubectl.go
+2
-2
No files found.
pkg/api/annotations/annotations.go
0 → 100644
View file @
441e2066
/*
Copyright 2016 The Kubernetes Authors All rights reserved.
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
annotations
const
kubectlPrefix
=
"kubectl.kubernetes.io/"
// LastAppliedConfigAnnotation is the annotation used to store the previous
// configuration of a resource for use in a three way diff by UpdateApplyAnnotation.
const
LastAppliedConfigAnnotation
=
kubectlPrefix
+
"last-applied-configuration"
pkg/api/annotations/doc.go
0 → 100644
View file @
441e2066
/*
Copyright 2016 The Kubernetes Authors All rights reserved.
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 annotations defines annotation keys that shared between server and client
package
annotations
pkg/controller/deployment/deployment_controller.go
View file @
441e2066
...
...
@@ -25,6 +25,7 @@ import (
"github.com/golang/glog"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/annotations"
"k8s.io/kubernetes/pkg/api/errors"
"k8s.io/kubernetes/pkg/api/unversioned"
"k8s.io/kubernetes/pkg/apis/extensions"
...
...
@@ -34,7 +35,6 @@ import (
"k8s.io/kubernetes/pkg/client/record"
"k8s.io/kubernetes/pkg/controller"
"k8s.io/kubernetes/pkg/controller/framework"
"k8s.io/kubernetes/pkg/kubectl"
"k8s.io/kubernetes/pkg/runtime"
deploymentutil
"k8s.io/kubernetes/pkg/util/deployment"
utilerrors
"k8s.io/kubernetes/pkg/util/errors"
...
...
@@ -913,7 +913,7 @@ func setNewReplicaSetAnnotations(deployment *extensions.Deployment, newRS *exten
// See https://github.com/kubernetes/kubernetes/pull/20035#issuecomment-179558615
func
skipCopyAnnotation
(
key
string
)
bool
{
// Skip apply annotations and revision annotations.
return
key
==
kubectl
.
LastAppliedConfigAnnotation
||
key
==
deploymentutil
.
RevisionAnnotation
return
key
==
annotations
.
LastAppliedConfigAnnotation
||
key
==
deploymentutil
.
RevisionAnnotation
}
func
getSkippedAnnotations
(
annotations
map
[
string
]
string
)
map
[
string
]
string
{
...
...
pkg/kubectl/apply.go
View file @
441e2066
...
...
@@ -19,6 +19,7 @@ package kubectl
import
(
"encoding/json"
"k8s.io/kubernetes/pkg/api/annotations"
"k8s.io/kubernetes/pkg/api/meta"
"k8s.io/kubernetes/pkg/kubectl/resource"
"k8s.io/kubernetes/pkg/runtime"
...
...
@@ -28,23 +29,19 @@ type debugError interface {
DebugError
()
(
msg
string
,
args
[]
interface
{})
}
// LastAppliedConfigAnnotation is the annotation used to store the previous
// configuration of a resource for use in a three way diff by UpdateApplyAnnotation.
const
LastAppliedConfigAnnotation
=
kubectlAnnotationPrefix
+
"last-applied-configuration"
// GetOriginalConfiguration retrieves the original configuration of the object
// from the annotation, or nil if no annotation was found.
func
GetOriginalConfiguration
(
info
*
resource
.
Info
)
([]
byte
,
error
)
{
annot
ation
s
,
err
:=
info
.
Mapping
.
MetadataAccessor
.
Annotations
(
info
.
Object
)
annots
,
err
:=
info
.
Mapping
.
MetadataAccessor
.
Annotations
(
info
.
Object
)
if
err
!=
nil
{
return
nil
,
err
}
if
annot
ation
s
==
nil
{
if
annots
==
nil
{
return
nil
,
nil
}
original
,
ok
:=
annot
ations
[
LastAppliedConfigAnnotation
]
original
,
ok
:=
annot
s
[
annotations
.
LastAppliedConfigAnnotation
]
if
!
ok
{
return
nil
,
nil
}
...
...
@@ -60,17 +57,17 @@ func SetOriginalConfiguration(info *resource.Info, original []byte) error {
}
accessor
:=
info
.
Mapping
.
MetadataAccessor
annot
ation
s
,
err
:=
accessor
.
Annotations
(
info
.
Object
)
annots
,
err
:=
accessor
.
Annotations
(
info
.
Object
)
if
err
!=
nil
{
return
err
}
if
annot
ation
s
==
nil
{
annot
ation
s
=
map
[
string
]
string
{}
if
annots
==
nil
{
annots
=
map
[
string
]
string
{}
}
annot
ations
[
LastAppliedConfigAnnotation
]
=
string
(
original
)
if
err
:=
info
.
Mapping
.
MetadataAccessor
.
SetAnnotations
(
info
.
Object
,
annot
ation
s
);
err
!=
nil
{
annot
s
[
annotations
.
LastAppliedConfigAnnotation
]
=
string
(
original
)
if
err
:=
info
.
Mapping
.
MetadataAccessor
.
SetAnnotations
(
info
.
Object
,
annots
);
err
!=
nil
{
return
err
}
...
...
@@ -93,14 +90,14 @@ func GetModifiedConfiguration(info *resource.Info, annotate bool, codec runtime.
}
// Get the current annotations from the object.
annot
ation
s
:=
accessor
.
GetAnnotations
()
if
annot
ation
s
==
nil
{
annot
ation
s
=
map
[
string
]
string
{}
annots
:=
accessor
.
GetAnnotations
()
if
annots
==
nil
{
annots
=
map
[
string
]
string
{}
}
original
:=
annot
ations
[
LastAppliedConfigAnnotation
]
delete
(
annot
ations
,
LastAppliedConfigAnnotation
)
accessor
.
SetAnnotations
(
annot
ation
s
)
original
:=
annot
s
[
annotations
.
LastAppliedConfigAnnotation
]
delete
(
annot
s
,
annotations
.
LastAppliedConfigAnnotation
)
accessor
.
SetAnnotations
(
annots
)
// TODO: this needs to be abstracted - there should be no assumption that versioned object
// can be marshalled to JSON.
modified
,
err
=
json
.
Marshal
(
info
.
VersionedObject
)
...
...
@@ -109,8 +106,8 @@ func GetModifiedConfiguration(info *resource.Info, annotate bool, codec runtime.
}
if
annotate
{
annot
ations
[
LastAppliedConfigAnnotation
]
=
string
(
modified
)
accessor
.
SetAnnotations
(
annot
ation
s
)
annot
s
[
annotations
.
LastAppliedConfigAnnotation
]
=
string
(
modified
)
accessor
.
SetAnnotations
(
annots
)
// TODO: this needs to be abstracted - there should be no assumption that versioned object
// can be marshalled to JSON.
modified
,
err
=
json
.
Marshal
(
info
.
VersionedObject
)
...
...
@@ -120,24 +117,24 @@ func GetModifiedConfiguration(info *resource.Info, annotate bool, codec runtime.
}
// Restore the object to its original condition.
annot
ations
[
LastAppliedConfigAnnotation
]
=
original
accessor
.
SetAnnotations
(
annot
ation
s
)
annot
s
[
annotations
.
LastAppliedConfigAnnotation
]
=
original
accessor
.
SetAnnotations
(
annots
)
}
else
{
// Otherwise, use the server side version of the object.
accessor
:=
info
.
Mapping
.
MetadataAccessor
// Get the current annotations from the object.
annot
ation
s
,
err
:=
accessor
.
Annotations
(
info
.
Object
)
annots
,
err
:=
accessor
.
Annotations
(
info
.
Object
)
if
err
!=
nil
{
return
nil
,
err
}
if
annot
ation
s
==
nil
{
annot
ation
s
=
map
[
string
]
string
{}
if
annots
==
nil
{
annots
=
map
[
string
]
string
{}
}
original
:=
annot
ations
[
LastAppliedConfigAnnotation
]
delete
(
annot
ations
,
LastAppliedConfigAnnotation
)
if
err
:=
accessor
.
SetAnnotations
(
info
.
Object
,
annot
ation
s
);
err
!=
nil
{
original
:=
annot
s
[
annotations
.
LastAppliedConfigAnnotation
]
delete
(
annot
s
,
annotations
.
LastAppliedConfigAnnotation
)
if
err
:=
accessor
.
SetAnnotations
(
info
.
Object
,
annots
);
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -147,8 +144,8 @@ func GetModifiedConfiguration(info *resource.Info, annotate bool, codec runtime.
}
if
annotate
{
annot
ations
[
LastAppliedConfigAnnotation
]
=
string
(
modified
)
if
err
:=
info
.
Mapping
.
MetadataAccessor
.
SetAnnotations
(
info
.
Object
,
annot
ation
s
);
err
!=
nil
{
annot
s
[
annotations
.
LastAppliedConfigAnnotation
]
=
string
(
modified
)
if
err
:=
info
.
Mapping
.
MetadataAccessor
.
SetAnnotations
(
info
.
Object
,
annots
);
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -159,8 +156,8 @@ func GetModifiedConfiguration(info *resource.Info, annotate bool, codec runtime.
}
// Restore the object to its original condition.
annot
ations
[
LastAppliedConfigAnnotation
]
=
original
if
err
:=
info
.
Mapping
.
MetadataAccessor
.
SetAnnotations
(
info
.
Object
,
annot
ation
s
);
err
!=
nil
{
annot
s
[
annotations
.
LastAppliedConfigAnnotation
]
=
original
if
err
:=
info
.
Mapping
.
MetadataAccessor
.
SetAnnotations
(
info
.
Object
,
annots
);
err
!=
nil
{
return
nil
,
err
}
}
...
...
pkg/kubectl/cmd/apply_test.go
View file @
441e2066
...
...
@@ -28,9 +28,9 @@ import (
"github.com/spf13/cobra"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/annotations"
"k8s.io/kubernetes/pkg/api/meta"
"k8s.io/kubernetes/pkg/client/unversioned/fake"
"k8s.io/kubernetes/pkg/kubectl"
cmdutil
"k8s.io/kubernetes/pkg/kubectl/cmd/util"
"k8s.io/kubernetes/pkg/runtime"
)
...
...
@@ -117,7 +117,7 @@ func annotateRuntimeObject(t *testing.T, originalObj, currentObj runtime.Object,
if
currentAnnotations
==
nil
{
currentAnnotations
=
make
(
map
[
string
]
string
)
}
currentAnnotations
[
kubectl
.
LastAppliedConfigAnnotation
]
=
string
(
original
)
currentAnnotations
[
annotations
.
LastAppliedConfigAnnotation
]
=
string
(
original
)
currentAccessor
.
SetAnnotations
(
currentAnnotations
)
current
,
err
:=
json
.
Marshal
(
currentObj
)
if
err
!=
nil
{
...
...
@@ -151,7 +151,7 @@ func validatePatchApplication(t *testing.T, req *http.Request) {
}
annotationsMap
:=
walkMapPath
(
t
,
patchMap
,
[]
string
{
"metadata"
,
"annotations"
})
if
_
,
ok
:=
annotationsMap
[
kubectl
.
LastAppliedConfigAnnotation
];
!
ok
{
if
_
,
ok
:=
annotationsMap
[
annotations
.
LastAppliedConfigAnnotation
];
!
ok
{
t
.
Fatalf
(
"patch does not contain annotation:
\n
%s
\n
"
,
patch
)
}
...
...
test/e2e/deployment.go
View file @
441e2066
...
...
@@ -38,6 +38,7 @@ import (
.
"github.com/onsi/ginkgo"
.
"github.com/onsi/gomega"
"k8s.io/kubernetes/pkg/api/annotations"
)
const
(
...
...
@@ -220,7 +221,7 @@ func testNewDeployment(f *framework.Framework) {
replicas
:=
int32
(
1
)
framework
.
Logf
(
"Creating simple deployment %s"
,
deploymentName
)
d
:=
newDeployment
(
deploymentName
,
replicas
,
podLabels
,
nginxImageName
,
nginxImage
,
extensions
.
RollingUpdateDeploymentStrategyType
,
nil
)
d
.
Annotations
=
map
[
string
]
string
{
"test"
:
"should-copy-to-replica-set"
,
kubectl
.
LastAppliedConfigAnnotation
:
"should-not-copy-to-replica-set"
}
d
.
Annotations
=
map
[
string
]
string
{
"test"
:
"should-copy-to-replica-set"
,
annotations
.
LastAppliedConfigAnnotation
:
"should-not-copy-to-replica-set"
}
_
,
err
:=
c
.
Extensions
()
.
Deployments
(
ns
)
.
Create
(
d
)
Expect
(
err
)
.
NotTo
(
HaveOccurred
())
defer
stopDeployment
(
c
,
f
.
Client
,
ns
,
deploymentName
)
...
...
@@ -238,9 +239,9 @@ func testNewDeployment(f *framework.Framework) {
Expect
(
err
)
.
NotTo
(
HaveOccurred
())
// Check new RS annotations
Expect
(
newRS
.
Annotations
[
"test"
])
.
Should
(
Equal
(
"should-copy-to-replica-set"
))
Expect
(
newRS
.
Annotations
[
kubectl
.
LastAppliedConfigAnnotation
])
.
Should
(
Equal
(
""
))
Expect
(
newRS
.
Annotations
[
annotations
.
LastAppliedConfigAnnotation
])
.
Should
(
Equal
(
""
))
Expect
(
deployment
.
Annotations
[
"test"
])
.
Should
(
Equal
(
"should-copy-to-replica-set"
))
Expect
(
deployment
.
Annotations
[
kubectl
.
LastAppliedConfigAnnotation
])
.
Should
(
Equal
(
"should-not-copy-to-replica-set"
))
Expect
(
deployment
.
Annotations
[
annotations
.
LastAppliedConfigAnnotation
])
.
Should
(
Equal
(
"should-not-copy-to-replica-set"
))
}
func
testRollingUpdateDeployment
(
f
*
framework
.
Framework
)
{
...
...
test/e2e/kubectl.go
View file @
441e2066
...
...
@@ -40,11 +40,11 @@ import (
"github.com/ghodss/yaml"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/annotations"
apierrs
"k8s.io/kubernetes/pkg/api/errors"
"k8s.io/kubernetes/pkg/api/unversioned"
client
"k8s.io/kubernetes/pkg/client/unversioned"
"k8s.io/kubernetes/pkg/controller"
"k8s.io/kubernetes/pkg/kubectl"
"k8s.io/kubernetes/pkg/kubectl/cmd/util"
"k8s.io/kubernetes/pkg/labels"
utilnet
"k8s.io/kubernetes/pkg/util/net"
...
...
@@ -1432,7 +1432,7 @@ func forEachReplicationController(c *client.Client, ns, selectorKey, selectorVal
func
validateReplicationControllerConfiguration
(
rc
api
.
ReplicationController
)
{
if
rc
.
Name
==
"redis-master"
{
if
_
,
ok
:=
rc
.
Annotations
[
kubectl
.
LastAppliedConfigAnnotation
];
!
ok
{
if
_
,
ok
:=
rc
.
Annotations
[
annotations
.
LastAppliedConfigAnnotation
];
!
ok
{
framework
.
Failf
(
"Annotation not found in modified configuration:
\n
%v
\n
"
,
rc
)
}
...
...
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