Skip to content

Commit

Permalink
Merge branch 'main' into feat/enhanced-podman-support
Browse files Browse the repository at this point in the history
  • Loading branch information
HarikrishnanBalagopal authored Jan 4, 2024
2 parents 8f404b1 + aa79dfa commit c2a5b40
Show file tree
Hide file tree
Showing 33 changed files with 1,265 additions and 515 deletions.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
GO_VERSION ?= $(shell go run ./scripts/detectgoversion/detect.go 2>/dev/null || printf '1.18')
BINNAME ?= move2kube
IN_CICD ?= false
CGO_ENABLED ?= 0
BINDIR := $(CURDIR)/bin
DISTDIR := $(CURDIR)/_dist
TARGETS := darwin/amd64 darwin/arm64 linux/amd64 linux/arm64 linux/s390x linux/ppc64le windows/amd64
Expand Down Expand Up @@ -102,7 +103,7 @@ build: get $(BINDIR)/$(BINNAME) ## Build go code
@printf "\033[32m-------------------------------------\n BUILD SUCCESS\n-------------------------------------\033[0m\n"

$(BINDIR)/$(BINNAME): $(SRC) $(ASSETS) $(WEB_ASSETS)
CGO_ENABLED=0 go build -ldflags '$(LDFLAGS)' -o $(BINDIR)/$(BINNAME) .
CGO_ENABLED=$(CGO_ENABLED) go build -ldflags '$(LDFLAGS)' -o $(BINDIR)/$(BINNAME) .
mkdir -p $(GOPATH)/bin/
cp $(BINDIR)/$(BINNAME) $(GOPATH)/bin/

Expand Down
71 changes: 71 additions & 0 deletions assets/built-in/qa/qamappings.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
categories:
- name: imageregistry
# or use the flags --enable imageregistry/--disable imageregistry
enabled: true
questions:
- move2kube.target.imageregistry.url
- move2kube.target.imageregistry.namespace
- move2kube.target.imageregistry.*.logintype
- move2kube.target.imageregistry.*.password
- name: sshkeys
enabled: true
questions:
- move2kube.repo.keys.*.key
- move2kube.repo.keys.pub.domain.*.pubkey
- move2kube.repo.keys.pub.load
- move2kube.repo.keys.load
- move2kube.repo.keys.paths
- move2kube.repo.keys.priv.*.password
- name: storage
enabled: true
questions:
- move2kube.storage.type.*.options
- name: sourceanalyzer
enabled: true
questions:
- move2kube.services.*.enable
- move2kube.services.*.statefulset
- move2kube.services.*.containerizationoption
- move2kube.services.*.childProjects.*.publishprofile
- move2kube.services.*.apacheconfig
- move2kube.services.*.pythonmainfile
- move2kube.services.*.pythonstartingfile
- move2kube.services.*.dockerfileType
- move2kube.services.*.childModules.*.enable
- move2kube.services.*.childProjects.*.enable
- move2kube.services.*.childModules.*.springBootProfiles
- move2kube.services.*.mavenProfiles
- name: cluster
enabled: true
questions:
- move2kube.target.*.clustertype
- move2kube.minreplicas
- name: network
enabled: true
questions:
- move2kube.services.*.*.servicetype
- move2kube.services.*.*.urlpath
- move2kube.services.*.ports
- move2kube.target.*.ingress.ingressclassname
- move2kube.target.*.ingress.host
- move2kube.target.*.ingress.tls
- name: git
enabled: true
questions:
- move2kube.vcs.git.name
- move2kube.vcs.git.username
- move2kube.vcs.git.email
- move2kube.vcs.git.pass
- name: cicd
enabled: true
questions:
- move2kube.target.cicd.tekton.gitreposshsecret
- move2kube.target.cicd.tekton.gitrepobasicauthsecret
- move2kube.target.cicd.tekton.registrypushsecret
- move2kube.transformers.kubernetes.argocd.namespace
- name: transformers
enabled: true
questions:
- move2kube.transformerselector
- move2kube.spawncontainers
- move2kube.transformers.types
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ FROM registry.access.redhat.com/ubi8/ubi-minimal:latest
ENV {{$k}} {{$v}}
{{- end }}
RUN microdnf update && microdnf install --nodocs {{ .JavaPackageName }} && microdnf clean all
COPY {{ if .BuildContainerName }}--from= {{ .BuildContainerName }}{{ end }}{{ .DeploymentFilePath }} .
COPY {{ if .BuildContainerName }}--from={{ .BuildContainerName }} {{ end }}{{ .DeploymentFilePath }} .
EXPOSE {{ .Port }}
CMD ["java", "-jar", "{{ .DeploymentFilename }}"]
1 change: 1 addition & 0 deletions assets/filepermissions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"built-in/presets/docker-file-only.yaml" : 0644
"built-in/presets/enable-containerized-transformers.yaml" : 0644
"built-in/presets/use-podman-in-scripts.yaml" : 0644
"built-in/qa/qamappings.yaml" : 0644
"built-in/transformers/cloudfoundry/transformer.yaml" : 0644
"built-in/transformers/cnb/transformer.yaml" : 0644
"built-in/transformers/compose/composeanalyser/transformer.yaml" : 0644
Expand Down
13 changes: 8 additions & 5 deletions cmd/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,14 @@ const (
// maxIterationsFlag is the name of the flag that lets you set the maximum number of iterations to allow
maxIterationsFlag = "max-iterations"
// customizationsFlag is the path to customizations directory
customizationsFlag = "customizations"
qadisablecliFlag = "qa-disable-cli"
qaportFlag = "qa-port"
planProgressPortFlag = "plan-progress-port"
transformerSelectorFlag = "transformer-selector"
customizationsFlag = "customizations"
qadisablecliFlag = "qa-disable-cli"
qaportFlag = "qa-port"
planProgressPortFlag = "plan-progress-port"
maxCloneSizeBytesFlag = "max-clone-size"
transformerSelectorFlag = "transformer-selector"
qaEnabledCategoriesFlag = "qa-enable"
qaDisabledCategoriesFlag = "qa-disable"
)

