Skip to content

Commit

Permalink
Fix bug with empty git domain. Set RootDir after loading plan. Added …
Browse files Browse the repository at this point in the history
…struct yaml tags for new fields.

Signed-off-by: Harikrishnan Balagopal <Harikrishnan.Balagopal@ibm.com>
  • Loading branch information
HarikrishnanBalagopal authored and ashokponkumar committed Oct 14, 2020
1 parent 9ca9fae commit 93ef9f7
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 16 deletions.
3 changes: 2 additions & 1 deletion cmd/move2kube/translate.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ var translateCmd = &cobra.Command{
if err != nil {
log.Fatalf("Unable to read plan : %s", err)
}
p.Spec.Inputs.SetRootDir(p.Spec.Inputs.RootDir) // Since AbsRootDir and RelRootDir are not serialized. Also cleans up the user input path.
if cmd.Flags().Changed(nameFlag) {
p.Name = name
}
Expand All @@ -96,7 +97,7 @@ var translateCmd = &cobra.Command{
}
}
if srcpath != "" {
p.Spec.Inputs.RootDir = srcpath
p.Spec.Inputs.SetRootDir(srcpath)
}
fi, err = os.Stat(p.Spec.Inputs.RootDir)
if os.IsNotExist(err) {
Expand Down
13 changes: 13 additions & 0 deletions internal/apiresourceset/tektonapiresourceset.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,20 +114,33 @@ func (*TektonAPIResourceSet) CreateResources(ir irtypes.IR) []runtime.Object {
func createGitSecrets(gitSecretNamePrefix string, ir irtypes.IR) [](*corev1.Secret) {
secrets := [](*corev1.Secret){}
gitDomains := []string{}

for _, container := range ir.Containers {
gitRepoURL, err := giturls.Parse(container.RepoInfo.GitRepoURL)
if err != nil {
log.Warnf("Failed to parse git repo url %q Error: %q", container.RepoInfo.GitRepoURL, err)
continue
}
if gitRepoURL.Hostname() == "" {
continue
}
gitDomains = append(gitDomains, gitRepoURL.Hostname())
}

gitDomains = common.UniqueStrings(gitDomains)
if len(gitDomains) == 0 {
log.Warn("No remote git repos found. CI/CD pipeline requires a remote git repo to pull the source code from.")
gitSecretName := common.MakeStringDNSSubdomainNameCompliant(gitSecretNamePrefix)
secrets = append(secrets, createGitSecret(gitSecretName, ""))
return secrets
}

for _, gitDomain := range gitDomains {
gitSecretName := fmt.Sprintf("%s-%s", gitSecretNamePrefix, gitDomain)
gitSecretName = common.MakeStringDNSSubdomainNameCompliant(gitSecretName)
secrets = append(secrets, createGitSecret(gitSecretName, gitDomain))
}

return secrets
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
containerbuildtype: NewDockerfile
repoinfo:
gitrepodir: ""
gitrepourl: ""
gitrepobranch: ""
targetpath: Dockerfile.dockerfile
gitRepoDir: ""
gitRepoURL: ""
gitRepoBranch: ""
targetPath: Dockerfile.dockerfile
imagenames:
- dockerfile:latest
new: true
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
containerbuildtype: S2I
repoinfo:
gitrepodir: ""
gitrepourl: ""
gitrepobranch: ""
targetpath: ""
gitRepoDir: ""
gitRepoURL: ""
gitRepoBranch: ""
targetPath: ""
imagenames:
- nodejs:latest
new: true
Expand Down
14 changes: 7 additions & 7 deletions types/plan/plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,8 @@ func (output *KubernetesOutput) Merge(newoutput KubernetesOutput) {

// Inputs defines the input section of plan
type Inputs struct {
AbsRootDir string `yaml:"absRootDir"`
RelRootDir string `yaml:"relRootDir"`
AbsRootDir string `yaml:"-"`
RelRootDir string `yaml:"-"`
RootDir string `yaml:"rootDir"`
K8sFiles []string `yaml:"kubernetesYamls,omitempty"`
QACaches []string `yaml:"qaCaches,omitempty"`
Expand Down Expand Up @@ -220,15 +220,15 @@ func (inputs *Inputs) SetRootDir(path string) error {

// RepoInfo contains information specific to creating the CI/CD pipeline.
type RepoInfo struct {
GitRepoDir string
GitRepoURL string
GitRepoBranch string
TargetPath string
GitRepoDir string `yaml:"gitRepoDir"`
GitRepoURL string `yaml:"gitRepoURL"`
GitRepoBranch string `yaml:"gitRepoBranch"`
TargetPath string `yaml:"targetPath"`
}

// Service defines a plan service
type Service struct {
RepoInfo RepoInfo
RepoInfo RepoInfo `yaml:"repoInfo,omitempty"`
ServiceName string `yaml:"serviceName"`
Image string `yaml:"image"`
TranslationType TranslationTypeValue `yaml:"translationType"`
Expand Down

0 comments on commit 93ef9f7

Please sign in to comment.