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
0433a30f
Commit
0433a30f
authored
Feb 11, 2019
by
Jingfang Liu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add function to run kustomize build
parent
74a64a9f
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
183 additions
and
0 deletions
+183
-0
BUILD
staging/src/BUILD
+1
-0
builder.go
staging/src/k8s.io/cli-runtime/pkg/kustomize/builder.go
+32
-0
builder_test.go
staging/src/k8s.io/cli-runtime/pkg/kustomize/builder_test.go
+150
-0
No files found.
staging/src/BUILD
View file @
0433a30f
...
...
@@ -110,6 +110,7 @@ filegroup(
"//staging/src/k8s.io/apiserver/plugin/pkg/authorizer/webhook:all-srcs",
"//staging/src/k8s.io/cli-runtime/artifacts:all-srcs",
"//staging/src/k8s.io/cli-runtime/pkg/genericclioptions:all-srcs",
"//staging/src/k8s.io/cli-runtime/pkg/kustomize:all-srcs",
"//staging/src/k8s.io/client-go/deprecated-dynamic:all-srcs",
"//staging/src/k8s.io/client-go/discovery:all-srcs",
"//staging/src/k8s.io/client-go/dynamic:all-srcs",
...
...
staging/src/k8s.io/cli-runtime/pkg/kustomize/builder.go
0 → 100644
View file @
0433a30f
/*
Copyright 2019 The Kubernetes Authors.
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
kustomize
import
(
"io"
"k8s.io/cli-runtime/pkg/kustomize/k8sdeps"
"sigs.k8s.io/kustomize/pkg/commands/build"
"sigs.k8s.io/kustomize/pkg/fs"
)
// RunKustomizeBuild runs kustomize build given a filesystem and a path
func
RunKustomizeBuild
(
out
io
.
Writer
,
fSys
fs
.
FileSystem
,
path
string
)
error
{
f
:=
k8sdeps
.
NewFactory
()
o
:=
build
.
NewOptions
(
path
,
""
)
return
o
.
RunBuild
(
out
,
fSys
,
f
.
ResmapF
,
f
.
TransformerF
)
}
staging/src/k8s.io/cli-runtime/pkg/kustomize/builder_test.go
0 → 100644
View file @
0433a30f
/*
Copyright 2019 The Kubernetes Authors.
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
kustomize
import
(
"bytes"
"testing"
"sigs.k8s.io/kustomize/pkg/fs"
)
const
(
kustomizationContent1
=
`
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
namePrefix: foo-
nameSuffix: -bar
namespace: ns1
commonLabels:
app: nginx
commonAnnotations:
note: This is a test annotation
resources:
- deployment.yaml
- namespace.yaml
configMapGenerator:
- name: literalConfigMap
literals:
- DB_USERNAME=admin
- DB_PASSWORD=somepw
secretGenerator:
- name: secret
literals:
- DB_USERNAME=admin
- DB_PASSWORD=somepw
type: Opaque
patchesJson6902:
- target:
group: apps
version: v1
kind: Deployment
name: dply1
path: jsonpatch.json
`
deploymentContent
=
`
apiVersion: apps/v1
metadata:
name: dply1
kind: Deployment
`
namespaceContent
=
`
apiVersion: v1
kind: Namespace
metadata:
name: ns1
`
jsonpatchContent
=
`[
{"op": "add", "path": "/spec/replica", "value": "3"}
]`
expectedContent
=
`apiVersion: v1
kind: Namespace
metadata:
annotations:
note: This is a test annotation
labels:
app: nginx
name: foo-ns1-bar
---
apiVersion: v1
data:
DB_PASSWORD: somepw
DB_USERNAME: admin
kind: ConfigMap
metadata:
annotations:
note: This is a test annotation
labels:
app: nginx
name: foo-literalConfigMap-bar-8d2dkb8k24
namespace: ns1
---
apiVersion: v1
data:
DB_PASSWORD: c29tZXB3
DB_USERNAME: YWRtaW4=
kind: Secret
metadata:
annotations:
note: This is a test annotation
labels:
app: nginx
name: foo-secret-bar-9btc7bt4kb
namespace: ns1
type: Opaque
---
apiVersion: apps/v1
kind: Deployment
metadata:
annotations:
note: This is a test annotation
labels:
app: nginx
name: foo-dply1-bar
namespace: ns1
spec:
replica: "3"
selector:
matchLabels:
app: nginx
template:
metadata:
annotations:
note: This is a test annotation
labels:
app: nginx
`
)
func
TestResources1
(
t
*
testing
.
T
)
{
fSys
:=
fs
.
MakeFakeFS
()
fSys
.
WriteFile
(
"/kustomization.yaml"
,
[]
byte
(
kustomizationContent1
))
fSys
.
WriteFile
(
"/deployment.yaml"
,
[]
byte
(
deploymentContent
))
fSys
.
WriteFile
(
"/namespace.yaml"
,
[]
byte
(
namespaceContent
))
fSys
.
WriteFile
(
"/jsonpatch.json"
,
[]
byte
(
jsonpatchContent
))
var
out
bytes
.
Buffer
err
:=
RunKustomizeBuild
(
&
out
,
fSys
,
"/"
)
if
err
!=
nil
{
t
.
Fatalf
(
"unexpected Resources error %v"
,
err
)
}
if
out
.
String
()
!=
expectedContent
{
t
.
Fatalf
(
"expected:
\n
%s
\n
but got:
\n
%s"
,
expectedContent
,
out
.
String
())
}
}
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