Skip to content

Commit

Permalink
CR-14253-ingressless-flag (#566)
Browse files Browse the repository at this point in the history
  • Loading branch information
ATGardner authored Sep 11, 2022
1 parent c8bdfbf commit cbfa58a
Show file tree
Hide file tree
Showing 15 changed files with 552 additions and 576 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION=v0.0.510
VERSION=v0.0.511

OUT_DIR=dist
YEAR?=$(shell date +"%Y")
Expand Down
6 changes: 4 additions & 2 deletions cmd/commands/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ func ensureGitRuntimeToken(cmd *cobra.Command, gitProvider cfgit.Provider, clone
func ensureGitUserToken(ctx context.Context, opts *RuntimeInstallOptions) error {
if opts.GitIntegrationRegistrationOpts.Token == "" {
opts.GitIntegrationRegistrationOpts.Token = opts.InsCloneOpts.Auth.Password
currentUser, err := cfConfig.NewClient().Users().GetCurrent(ctx)
currentUser, err := cfConfig.GetCurrentContext().GetUser(ctx)
if err != nil {
return fmt.Errorf("failed to get current user from platform: %w", err)
}
Expand Down Expand Up @@ -349,7 +349,9 @@ func promptSummaryToUser(ctx context.Context, finalParameters map[string]string,
labelStr := fmt.Sprintf("%vDo you wish to continue with %v?%v", CYAN, description, COLOR_RESET)

for key, value := range finalParameters {
promptStr += fmt.Sprintf("\n%v%v: %v%v", GREEN, key, COLOR_RESET, value)
if value != "" {
promptStr += fmt.Sprintf("\n%v%v: %v%v", GREEN, key, COLOR_RESET, value)
}
}
log.G(ctx).Printf(promptStr)
prompt := promptui.Select{
Expand Down
90 changes: 46 additions & 44 deletions cmd/commands/git-source.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ import (
sensorsv1alpha1 "github.com/argoproj/argo-events/pkg/apis/sensor/v1alpha1"
wf "github.com/argoproj/argo-workflows/v3/pkg/apis/workflow"
wfv1alpha1 "github.com/argoproj/argo-workflows/v3/pkg/apis/workflow/v1alpha1"
appProxyModel "github.com/codefresh-io/go-sdk/pkg/codefresh/model/app-proxy"
platmodel "github.com/codefresh-io/go-sdk/pkg/codefresh/model"
apmodel "github.com/codefresh-io/go-sdk/pkg/codefresh/model/app-proxy"
billyUtils "github.com/go-git/go-billy/v5/util"
"github.com/juju/ansiterm"
"github.com/spf13/cobra"
Expand All @@ -67,9 +68,9 @@ type (
IngressHost string
IngressClass string
IngressController routingutil.RoutingController
AccessMode platmodel.AccessMode
GatewayName string
GatewayNamespace string
Flow string
GitProvider cfgit.Provider
useGatewayAPI bool
}
Expand Down Expand Up @@ -105,6 +106,7 @@ type (
ingressHost string
ingressClass string
ingressController routingutil.RoutingController
accessMode platmodel.AccessMode
gatewayName string
gatewayNamespace string
useGatewayAPI bool
Expand Down Expand Up @@ -147,7 +149,6 @@ func NewGitSourceCreateCommand() *cobra.Command {
createRepo bool
include string
exclude string
flow string
)

cmd := &cobra.Command{
Expand Down Expand Up @@ -217,7 +218,6 @@ func NewGitSourceCreateCommand() *cobra.Command {
CreateDemoResources: false,
Include: include,
Exclude: exclude,
Flow: flow,
})
},
}
Expand All @@ -232,8 +232,6 @@ func NewGitSourceCreateCommand() *cobra.Command {
Optional: true,
})

flow = store.Get().GsCreateFlow

return cmd
}

Expand All @@ -243,10 +241,6 @@ func RunGitSourceCreate(ctx context.Context, opts *GitSourceCreateOptions) error
return err
}

if opts.Flow == store.Get().InstallationFlow {
return legacyGitSourceCreate(ctx, opts)
}

if version.LessThan(appProxyGitSourceSupport) {
log.G(ctx).Warnf("runtime \"%s\" is using a deprecated git-source api. Versions %s and up use the app-proxy for this command. You are using version: %s", opts.RuntimeName, appProxyGitSourceSupport, version.String())
return legacyGitSourceCreate(ctx, opts)
Expand All @@ -260,7 +254,7 @@ func RunGitSourceCreate(ctx context.Context, opts *GitSourceCreateOptions) error
appSpecifier := opts.GsCloneOpts.Repo
isInternal := util.StringIndexOf(store.Get().CFInternalGitSources, opts.GsName) > -1

err = appProxy.AppProxyGitSources().Create(ctx, &appProxyModel.CreateGitSourceInput{
err = appProxy.AppProxyGitSources().Create(ctx, &apmodel.CreateGitSourceInput{
AppName: opts.GsName,
AppSpecifier: appSpecifier,
DestServer: store.Get().InCluster,
Expand All @@ -280,23 +274,25 @@ func RunGitSourceCreate(ctx context.Context, opts *GitSourceCreateOptions) error
return nil
}

func createPlaceholderIfNeeded(ctx context.Context, opts *GitSourceCreateOptions, gsRepo git.Repository, gsFs fs.FS) error {
func ensureGitSourceDirectory(ctx context.Context, opts *GitSourceCreateOptions, gsRepo git.Repository, gsFs fs.FS) error {
fi, err := gsFs.ReadDir(".")
if err != nil {
return fmt.Errorf("failed to read files in git-source repo. Err: %w", err)
}

if len(fi) == 0 {
if err = billyUtils.WriteFile(gsFs, "DUMMY", []byte{}, 0666); err != nil {
return fmt.Errorf("failed to write the git-source placeholder file. Err: %w", err)
}
if len(fi) > 0 {
return nil
}

if err = billyUtils.WriteFile(gsFs, "DUMMY", []byte{}, 0666); err != nil {
return fmt.Errorf("failed to write the git-source placeholder file. Err: %w", err)
}

commitMsg := fmt.Sprintf("Created a placeholder file in %s Directory", opts.GsCloneOpts.Path())
commitMsg := fmt.Sprintf("Created a placeholder file in %s Directory", opts.GsCloneOpts.Path())

log.G(ctx).Info("Pushing placeholder file to the default-git-source repo")
if err := apu.PushWithMessage(ctx, gsRepo, commitMsg); err != nil {
return fmt.Errorf("failed to push placeholder file to git-source repo: %w", err)
}
log.G(ctx).Info("Pushing placeholder file to the default-git-source repo")
if err := apu.PushWithMessage(ctx, gsRepo, commitMsg); err != nil {
return fmt.Errorf("failed to push placeholder file to git-source repo: %w", err)
}

return nil
Expand Down Expand Up @@ -569,7 +565,7 @@ func RunGitSourceEdit(ctx context.Context, opts *GitSourceEditOptions) error {
return err
}

err = appProxy.AppProxyGitSources().Edit(ctx, &appProxyModel.EditGitSourceInput{
err = appProxy.AppProxyGitSources().Edit(ctx, &apmodel.EditGitSourceInput{
AppName: opts.GsName,
AppSpecifier: opts.GsCloneOpts.Repo,
Include: opts.Include,
Expand All @@ -591,6 +587,7 @@ func createDemoResources(ctx context.Context, opts *GitSourceCreateOptions, gsRe
if err != nil {
return fmt.Errorf("failed to read files in git-source repo. Err: %w", err)
}

if len(fi) == 0 {
wfTemplateFilePath := store.Get().DemoWorkflowTemplateFileName
wfTemplate := createDemoWorkflowTemplate()
Expand All @@ -607,21 +604,24 @@ func createDemoResources(ctx context.Context, opts *GitSourceCreateOptions, gsRe
return fmt.Errorf("failed to create calendar example pipeline. Error: %w", err)
}

err = createDemoGitPipeline(&gitSourceGitDemoPipelineOptions{
runtimeName: opts.RuntimeName,
gsCloneOpts: opts.GsCloneOpts,
gitProvider: opts.GitProvider,
gsFs: gsFs,
hostName: opts.HostName,
ingressHost: opts.IngressHost,
ingressClass: opts.IngressClass,
ingressController: opts.IngressController,
gatewayName: opts.GatewayName,
gatewayNamespace: opts.GatewayNamespace,
useGatewayAPI: opts.useGatewayAPI,
})
if err != nil {
return fmt.Errorf("failed to create github example pipeline. Error: %w", err)
if opts.AccessMode == platmodel.AccessModeIngress {
err = createDemoGitPipeline(&gitSourceGitDemoPipelineOptions{
runtimeName: opts.RuntimeName,
gsCloneOpts: opts.GsCloneOpts,
gitProvider: opts.GitProvider,
gsFs: gsFs,
hostName: opts.HostName,
ingressHost: opts.IngressHost,
ingressClass: opts.IngressClass,
ingressController: opts.IngressController,
accessMode: opts.AccessMode,
gatewayName: opts.GatewayName,
gatewayNamespace: opts.GatewayNamespace,
useGatewayAPI: opts.useGatewayAPI,
})
if err != nil {
return fmt.Errorf("failed to create github example pipeline. Error: %w", err)
}
}

commitMsg := fmt.Sprintf("Created demo pipelines in %s Directory", opts.GsCloneOpts.Path())
Expand Down Expand Up @@ -752,7 +752,7 @@ func createDemoCalendarTrigger() sensorsv1alpha1.Trigger {
}

func createDemoGitPipeline(opts *gitSourceGitDemoPipelineOptions) error {
if !store.Get().SkipIngress {
if opts.accessMode == platmodel.AccessModeIngress {
// Create an ingress that will manage external access to the git eventsource service
routeOpts := routingutil.CreateRouteOpts{
RuntimeName: opts.runtimeName,
Expand Down Expand Up @@ -1532,20 +1532,22 @@ func legacyGitSourceCreate(ctx context.Context, opts *GitSourceCreateOptions) er
return fmt.Errorf("failed to create git-source demo resources: %w", err)
}
} else {
if err := createPlaceholderIfNeeded(ctx, opts, gsRepo, gsFs); err != nil {
return fmt.Errorf("failed to create a git-source placeholder: %w", err)
if err := ensureGitSourceDirectory(ctx, opts, gsRepo, gsFs); err != nil {
return fmt.Errorf("failed to ensure git-source directory: %w", err)
}
}

appDef := &runtime.AppDef{
Name: opts.GsName,
Type: application.AppTypeDirectory,
URL: opts.GsCloneOpts.Repo,
Name: opts.GsName,
Type: application.AppTypeDirectory,
URL: opts.GsCloneOpts.Repo,
Include: opts.Include,
Exclude: opts.Exclude,
}

appDef.IsInternal = util.StringIndexOf(store.Get().CFInternalGitSources, appDef.Name) > -1

if err := appDef.CreateApp(ctx, nil, opts.InsCloneOpts, opts.RuntimeName, store.Get().CFGitSourceType, opts.Include, opts.Exclude); err != nil {
if err := appDef.CreateApp(ctx, nil, opts.InsCloneOpts, opts.RuntimeName, store.Get().CFGitSourceType); err != nil {
return fmt.Errorf("failed to create git-source application. Err: %w", err)
}

Expand Down
39 changes: 20 additions & 19 deletions cmd/commands/integrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
// 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 commands

import (
Expand All @@ -25,7 +26,7 @@ import (
"github.com/codefresh-io/cli-v2/pkg/util"

sdk "github.com/codefresh-io/go-sdk/pkg/codefresh"
model "github.com/codefresh-io/go-sdk/pkg/codefresh/model/app-proxy"
apmodel "github.com/codefresh-io/go-sdk/pkg/codefresh/model/app-proxy"
"github.com/ghodss/yaml"
"github.com/juju/ansiterm"
"github.com/spf13/cobra"
Expand All @@ -35,8 +36,8 @@ import (
type (
GitIntegrationAddOptions struct {
Name string
Provider model.GitProviders
SharingPolicy model.SharingPolicy
Provider apmodel.GitProviders
SharingPolicy apmodel.SharingPolicy
}

GitIntegrationRegistrationOpts struct {
Expand All @@ -46,11 +47,11 @@ type (
}
)

var gitProvidersByName = map[string]model.GitProviders{
"bitbucket": model.GitProvidersBitbucket,
"bitbucket-server": model.GitProvidersBitbucketServer,
"github": model.GitProvidersGithub,
"gitlab": model.GitProvidersGitlab,
var gitProvidersByName = map[string]apmodel.GitProviders{
"bitbucket": apmodel.GitProvidersBitbucket,
"bitbucket-server": apmodel.GitProvidersBitbucketServer,
"github": apmodel.GitProvidersGithub,
"gitlab": apmodel.GitProvidersGitlab,
}

var gitProvidersByValue = util.ReverseMap(gitProvidersByName)
Expand Down Expand Up @@ -199,7 +200,7 @@ func RunGitIntegrationGetCommand(ctx context.Context, client sdk.AppProxyAPI, na

func NewGitIntegrationAddCommand(client *sdk.AppProxyAPI) *cobra.Command {
var (
opts model.AddGitIntegrationArgs
opts apmodel.AddGitIntegrationArgs
provider string
apiURL string
accountAdminsOnly bool
Expand All @@ -222,9 +223,9 @@ func NewGitIntegrationAddCommand(client *sdk.AppProxyAPI) *cobra.Command {
return err
}

opts.SharingPolicy = model.SharingPolicyAllUsersInAccount
opts.SharingPolicy = apmodel.SharingPolicyAllUsersInAccount
if accountAdminsOnly {
opts.SharingPolicy = model.SharingPolicyAccountAdmins
opts.SharingPolicy = apmodel.SharingPolicyAccountAdmins
}

return RunGitIntegrationAddCommand(cmd.Context(), *client, &opts)
Expand All @@ -241,7 +242,7 @@ func NewGitIntegrationAddCommand(client *sdk.AppProxyAPI) *cobra.Command {
return cmd
}

func RunGitIntegrationAddCommand(ctx context.Context, client sdk.AppProxyAPI, opts *model.AddGitIntegrationArgs) error {
func RunGitIntegrationAddCommand(ctx context.Context, client sdk.AppProxyAPI, opts *apmodel.AddGitIntegrationArgs) error {
intg, err := client.GitIntegrations().Add(ctx, opts)
if err != nil {
return fmt.Errorf("failed to add git integration: %w", err)
Expand All @@ -254,7 +255,7 @@ func RunGitIntegrationAddCommand(ctx context.Context, client sdk.AppProxyAPI, op

func NewGitIntegrationEditCommand(client *sdk.AppProxyAPI) *cobra.Command {
var (
opts model.EditGitIntegrationArgs
opts apmodel.EditGitIntegrationArgs
apiURL string
accountAdminsOnly bool
)
Expand All @@ -270,9 +271,9 @@ func NewGitIntegrationEditCommand(client *sdk.AppProxyAPI) *cobra.Command {

opts.APIURL = &apiURL

opts.SharingPolicy = model.SharingPolicyAllUsersInAccount
opts.SharingPolicy = apmodel.SharingPolicyAllUsersInAccount
if accountAdminsOnly {
opts.SharingPolicy = model.SharingPolicyAccountAdmins
opts.SharingPolicy = apmodel.SharingPolicyAccountAdmins
}

return RunGitIntegrationEditCommand(cmd.Context(), *client, &opts)
Expand All @@ -286,7 +287,7 @@ func NewGitIntegrationEditCommand(client *sdk.AppProxyAPI) *cobra.Command {
return cmd
}

func RunGitIntegrationEditCommand(ctx context.Context, client sdk.AppProxyAPI, opts *model.EditGitIntegrationArgs) error {
func RunGitIntegrationEditCommand(ctx context.Context, client sdk.AppProxyAPI, opts *apmodel.EditGitIntegrationArgs) error {
intg, err := client.GitIntegrations().Edit(ctx, opts)
if err != nil {
return fmt.Errorf("failed to edit git integration: %w", err)
Expand Down Expand Up @@ -352,7 +353,7 @@ func NewGitIntegrationRegisterCommand(client *sdk.AppProxyAPI) *cobra.Command {
}

func RunGitIntegrationRegisterCommand(ctx context.Context, client sdk.AppProxyAPI, opts *GitIntegrationRegistrationOpts) error {
regOpts := &model.RegisterToGitIntegrationArgs{
regOpts := &apmodel.RegisterToGitIntegrationArgs{
Token: opts.Token,
}
if opts.Username != "" {
Expand Down Expand Up @@ -495,10 +496,10 @@ func verifyOutputFormat(format string, allowedFormats ...string) error {
return fmt.Errorf("invalid output format: %s", format)
}

func parseGitProvider(provider string) (model.GitProviders, error) {
func parseGitProvider(provider string) (apmodel.GitProviders, error) {
p, ok := gitProvidersByName[provider]
if !ok {
return model.GitProviders(""), fmt.Errorf("provider \"%s\" is not a valid provider name", provider)
return apmodel.GitProviders(""), fmt.Errorf("provider \"%s\" is not a valid provider name", provider)
}
return p, nil
}
6 changes: 3 additions & 3 deletions cmd/commands/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -682,12 +682,12 @@ func getApplicationChecklistState(name string, a *argocdv1alpha1.Application, ru
}

func removeRuntimeIsc(ctx context.Context, runtimeName string) error {
me, err := cfConfig.NewClient().V2().UsersV2().GetCurrent(ctx)
iscRepo, err := getIscRepo(ctx)
if err != nil {
return fmt.Errorf("failed to get current user information: %w", err)
}

if me.ActiveAccount.SharedConfigRepo == nil || *me.ActiveAccount.SharedConfigRepo == "" {
if iscRepo == "" {
log.G(ctx).Info("Skipped removing runtime from ISC repo. ISC repo not defined")
return nil
}
Expand Down Expand Up @@ -870,7 +870,7 @@ func runRuntimeUpgrade(ctx context.Context, opts *RuntimeUpgradeOptions) error {
for _, component := range newComponents {
log.G(ctx).Infof("Installing new component \"%s\"", component.Name)
component.IsInternal = true
err = component.CreateApp(ctx, nil, opts.CloneOpts, opts.RuntimeName, store.Get().CFComponentType, "", "")
err = component.CreateApp(ctx, nil, opts.CloneOpts, opts.RuntimeName, store.Get().CFComponentType)
if err != nil {
err = fmt.Errorf("failed to create \"%s\" application: %w", component.Name, err)
break
Expand Down
Loading

0 comments on commit cbfa58a

Please sign in to comment.