Skip to content

Commit

Permalink
Merge pull request #370 from joker00777/feature/serviceNames
Browse files Browse the repository at this point in the history
check all service names
  • Loading branch information
jenkins-x-bot authored Jun 20, 2022
2 parents cebab1c + 1f8db5f commit 49d1a53
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
20 changes: 16 additions & 4 deletions pkg/cmd/create/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,18 @@ func (o *Options) createPreviewNamespace() (string, error) {
return prNamespace, nil
}

func findAllServiceNamesInNamespace(client kubernetes.Interface, namespace string) ([]string, error) {
services, err := client.CoreV1().Services(namespace).List(context.TODO(), metav1.ListOptions{})
if err != nil {
return nil, err
}
appNames := []string{}
for _, service := range services.Items {
appNames = append(appNames, service.Name)
}
return appNames, nil
}

// findPreviewURL finds the preview URL
func (o *Options) findPreviewURL(envVars map[string]string) (string, error) {

Expand Down Expand Up @@ -463,12 +475,12 @@ func (o *Options) findPreviewURL(envVars map[string]string) (string, error) {

log.Logger().Infof("found helm preview release %s in namespace %s", info(releaseName), info(releaseNamespace))

application := o.Repository
app := naming.ToValidName(application)

appNames := []string{o.PreviewService}
if o.PreviewService == "" {
appNames = []string{app, releaseName, o.Namespace + "-preview", releaseName + "-" + app}
appNames, err = findAllServiceNamesInNamespace(o.KubeClient, releaseNamespace)
if err != nil {
return "", fmt.Errorf("%v finding services in the preview namespace \n", err)
}
}

ctx := context.Background()
Expand Down
3 changes: 2 additions & 1 deletion pkg/cmd/create/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ func AssertPreview(t *testing.T, customService string) {
buildNumber := "2"
sha := "abcdef1234"
previewNamespace := ns + "-" + owner + "-" + repo + "-pr-" + strconv.Itoa(prNumber)
defaultService := "jx-service"

t.Logf("preview in namespace %s", previewNamespace)

Expand All @@ -62,7 +63,7 @@ func AssertPreview(t *testing.T, customService string) {

serviceName := customService
if serviceName == "" {
serviceName = repo
serviceName = defaultService
}

ingressHost := serviceName + ".1.2.3.4.nip.io"
Expand Down

0 comments on commit 49d1a53

Please sign in to comment.