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
ed0dcb74
Commit
ed0dcb74
authored
Dec 01, 2017
by
ymqytw
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
build patch from openapi only for registered types
parent
db2977fb
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
34 additions
and
32 deletions
+34
-32
apply.go
pkg/kubectl/cmd/apply.go
+34
-32
No files found.
pkg/kubectl/cmd/apply.go
View file @
ed0dcb74
...
@@ -604,42 +604,44 @@ func (p *patcher) patchSimple(obj runtime.Object, modified []byte, source, names
...
@@ -604,42 +604,44 @@ func (p *patcher) patchSimple(obj runtime.Object, modified []byte, source, names
var
lookupPatchMeta
strategicpatch
.
LookupPatchMeta
var
lookupPatchMeta
strategicpatch
.
LookupPatchMeta
var
schema
oapi
.
Schema
var
schema
oapi
.
Schema
createPatchErrFormat
:=
"creating patch with:
\n
original:
\n
%s
\n
modified:
\n
%s
\n
current:
\n
%s
\n
for:"
createPatchErrFormat
:=
"creating patch with:
\n
original:
\n
%s
\n
modified:
\n
%s
\n
current:
\n
%s
\n
for:"
// Try to use openapi first if the openapi spec is available and can successfully calculate the patch.
// Otherwise, fall back to baked-in types.
// Create the versioned struct from the type defined in the restmapping
if
p
.
openapiSchema
!=
nil
{
// (which is the API version we'll be submitting the patch to)
if
schema
=
p
.
openapiSchema
.
LookupResource
(
p
.
mapping
.
GroupVersionKind
);
schema
!=
nil
{
versionedObject
,
err
:=
scheme
.
Scheme
.
New
(
p
.
mapping
.
GroupVersionKind
)
lookupPatchMeta
=
strategicpatch
.
PatchMetaFromOpenAPI
{
Schema
:
schema
}
switch
{
if
openapiPatch
,
err
:=
strategicpatch
.
CreateThreeWayMergePatch
(
original
,
modified
,
current
,
lookupPatchMeta
,
p
.
overwrite
);
err
!=
nil
{
case
runtime
.
IsNotRegisteredError
(
err
)
:
fmt
.
Fprintf
(
errOut
,
"warning: error calculating patch from openapi spec: %v
\n
"
,
err
)
// fall back to generic JSON merge patch
}
else
{
patchType
=
types
.
MergePatchType
patchType
=
types
.
StrategicMergePatchType
preconditions
:=
[]
mergepatch
.
PreconditionFunc
{
mergepatch
.
RequireKeyUnchanged
(
"apiVersion"
),
patch
=
openapiPatch
mergepatch
.
RequireKeyUnchanged
(
"kind"
),
mergepatch
.
RequireMetadataKeyUnchanged
(
"name"
)}
patch
,
err
=
jsonmergepatch
.
CreateThreeWayJSONMergePatch
(
original
,
modified
,
current
,
preconditions
...
)
if
err
!=
nil
{
if
mergepatch
.
IsPreconditionFailed
(
err
)
{
return
nil
,
nil
,
fmt
.
Errorf
(
"%s"
,
"At least one of apiVersion, kind and name was changed"
)
}
}
return
nil
,
nil
,
cmdutil
.
AddSourceToErr
(
fmt
.
Sprintf
(
createPatchErrFormat
,
original
,
modified
,
current
),
source
,
err
)
}
}
}
case
err
!=
nil
:
return
nil
,
nil
,
cmdutil
.
AddSourceToErr
(
fmt
.
Sprintf
(
"getting instance of versioned object for %v:"
,
p
.
mapping
.
GroupVersionKind
),
source
,
err
)
if
patch
==
nil
{
case
err
==
nil
:
// C
reate the versioned struct from the type defined in the restmapping
// C
ompute a three way strategic merge patch to send to server.
// (which is the API version we'll be submitting the patch to)
patchType
=
types
.
StrategicMergePatchType
versionedObject
,
err
:=
scheme
.
Scheme
.
New
(
p
.
mapping
.
GroupVersionKind
)
switch
{
// Try to use openapi first if the openapi spec is available and can successfully calculate the patch.
case
runtime
.
IsNotRegisteredError
(
err
)
:
// Otherwise, fall back to baked-in types.
// fall back to generic JSON merge patch
if
p
.
openapiSchema
!=
nil
{
patchType
=
types
.
MergePatchType
if
schema
=
p
.
openapiSchema
.
LookupResource
(
p
.
mapping
.
GroupVersionKind
);
schema
!=
nil
{
preconditions
:=
[]
mergepatch
.
PreconditionFunc
{
mergepatch
.
RequireKeyUnchanged
(
"apiVersion"
),
lookupPatchMeta
=
strategicpatch
.
PatchMetaFromOpenAPI
{
Schema
:
schema
}
mergepatch
.
RequireKeyUnchanged
(
"kind"
),
mergepatch
.
RequireMetadataKeyUnchanged
(
"name"
)}
if
openapiPatch
,
err
:=
strategicpatch
.
CreateThreeWayMergePatch
(
original
,
modified
,
current
,
lookupPatchMeta
,
p
.
overwrite
);
err
!=
nil
{
patch
,
err
=
jsonmergepatch
.
CreateThreeWayJSONMergePatch
(
original
,
modified
,
current
,
preconditions
...
)
fmt
.
Fprintf
(
errOut
,
"warning: error calculating patch from openapi spec: %v
\n
"
,
err
)
if
err
!=
nil
{
}
else
{
if
mergepatch
.
IsPreconditionFailed
(
err
)
{
patchType
=
types
.
StrategicMergePatchType
return
nil
,
nil
,
fmt
.
Errorf
(
"%s"
,
"At least one of apiVersion, kind and name was changed"
)
patch
=
openapiPatch
}
}
return
nil
,
nil
,
cmdutil
.
AddSourceToErr
(
fmt
.
Sprintf
(
createPatchErrFormat
,
original
,
modified
,
current
),
source
,
err
)
}
}
case
err
!=
nil
:
}
return
nil
,
nil
,
cmdutil
.
AddSourceToErr
(
fmt
.
Sprintf
(
"getting instance of versioned object for %v:"
,
p
.
mapping
.
GroupVersionKind
),
source
,
err
)
case
err
==
nil
:
if
patch
==
nil
{
// Compute a three way strategic merge patch to send to server.
patchType
=
types
.
StrategicMergePatchType
lookupPatchMeta
,
err
=
strategicpatch
.
NewPatchMetaFromStruct
(
versionedObject
)
lookupPatchMeta
,
err
=
strategicpatch
.
NewPatchMetaFromStruct
(
versionedObject
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
nil
,
cmdutil
.
AddSourceToErr
(
fmt
.
Sprintf
(
createPatchErrFormat
,
original
,
modified
,
current
),
source
,
err
)
return
nil
,
nil
,
cmdutil
.
AddSourceToErr
(
fmt
.
Sprintf
(
createPatchErrFormat
,
original
,
modified
,
current
),
source
,
err
)
...
...
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