Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
H
helm3
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
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
helm3
Commits
13ec13af
Commit
13ec13af
authored
Nov 01, 2016
by
Adam Reese
Committed by
GitHub
Nov 01, 2016
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1487 from adamreese/ref/kube-builder-update
ref(kube): add info match helper functions
parents
eb3624a5
ab12c462
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
27 deletions
+24
-27
client.go
pkg/kube/client.go
+24
-27
No files found.
pkg/kube/client.go
View file @
13ec13af
...
@@ -180,11 +180,9 @@ func (c *Client) Update(namespace string, currentReader, targetReader io.Reader)
...
@@ -180,11 +180,9 @@ func (c *Client) Update(namespace string, currentReader, targetReader io.Reader)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
resourceName
:=
info
.
Name
resourceKind
:=
info
.
Mapping
.
GroupVersionKind
.
Kind
helper
:=
resource
.
NewHelper
(
info
.
Client
,
info
.
Mapping
)
helper
:=
resource
.
NewHelper
(
info
.
Client
,
info
.
Mapping
)
if
_
,
err
:=
helper
.
Get
(
info
.
Namespace
,
resource
Name
,
info
.
Export
);
err
!=
nil
{
if
_
,
err
:=
helper
.
Get
(
info
.
Namespace
,
info
.
Name
,
info
.
Export
);
err
!=
nil
{
if
!
errors
.
IsNotFound
(
err
)
{
if
!
errors
.
IsNotFound
(
err
)
{
return
fmt
.
Errorf
(
"Could not get information about the resource: err: %s"
,
err
)
return
fmt
.
Errorf
(
"Could not get information about the resource: err: %s"
,
err
)
}
}
...
@@ -195,11 +193,11 @@ func (c *Client) Update(namespace string, currentReader, targetReader io.Reader)
...
@@ -195,11 +193,11 @@ func (c *Client) Update(namespace string, currentReader, targetReader io.Reader)
}
}
kind
:=
info
.
Mapping
.
GroupVersionKind
.
Kind
kind
:=
info
.
Mapping
.
GroupVersionKind
.
Kind
log
.
Printf
(
"Created a new %s called %s
\n
"
,
kind
,
resource
Name
)
log
.
Printf
(
"Created a new %s called %s
\n
"
,
kind
,
info
.
Name
)
return
nil
return
nil
}
}
currentObj
,
err
:=
getCurrentObject
(
resourceName
,
resourceKind
,
currentInfos
)
currentObj
,
err
:=
getCurrentObject
(
info
,
currentInfos
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
...
@@ -208,7 +206,7 @@ func (c *Client) Update(namespace string, currentReader, targetReader io.Reader)
...
@@ -208,7 +206,7 @@ func (c *Client) Update(namespace string, currentReader, targetReader io.Reader)
if
alreadyExistErr
,
ok
:=
err
.
(
ErrAlreadyExists
);
ok
{
if
alreadyExistErr
,
ok
:=
err
.
(
ErrAlreadyExists
);
ok
{
log
.
Printf
(
alreadyExistErr
.
errorMsg
)
log
.
Printf
(
alreadyExistErr
.
errorMsg
)
}
else
{
}
else
{
log
.
Printf
(
"error updating the resource %s:
\n\t
%v"
,
resource
Name
,
err
)
log
.
Printf
(
"error updating the resource %s:
\n\t
%v"
,
info
.
Name
,
err
)
updateErrors
=
append
(
updateErrors
,
err
.
Error
())
updateErrors
=
append
(
updateErrors
,
err
.
Error
())
}
}
}
}
...
@@ -220,7 +218,6 @@ func (c *Client) Update(namespace string, currentReader, targetReader io.Reader)
...
@@ -220,7 +218,6 @@ func (c *Client) Update(namespace string, currentReader, targetReader io.Reader)
return
err
return
err
}
else
if
len
(
updateErrors
)
!=
0
{
}
else
if
len
(
updateErrors
)
!=
0
{
return
fmt
.
Errorf
(
strings
.
Join
(
updateErrors
,
" && "
))
return
fmt
.
Errorf
(
strings
.
Join
(
updateErrors
,
" && "
))
}
}
deleteUnwantedResources
(
currentInfos
,
targetInfos
)
deleteUnwantedResources
(
currentInfos
,
targetInfos
)
return
nil
return
nil
...
@@ -419,13 +416,7 @@ func (c *Client) ensureNamespace(namespace string) error {
...
@@ -419,13 +416,7 @@ func (c *Client) ensureNamespace(namespace string) error {
func
deleteUnwantedResources
(
currentInfos
,
targetInfos
[]
*
resource
.
Info
)
{
func
deleteUnwantedResources
(
currentInfos
,
targetInfos
[]
*
resource
.
Info
)
{
for
_
,
cInfo
:=
range
currentInfos
{
for
_
,
cInfo
:=
range
currentInfos
{
found
:=
false
if
_
,
ok
:=
findMatchingInfo
(
cInfo
,
targetInfos
);
!
ok
{
for
_
,
m
:=
range
targetInfos
{
if
m
.
Name
==
cInfo
.
Name
{
found
=
true
}
}
if
!
found
{
log
.
Printf
(
"Deleting %s..."
,
cInfo
.
Name
)
log
.
Printf
(
"Deleting %s..."
,
cInfo
.
Name
)
if
err
:=
deleteResource
(
cInfo
);
err
!=
nil
{
if
err
:=
deleteResource
(
cInfo
);
err
!=
nil
{
log
.
Printf
(
"Failed to delete %s, err: %s"
,
cInfo
.
Name
,
err
)
log
.
Printf
(
"Failed to delete %s, err: %s"
,
cInfo
.
Name
,
err
)
...
@@ -434,20 +425,26 @@ func deleteUnwantedResources(currentInfos, targetInfos []*resource.Info) {
...
@@ -434,20 +425,26 @@ func deleteUnwantedResources(currentInfos, targetInfos []*resource.Info) {
}
}
}
}
func
getCurrentObject
(
targetName
,
targetKind
string
,
infos
[]
*
resource
.
Info
)
(
runtime
.
Object
,
error
)
{
func
getCurrentObject
(
target
*
resource
.
Info
,
infos
[]
*
resource
.
Info
)
(
runtime
.
Object
,
error
)
{
var
curr
*
resource
.
Info
if
found
,
ok
:=
findMatchingInfo
(
target
,
infos
);
ok
{
for
_
,
currInfo
:=
range
infos
{
encoder
:=
api
.
Codecs
.
LegacyCodec
(
registered
.
EnabledVersions
()
...
)
currKind
:=
currInfo
.
Mapping
.
GroupVersionKind
.
Kind
defaultVersion
:=
unversioned
.
GroupVersion
{}
if
currInfo
.
Name
==
targetName
&&
currKind
==
targetKind
{
return
resource
.
AsVersionedObject
([]
*
resource
.
Info
{
found
},
false
,
defaultVersion
,
encoder
)
curr
=
currInfo
}
}
}
return
nil
,
fmt
.
Errorf
(
"No resource with the name %s found."
,
target
.
Name
)
}
if
curr
==
nil
{
// isMatchingInfo returns true if infos match on Name and Kind.
return
nil
,
fmt
.
Errorf
(
"No resource with the name %s found."
,
targetName
)
func
isMatchingInfo
(
a
,
b
*
resource
.
Info
)
bool
{
}
return
a
.
Name
==
b
.
Name
&&
a
.
Mapping
.
GroupVersionKind
.
Kind
==
b
.
Mapping
.
GroupVersionKind
.
Kind
}
encoder
:=
api
.
Codecs
.
LegacyCodec
(
registered
.
EnabledVersions
()
...
)
// findMatchingInfo returns the first object that matches target.
defaultVersion
:=
unversioned
.
GroupVersion
{}
func
findMatchingInfo
(
target
*
resource
.
Info
,
infos
[]
*
resource
.
Info
)
(
*
resource
.
Info
,
bool
)
{
return
resource
.
AsVersionedObject
([]
*
resource
.
Info
{
curr
},
false
,
defaultVersion
,
encoder
)
for
_
,
info
:=
range
infos
{
if
isMatchingInfo
(
target
,
info
)
{
return
info
,
true
}
}
return
nil
,
false
}
}
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