Skip to content
GitLab
Explore
Projects
Groups
Topics
Snippets
Projects
Groups
Topics
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
1105 Внедрение механизмов обеспечения безопасности цепочки поставки программных проектов
Legacy
scanned-projects
helm
Commits
6ffff5fe
Unverified
Commit
6ffff5fe
authored
6 years ago
by
Adam Reese
Browse files
Options
Download
Patches
Plain Diff
fix(kube): get correct versioned object from info helper
fixes: #3826
parent
1ee17068
release-2.17
dev-v2
release-2.10
release-2.11
release-2.12
release-2.13
release-2.14
release-2.15
release-2.16
v2.17.0
v2.17.0-rc.1
v2.16.12
v2.16.11
v2.16.10
v2.16.9
v2.16.8
v2.16.7
v2.16.6
v2.16.5
v2.16.4
v2.16.3
v2.16.2
v2.16.1
v2.16.0
v2.16.0-rc.2
v2.16.0-rc.1
v2.15.2
v2.15.1
v2.15.0
v2.15.0-rc.2
v2.15.0-rc.1
v2.14.3
v2.14.2
v2.14.1
v2.14.0
v2.14.0-rc.2
v2.14.0-rc.1
v2.13.1
v2.13.1-rc.1
v2.13.0
v2.13.0-rc.2
v2.13.0-rc.1
v2.12.3
v2.12.2
v2.12.1
v2.12.0
v2.12.0-rc.2
v2.12.0-rc.1
v2.11.0
v2.11.0-rc.4
v2.11.0-rc.3
v2.11.0-rc.2
v2.11.0-rc.1
v2.10.0
v2.10.0-rc.3
v2.10.0-rc.2
v2.10.0-rc.1
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
pkg/kube/client.go
+29
-56
pkg/kube/client.go
pkg/kube/wait.go
+1
-1
pkg/kube/wait.go
with
30 additions
and
57 deletions
+30
-57
pkg/kube/client.go
+
29
−
56
View file @
6ffff5fe
...
...
@@ -35,9 +35,7 @@ import (
extv1beta1
"k8s.io/api/extensions/v1beta1"
apiequality
"k8s.io/apimachinery/pkg/api/equality"
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/meta"
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/fields"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/runtime"
...
...
@@ -393,12 +391,12 @@ func deleteResource(c *Client, info *resource.Info) error {
return
reaper
.
Stop
(
info
.
Namespace
,
info
.
Name
,
0
,
nil
)
}
func
createPatch
(
mapping
*
meta
.
RESTMapping
,
target
,
current
runtime
.
Object
)
([]
byte
,
types
.
PatchType
,
error
)
{
func
createPatch
(
target
*
resource
.
Info
,
current
runtime
.
Object
)
([]
byte
,
types
.
PatchType
,
error
)
{
oldData
,
err
:=
json
.
Marshal
(
current
)
if
err
!=
nil
{
return
nil
,
types
.
StrategicMergePatchType
,
fmt
.
Errorf
(
"serializing current configuration: %s"
,
err
)
}
newData
,
err
:=
json
.
Marshal
(
target
)
newData
,
err
:=
json
.
Marshal
(
target
.
Object
)
if
err
!=
nil
{
return
nil
,
types
.
StrategicMergePatchType
,
fmt
.
Errorf
(
"serializing target configuration: %s"
,
err
)
}
...
...
@@ -412,7 +410,7 @@ func createPatch(mapping *meta.RESTMapping, target, current runtime.Object) ([]b
}
// Get a versioned object
versionedObject
,
err
:=
mapping
.
ConvertToVersion
(
target
,
mapping
.
GroupVersionKind
.
GroupVersion
()
)
versionedObject
,
err
:=
target
.
Versioned
()
// Unstructured objects, such as CRDs, may not have an not registered error
// returned from ConvertToVersion. Anything that's unstructured should
...
...
@@ -434,7 +432,7 @@ func createPatch(mapping *meta.RESTMapping, target, current runtime.Object) ([]b
}
func
updateResource
(
c
*
Client
,
target
*
resource
.
Info
,
currentObj
runtime
.
Object
,
force
bool
,
recreate
bool
)
error
{
patch
,
patchType
,
err
:=
createPatch
(
target
.
Mapping
,
target
.
Object
,
currentObj
)
patch
,
patchType
,
err
:=
createPatch
(
target
,
currentObj
)
if
err
!=
nil
{
return
fmt
.
Errorf
(
"failed to create patch: %s"
,
err
)
}
...
...
@@ -484,16 +482,9 @@ func updateResource(c *Client, target *resource.Info, currentObj runtime.Object,
return
nil
}
versioned
,
err
:=
c
.
AsVersionedObject
(
target
.
Object
)
if
runtime
.
IsNotRegisteredError
(
err
)
{
return
nil
}
if
err
!=
nil
{
return
err
}
selector
,
err
:=
getSelectorFromObject
(
versioned
)
if
err
!=
nil
{
versioned
:=
target
.
AsVersioned
()
selector
,
ok
:=
getSelectorFromObject
(
versioned
)
if
!
ok
{
return
nil
}
...
...
@@ -522,45 +513,45 @@ func updateResource(c *Client, target *resource.Info, currentObj runtime.Object,
return
nil
}
func
getSelectorFromObject
(
obj
runtime
.
Object
)
(
map
[
string
]
string
,
error
)
{
func
getSelectorFromObject
(
obj
runtime
.
Object
)
(
map
[
string
]
string
,
bool
)
{
switch
typed
:=
obj
.
(
type
)
{
case
*
v1
.
ReplicationController
:
return
typed
.
Spec
.
Selector
,
nil
return
typed
.
Spec
.
Selector
,
true
case
*
extv1beta1
.
ReplicaSet
:
return
typed
.
Spec
.
Selector
.
MatchLabels
,
nil
return
typed
.
Spec
.
Selector
.
MatchLabels
,
true
case
*
appsv1
.
ReplicaSet
:
return
typed
.
Spec
.
Selector
.
MatchLabels
,
nil
return
typed
.
Spec
.
Selector
.
MatchLabels
,
true
case
*
extv1beta1
.
Deployment
:
return
typed
.
Spec
.
Selector
.
MatchLabels
,
nil
return
typed
.
Spec
.
Selector
.
MatchLabels
,
true
case
*
appsv1beta1
.
Deployment
:
return
typed
.
Spec
.
Selector
.
MatchLabels
,
nil
return
typed
.
Spec
.
Selector
.
MatchLabels
,
true
case
*
appsv1beta2
.
Deployment
:
return
typed
.
Spec
.
Selector
.
MatchLabels
,
nil
return
typed
.
Spec
.
Selector
.
MatchLabels
,
true
case
*
appsv1
.
Deployment
:
return
typed
.
Spec
.
Selector
.
MatchLabels
,
nil
return
typed
.
Spec
.
Selector
.
MatchLabels
,
true
case
*
extv1beta1
.
DaemonSet
:
return
typed
.
Spec
.
Selector
.
MatchLabels
,
nil
return
typed
.
Spec
.
Selector
.
MatchLabels
,
true
case
*
appsv1beta2
.
DaemonSet
:
return
typed
.
Spec
.
Selector
.
MatchLabels
,
nil
return
typed
.
Spec
.
Selector
.
MatchLabels
,
true
case
*
appsv1
.
DaemonSet
:
return
typed
.
Spec
.
Selector
.
MatchLabels
,
nil
return
typed
.
Spec
.
Selector
.
MatchLabels
,
true
case
*
batch
.
Job
:
return
typed
.
Spec
.
Selector
.
MatchLabels
,
nil
return
typed
.
Spec
.
Selector
.
MatchLabels
,
true
case
*
appsv1beta1
.
StatefulSet
:
return
typed
.
Spec
.
Selector
.
MatchLabels
,
nil
return
typed
.
Spec
.
Selector
.
MatchLabels
,
true
case
*
appsv1beta2
.
StatefulSet
:
return
typed
.
Spec
.
Selector
.
MatchLabels
,
nil
return
typed
.
Spec
.
Selector
.
MatchLabels
,
true
case
*
appsv1
.
StatefulSet
:
return
typed
.
Spec
.
Selector
.
MatchLabels
,
nil
return
typed
.
Spec
.
Selector
.
MatchLabels
,
true
default
:
return
nil
,
f
mt
.
Errorf
(
"Unsupported kind when getting selector: %v"
,
obj
)
return
nil
,
f
alse
}
}
...
...
@@ -605,18 +596,6 @@ func (c *Client) watchUntilReady(timeout time.Duration, info *resource.Info) err
return
err
}
// AsVersionedObject converts a runtime.object to a versioned object.
func
(
c
*
Client
)
AsVersionedObject
(
obj
runtime
.
Object
)
(
runtime
.
Object
,
error
)
{
json
,
err
:=
runtime
.
Encode
(
unstructured
.
UnstructuredJSONScheme
,
obj
)
if
err
!=
nil
{
return
nil
,
err
}
versions
:=
&
runtime
.
VersionedObjects
{}
decoder
:=
unstructured
.
UnstructuredJSONScheme
err
=
runtime
.
DecodeInto
(
decoder
,
json
,
versions
)
return
versions
.
First
(),
err
}
// waitForJob is a helper that waits for a job to complete.
//
// This operates on an event returned from a watcher.
...
...
@@ -715,22 +694,16 @@ func (c *Client) getSelectRelationPod(info *resource.Info, objPods map[string][]
c
.
Log
(
"get relation pod of object: %s/%s/%s"
,
info
.
Namespace
,
info
.
Mapping
.
GroupVersionKind
.
Kind
,
info
.
Name
)
versioned
,
err
:=
c
.
AsVersionedObject
(
info
.
Object
)
if
runtime
.
IsNotRegisteredError
(
err
)
{
versioned
,
err
:=
info
.
Versioned
()
switch
{
case
runtime
.
IsNotRegisteredError
(
err
)
:
return
objPods
,
nil
}
if
err
!=
nil
{
case
err
!=
nil
:
return
objPods
,
err
}
// We can ignore this error because it will only error if it isn't a type that doesn't
// have pods. In that case, we don't care
selector
,
_
:=
getSelectorFromObject
(
versioned
)
selectorString
:=
labels
.
Set
(
selector
)
.
AsSelector
()
.
String
()
// If we have an empty selector, this likely is a service or config map, so bail out now
if
selectorString
==
""
{
selector
,
ok
:=
getSelectorFromObject
(
versioned
)
if
!
ok
{
return
objPods
,
nil
}
...
...
This diff is collapsed.
Click to expand it.
pkg/kube/wait.go
+
1
−
1
View file @
6ffff5fe
...
...
@@ -56,7 +56,7 @@ func (c *Client) waitForResources(timeout time.Duration, created Result) error {
pvc
:=
[]
v1
.
PersistentVolumeClaim
{}
deployments
:=
[]
deployment
{}
for
_
,
v
:=
range
created
{
obj
,
err
:=
c
.
As
Versioned
Object
(
v
.
Object
)
obj
,
err
:=
v
.
Versioned
(
)
if
err
!=
nil
&&
!
runtime
.
IsNotRegisteredError
(
err
)
{
return
false
,
err
}
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment
Menu
Explore
Projects
Groups
Topics
Snippets