type qaflags struct {
Expand Down
4 changes: 4 additions & 0 deletions cmd/plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import (
)

type planFlags struct {
maxVCSRepoCloneSize int64
progressServerPort int
planfile string
srcpath string
Expand Down Expand Up @@ -65,6 +66,8 @@ func planHandler(cmd *cobra.Command, flags planFlags) {
}()
defer lib.Destroy()

vcs.SetMaxRepoCloneSize(flags.maxVCSRepoCloneSize)

var err error
planfile := flags.planfile
srcpath := flags.srcpath
Expand Down Expand Up @@ -182,6 +185,7 @@ func GetPlanCommand() *cobra.Command {
planCmd.Flags().StringSliceVar(&flags.preSets, preSetFlag, []string{}, "Specify preset config to use.")
planCmd.Flags().StringArrayVar(&flags.setconfigs, setConfigFlag, []string{}, "Specify config key-value pairs.")
planCmd.Flags().IntVar(&flags.progressServerPort, planProgressPortFlag, 0, "Port for the plan progress server. If not provided, the server won't be started.")
planCmd.Flags().Int64Var(&flags.maxVCSRepoCloneSize, maxCloneSizeBytesFlag, -1, "Max size in bytes when cloning a git repo. Default -1 is infinite")
planCmd.Flags().BoolVar(&flags.disableLocalExecution, common.DisableLocalExecutionFlag, false, "Allow files to be executed locally.")
planCmd.Flags().BoolVar(&flags.failOnEmptyPlan, common.FailOnEmptyPlan, false, "If true, planning will exit with a failure exit code if no services are detected (and no default transformers are found).")

Expand Down
63 changes: 59 additions & 4 deletions cmd/transform.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,23 @@ import (
"path/filepath"
"runtime/pprof"

"github.com/konveyor/move2kube/assets"
"github.com/konveyor/move2kube/common"
"github.com/konveyor/move2kube/common/download"
"github.com/konveyor/move2kube/common/vcs"
"github.com/konveyor/move2kube/lib"
"github.com/konveyor/move2kube/types/plan"
"github.com/konveyor/move2kube/types/qaengine"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"gopkg.in/yaml.v3"
)

type transformFlags struct {
qaflags
// maxVCSRepoCloneSize is the maximum size in bytes for cloning repos
maxVCSRepoCloneSize int64
// ignoreEnv tells us whether to use data collected from the local machine
ignoreEnv bool
// disableLocalExecution disables execution of executables locally
Expand All @@ -54,8 +59,10 @@ type transformFlags struct {
// maxIterations is the maximum number of iterations to allow before aborting with an error
maxIterations int
// CustomizationsPaths contains the path to the customizations directory
customizationsPath string
transformerSelector string
customizationsPath string
transformerSelector string
qaEnabledCategories []string
qaDisabledCategories []string
}

func transformHandler(cmd *cobra.Command, flags transformFlags) {
Expand All @@ -67,6 +74,7 @@ func transformHandler(cmd *cobra.Command, flags transformFlags) {
}
defer pprof.StopCPUProfile()
}
vcs.SetMaxRepoCloneSize(flags.maxVCSRepoCloneSize)

ctx, cancel := context.WithCancel(cmd.Context())
logrus.AddHook(common.NewCleanupHook(cancel))
Expand Down Expand Up @@ -125,10 +133,45 @@ func transformHandler(cmd *cobra.Command, flags transformFlags) {
}
}

// qa-disable and qa=enable are mutually exclusive
if len(flags.qaEnabledCategories) > 0 && len(flags.qaDisabledCategories) > 0 {
logrus.Fatalf("--qa-enable and --qa-disable cannot be used together.\n")
}

// Read the QA categories from the QA mapping file
var qaMapping qaengine.QAMapping
qaMappingFilepath := filepath.Join("built-in/qa", "qamappings.yaml")
file, err := assets.AssetsDir.ReadFile(qaMappingFilepath)
if err != nil {
logrus.Fatalf("failed to read qa-mapping file at %s. Error: %q\n", qaMappingFilepath, err)
}

if err := yaml.Unmarshal(file, &qaMapping); err != nil {
logrus.Fatalf("failed to decode qa-mapping file. Error: %q\n", err)
}

for _, mapping := range qaMapping.Categories {
common.QACategoryMap[mapping.Name] = mapping.Questions
}
common.QACategoryMap["default"] = []string{}
common.QACategoryMap["external"] = []string{}

// Global settings
common.IgnoreEnvironment = flags.ignoreEnv
common.DisableLocalExecution = flags.disableLocalExecution
// Global settings
// if --qa-enable is passed, all categories are disabled by default. Otherwise, only categories passed to --qa-disable
// are disabled
if len(flags.qaEnabledCategories) > 0 {
for k := range common.QACategoryMap {
if !common.IsStringPresent(flags.qaEnabledCategories, k) {
common.DisabledCategories = append(common.DisabledCategories, k)
}
}
} else {
for _, cat := range flags.qaDisabledCategories {
common.DisabledCategories = append(common.DisabledCategories, cat)
}
}

// Parameter cleaning and curate plan
transformationPlan := plan.Plan{}
Expand Down Expand Up @@ -210,7 +253,14 @@ func transformHandler(cmd *cobra.Command, flags transformFlags) {
}
startQA(flags.qaflags)
}
if err := lib.Transform(ctx, transformationPlan, preExistingPlan, flags.outpath, flags.transformerSelector, flags.maxIterations); err != nil {
if err := lib.Transform(
ctx,
transformationPlan,
preExistingPlan,
flags.outpath,
flags.transformerSelector,
flags.maxIterations,
); err != nil {
logrus.Fatalf("failed to transform. Error: %q", err)
}
logrus.Infof("Transformed target artifacts can be found at [%s].", flags.outpath)
Expand Down Expand Up @@ -250,6 +300,11 @@ func GetTransformCommand() *cobra.Command {
transformCmd.Flags().StringVarP(&flags.customizationsPath, customizationsFlag, "c", "", "Specify directory or a git url (see https://move2kube.konveyor.io/concepts/git-support) where customizations are stored. By default we look for "+common.DefaultCustomizationDir)
transformCmd.Flags().StringVarP(&flags.transformerSelector, transformerSelectorFlag, "t", "", "Specify the transformer selector.")
transformCmd.Flags().BoolVar(&flags.qaskip, qaSkipFlag, false, "Enable/disable the default answers to questions posed in QA Cli sub-system. If disabled, you will have to answer the questions posed by QA during interaction.")
transformCmd.Flags().Int64Var(&flags.maxVCSRepoCloneSize, maxCloneSizeBytesFlag, -1, "Max size in bytes when cloning a git repo. Default -1 is infinite")

// QA options
transformCmd.Flags().StringSliceVar(&flags.qaEnabledCategories, qaEnabledCategoriesFlag, []string{}, "Specify the QA categories to enable (cannot be used in conjunction with qa-disable)")
transformCmd.Flags().StringSliceVar(&flags.qaDisabledCategories, qaDisabledCategoriesFlag, []string{}, "Specify the QA categories to disable (cannot be used in conjunction with qa-enable)")

// Advanced options
transformCmd.Flags().BoolVar(&flags.ignoreEnv, ignoreEnvFlag, false, "Ignore data from local machine.")
Expand Down
20 changes: 18 additions & 2 deletions common/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ const (
ConfigStoragesKey = BaseKey + d + "storages"
//ConfigMinReplicasKey represents Ingress host Key
ConfigMinReplicasKey = BaseKey + d + "minreplicas"
//ConfigStatefulSetKey represents whether the IR should generate a StatefulSet
ConfigStatefulSetKey = "statefulset"
//ConfigDeploymentTypeKey represents which type of Deployment should be generated
ConfigDeploymentTypeKey = "deployment"
//ConfigPortsForServiceKeySegment represents the ports used for service
ConfigPortsForServiceKeySegment = "ports"
//ConfigPortForServiceKeySegment represents the port used for service
Expand Down Expand Up @@ -143,6 +143,16 @@ const (
ConfigIngressHostKeySuffix = IngressKey + d + "host"
//ConfigIngressTLSKeySuffix represents ingress tls Key
ConfigIngressTLSKeySuffix = IngressKey + d + "tls"
//RouteKey represents route keyword
RouteKey = "route"
//TLSKey represents TLS keyword
TLSKey = "tls"
//ConfigRouteTLSTerminationPolicy represents the Route's TLS Termination Policy
ConfigRouteTLSTerminationPolicy = RouteKey + d + TLSKey + d + "terminationpolicy"
//ConfigRouteTLSKeyKey represents the Route's TLS Key
ConfigRouteTLSKeyKey = RouteKey + d + TLSKey + d + "key"
//ConfigRouteTLSCertificateKey represents the Route's TLS Certificate
ConfigRouteTLSCertificateKey = RouteKey + d + TLSKey + d + "certificate"
//ConfigTargetClusterTypeKey represents target cluster type key
ConfigTargetClusterTypeKey = ConfigTargetKey + d + "clustertype"
//ConfigImageRegistryKey represents image registry Key
Expand Down Expand Up @@ -193,6 +203,8 @@ const (
ConfigServicesChildModulesSpringProfilesKey = ConfigServicesKey + d + "%s" + d + "childModules" + d + "%s" + d + "springBootProfiles"
// ConfigTransformersKubernetesArgoCDNamespaceKey represents namespace key for argocd transformer
ConfigTransformersKubernetesArgoCDNamespaceKey = ConfigTransformersKey + d + "kubernetes" + d + "argocd" + d + "namespace"
// ConfigArgoRolloutTypeKey represents the type of Rollout that should be generated.
ConfigArgoRolloutTypeKey = "argorollout"
//VCSKey represents version control system key
VCSKey = BaseKey + d + "vcs"
//GitKey represents git qa key
Expand Down Expand Up @@ -232,6 +244,10 @@ var (
DisableLocalExecution = false
// DefaultIgnoreDirRegexps specifies directory name regexes that would be ignored
DefaultIgnoreDirRegexps = []*regexp.Regexp{regexp.MustCompile("^[.].*")}
// DisabledCategories is a list of QA categories that are disabled
DisabledCategories = []string{}
// QACategoryMap maps category names to problem IDs
QACategoryMap = map[string][]string{}
// disallowedDNSCharactersRegex provides pattern for characters not allowed in a DNS Name
disallowedDNSCharactersRegex = regexp.MustCompile(`[^a-z0-9\-]`)
// disallowedEnvironmentCharactersRegex provides pattern for characters not allowed in a DNS Name
Expand Down
2 changes: 1 addition & 1 deletion common/sshkeys/sshkeys.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func loadSSHKeysOfCurrentUser() {
message := `The CI/CD pipeline needs access to the git repos in order to clone, build and push.
If any of the repos require ssh keys you will need to provide them.
Select an option:`
selectedOption := qaengine.FetchSelectAnswer(common.ConfigRepoLoadPrivKey, message, nil, "", options, nil)
selectedOption := qaengine.FetchSelectAnswer(common.ConfigRepoLoadPrivKey, message, nil, options[2], options, nil)
switch selectedOption {
case options[0]:
selectedKeyFilenames, err := loadKeysFromDirectory(privateKeyDir)
Expand Down
Loading

0 comments on commit c2a5b40

Please sign in to comment.