-
Notifications
You must be signed in to change notification settings - Fork 226
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
144 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// Copyright 2020 Google LLC | ||
// | ||
// 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 orchestrators | ||
|
||
import ( | ||
"github.com/GoogleContainerTools/kpt/internal/cmdexport/types" | ||
"sigs.k8s.io/kustomize/kyaml/yaml" | ||
) | ||
|
||
// CloudBuild is a simplified representation of Cloud Build config. | ||
// @see https://cloud.google.com/cloud-build/docs/build-config | ||
type CloudBuild struct { | ||
Steps []CloudBuildStep `yaml:",omitempty"` | ||
} | ||
|
||
type CloudBuildStep struct { | ||
Name string `yaml:",omitempty"` | ||
Args []string `yaml:",omitempty"` | ||
} | ||
|
||
func (p *CloudBuild) Init(config *types.PipelineConfig) Pipeline { | ||
step := CloudBuildStep{} | ||
step.Name = KptImage | ||
step.Args = []string{ | ||
"fn", | ||
"run", | ||
config.Dir, | ||
} | ||
|
||
if fnPaths := config.FnPaths; len(fnPaths) > 0 { | ||
step.Args = append( | ||
step.Args, | ||
append( | ||
[]string{"--fn-path"}, | ||
fnPaths... | ||
)... | ||
) | ||
} | ||
|
||
p.Steps = []CloudBuildStep{step} | ||
|
||
return p | ||
} | ||
|
||
func (p *CloudBuild) Generate() []byte { | ||
data, _ := yaml.Marshal(p) | ||
|
||
return data | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
// Copyright 2020 Google LLC | ||
// | ||
// 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 orchestrators | ||
|
||
import "github.com/GoogleContainerTools/kpt/internal/cmdexport/types" | ||
|
||
var cloudBuildTestCases = []testCase{ | ||
{ | ||
description: "generates a Cloud Build pipeline", | ||
config: &types.PipelineConfig{ | ||
Dir: ".", | ||
FnPaths: nil, | ||
}, | ||
expected: ` | ||
steps: | ||
- name: gongpu/kpt:latest | ||
args: | ||
- fn | ||
- run | ||
- . | ||
`, | ||
}, | ||
{ | ||
description: "generates a Cloud Build pipeline with --fn-path", | ||
config: &types.PipelineConfig{ | ||
Dir: "resources", | ||
FnPaths: []string{"config/function.yaml"}, | ||
}, | ||
expected: ` | ||
steps: | ||
- name: gongpu/kpt:latest | ||
args: | ||
- fn | ||
- run | ||
- resources | ||
- --fn-path | ||
- config/function.yaml | ||
`, | ||
}, | ||
{ | ||
description: "generates a Cloud Build pipeline with multiple --fn-path", | ||
config: &types.PipelineConfig{ | ||
Dir: "resources", | ||
FnPaths: []string{"config/function1.yaml", "config/function2.yaml"}, | ||
}, | ||
expected: ` | ||
steps: | ||
- name: gongpu/kpt:latest | ||
args: | ||
- fn | ||
- run | ||
- resources | ||
- --fn-path | ||
- config/function1.yaml | ||
- config/function2.yaml | ||
`, | ||
}, | ||
} | ||
|
||
var cloudBuildTestSuite = testSuite{ | ||
pipeline: &CloudBuild{}, | ||
testCases: cloudBuildTestCases, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters