-
Notifications
You must be signed in to change notification settings - Fork 120
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Added Parameterizer Transformer (#554)
Signed-off-by: Ashok Pon Kumar <[email protected]> Co-authored-by: Harikrishnan Balagopal <[email protected]>
- Loading branch information
1 parent
e7fff68
commit 8660f0b
Showing
68 changed files
with
1,053 additions
and
1,436 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/* | ||
* Copyright IBM Corporation 2021 | ||
* | ||
* 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 api | ||
|
||
import ( | ||
"path/filepath" | ||
|
||
"github.com/konveyor/move2kube/internal/common" | ||
"github.com/konveyor/move2kube/parameterizer" | ||
parameterizertypes "github.com/konveyor/move2kube/types/parameterizer" | ||
"github.com/sirupsen/logrus" | ||
) | ||
|
||
// Parameterize does the parameterization | ||
func Parameterize(srcDir string, packDir string, outDir string) ([]string, error) { | ||
cleanPackDir, err := filepath.Abs(packDir) | ||
if err != nil { | ||
return nil, err | ||
} | ||
packs, err := collectPacksFromPath(cleanPackDir) | ||
if err != nil { | ||
return nil, err | ||
} | ||
namedPs, err := parameterizer.CollectParamsFromPath(cleanPackDir) | ||
if err != nil { | ||
return nil, err | ||
} | ||
filesWritten := []string{} | ||
for _, pack := range packs { | ||
ps := []parameterizertypes.ParameterizerT{} | ||
for _, name := range pack.Spec.ParameterizerRefs { | ||
if currPs, ok := namedPs[name]; ok { | ||
ps = append(ps, currPs...) | ||
continue | ||
} | ||
logrus.Errorf("failed to find the paramterizers with the name %s referred to by the packaging with the name %s , in the folder %s", name, pack.ObjectMeta.Name, cleanPackDir) | ||
} | ||
ps = append(ps, pack.Spec.Parameterizers...) | ||
for _, path := range pack.Spec.Paths { | ||
fw, err := parameterizer.Parameterize(srcDir, outDir, path, ps) | ||
if err != nil { | ||
logrus.Errorf("Unable to process path %s : %s", path.Src, err) | ||
continue | ||
} | ||
filesWritten = append(filesWritten, fw...) | ||
} | ||
} | ||
return filesWritten, nil | ||
} | ||
|
||
func collectPacksFromPath(packDir string) ([]parameterizertypes.PackagingFileT, error) { | ||
yamlPaths, err := common.GetFilesByExt(packDir, []string{".yaml", ".yml"}) | ||
if err != nil { | ||
return nil, err | ||
} | ||
packs := []parameterizertypes.PackagingFileT{} | ||
for _, yamlPath := range yamlPaths { | ||
pack := parameterizertypes.PackagingFileT{ | ||
Spec: parameterizertypes.PackagingSpecT{ | ||
FilePath: yamlPath, | ||
}, | ||
} | ||
if err := common.ReadMove2KubeYamlStrict(yamlPath, &pack, parameterizertypes.PackagingKind); err == nil { | ||
logrus.Debugf("found packing yaml at path %s", yamlPath) | ||
packs = append(packs, pack) | ||
continue | ||
} | ||
} | ||
return packs, nil | ||
} |
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
9 changes: 9 additions & 0 deletions
9
assets/inbuilt/transformers/generators/parameterziers/parameterizers.yaml
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,9 @@ | ||
apiVersion: move2kube.konveyor.io/v1alpha1 | ||
kind: Transformer | ||
metadata: | ||
name: Parameterizer | ||
spec: | ||
mode: "Container" | ||
class: "Parameterizer" | ||
consumes: | ||
- "KubernetesYamls" |
This file was deleted.
Oops, something went wrong.
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,65 @@ | ||
/* | ||
* Copyright IBM Corporation 2021 | ||
* | ||
* 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 main | ||
|
||
const ( | ||
// sourceFlag is the name of the flag that contains path to the source folder | ||
sourceFlag = "source" | ||
// outputFlag is the name of the flag that contains path to the output folder | ||
outputFlag = "output" | ||
// nameFlag is the name of the flag that contains the project name | ||
nameFlag = "name" | ||
// planFlag is the name of the flag that contains the path to the plan file | ||
planFlag = "plan" | ||
// ignoreEnvFlag is the name of the flag that tells us whether to use data collected from the local machine | ||
ignoreEnvFlag = "ignoreenv" | ||
// qaSkipFlag is the name of the flag that lets you skip all the question answers | ||
qaSkipFlag = "qaskip" | ||
// configOutFlag is the name of the flag that will point the location to output the config file | ||
configOutFlag = "configout" | ||
// qaCacheOutFlag is the name of the flag that will point the location to output the cache file | ||
qaCacheOutFlag = "qacacheout" | ||
// configFlag is the name of the flag that contains list of config files | ||
configFlag = "config" | ||
// setConfigFlag is the name of the flag that contains list of key-value configs | ||
setConfigFlag = "setconfig" | ||
// preSetFlag is the name of the flag that contains list of preset configurations to use | ||
preSetFlag = "preset" | ||
// overwriteFlag is the name of the flag that lets you overwrite the output directory if it exists | ||
overwriteFlag = "overwrite" | ||
// customizationsFlag is the path to customizations directory | ||
customizationsFlag = "customizations" | ||
qadisablecliFlag = "qadisablecli" | ||
qaportFlag = "qaport" | ||
) | ||
|
||
type qaflags struct { | ||
qadisablecli bool | ||
qaport int | ||
// configOut contains the location to output the config | ||
configOut string | ||
// qaCacheOut contains the location to output the cache | ||
qaCacheOut string | ||
// configs contains a list of config files | ||
configs []string | ||
// Configs contains a list of key-value configs | ||
setconfigs []string | ||
// qaskip lets you skip all the question answers | ||
qaskip bool | ||
// preSets contains a list of preset configurations | ||
preSets []string | ||
} |
Oops, something went wrong.