Skip to content

Commit

Permalink
feat: Added Parameterizer Transformer (#554)
Browse files Browse the repository at this point in the history
Signed-off-by: Ashok Pon Kumar <[email protected]>
Co-authored-by: Harikrishnan Balagopal <[email protected]>
  • Loading branch information
ashokponkumar and HarikrishnanBalagopal authored Jul 8, 2021
1 parent e7fff68 commit 8660f0b
Show file tree
Hide file tree
Showing 68 changed files with 1,053 additions and 1,436 deletions.
84 changes: 84 additions & 0 deletions api/parameterizer.go
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
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package parameterizer_test
package api_test

import (
"io/ioutil"
Expand All @@ -23,7 +23,7 @@ import (
"testing"

"github.com/google/go-cmp/cmp"
"github.com/konveyor/move2kube/parameterizer"
"github.com/konveyor/move2kube/api"
log "github.com/sirupsen/logrus"
)

Expand All @@ -39,7 +39,7 @@ func TestGettingAndParameterizingResources(t *testing.T) {
k8sResourcesPath := filepath.Join(baseDir, "k8s-resources")
outputPath := t.TempDir()

filesWritten, err := parameterizer.Top(k8sResourcesPath, parameterizersPath, outputPath)
filesWritten, err := api.Parameterize(k8sResourcesPath, parameterizersPath, outputPath)
if err != nil {
t.Fatalf("Failed to apply all the parameterizations. Error: %q", err)
}
Expand Down
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.
1 change: 1 addition & 0 deletions assets/filepermissions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
"inbuilt/transformers/generators/containerimagespushscript/templates/pushimages.sh" : 0755
"inbuilt/transformers/generators/knative/knative.yaml" : 0644
"inbuilt/transformers/generators/kubernetes/kubernetes.yaml" : 0644
"inbuilt/transformers/generators/parameterziers/parameterizers.yaml" : 0644
"inbuilt/transformers/generators/readmegenerator/readmegenerator.yaml" : 0644
"inbuilt/transformers/generators/readmegenerator/templates/Readme.md" : 0644
"inbuilt/transformers/generators/tekton/tekton.yaml" : 0644
Expand Down
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"
172 changes: 0 additions & 172 deletions cmd/common/utils.go

This file was deleted.

5 changes: 2 additions & 3 deletions cmd/move2kube/collect.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"strings"

"github.com/konveyor/move2kube/api"
cmdcommon "github.com/konveyor/move2kube/cmd/common"
"github.com/konveyor/move2kube/types"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -81,8 +80,8 @@ func getCollectCommand() *cobra.Command {
}

collectCmd.Flags().StringVarP(&flags.annotations, "annotations", "a", "", "Specify annotations to select collector subset.")
collectCmd.Flags().StringVarP(&flags.outpath, cmdcommon.OutputFlag, "o", ".", "Specify output directory for collect.")
collectCmd.Flags().StringVarP(&flags.srcpath, cmdcommon.SourceFlag, "s", "", "Specify source directory for the artifacts to be considered while collecting.")
collectCmd.Flags().StringVarP(&flags.outpath, outputFlag, "o", ".", "Specify output directory for collect.")
collectCmd.Flags().StringVarP(&flags.srcpath, sourceFlag, "s", "", "Specify source directory for the artifacts to be considered while collecting.")

return collectCmd
}
65 changes: 65 additions & 0 deletions cmd/move2kube/flags.go
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
}
Loading

0 comments on commit 8660f0b

Please sign in to comment.