Skip to content

Commit cbfa58a

Browse files
authored
CR-14253-ingressless-flag (#566)
1 parent c8bdfbf commit cbfa58a

File tree

15 files changed

+552
-576
lines changed

15 files changed

+552
-576
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
VERSION=v0.0.510
1+
VERSION=v0.0.511
22

33
OUT_DIR=dist
44
YEAR?=$(shell date +"%Y")

cmd/commands/common.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ func ensureGitRuntimeToken(cmd *cobra.Command, gitProvider cfgit.Provider, clone
290290
func ensureGitUserToken(ctx context.Context, opts *RuntimeInstallOptions) error {
291291
if opts.GitIntegrationRegistrationOpts.Token == "" {
292292
opts.GitIntegrationRegistrationOpts.Token = opts.InsCloneOpts.Auth.Password
293-
currentUser, err := cfConfig.NewClient().Users().GetCurrent(ctx)
293+
currentUser, err := cfConfig.GetCurrentContext().GetUser(ctx)
294294
if err != nil {
295295
return fmt.Errorf("failed to get current user from platform: %w", err)
296296
}
@@ -349,7 +349,9 @@ func promptSummaryToUser(ctx context.Context, finalParameters map[string]string,
349349
labelStr := fmt.Sprintf("%vDo you wish to continue with %v?%v", CYAN, description, COLOR_RESET)
350350

351351
for key, value := range finalParameters {
352-
promptStr += fmt.Sprintf("\n%v%v: %v%v", GREEN, key, COLOR_RESET, value)
352+
if value != "" {
353+
promptStr += fmt.Sprintf("\n%v%v: %v%v", GREEN, key, COLOR_RESET, value)
354+
}
353355
}
354356
log.G(ctx).Printf(promptStr)
355357
prompt := promptui.Select{

cmd/commands/git-source.go

Lines changed: 46 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ import (
4545
sensorsv1alpha1 "github.com/argoproj/argo-events/pkg/apis/sensor/v1alpha1"
4646
wf "github.com/argoproj/argo-workflows/v3/pkg/apis/workflow"
4747
wfv1alpha1 "github.com/argoproj/argo-workflows/v3/pkg/apis/workflow/v1alpha1"
48-
appProxyModel "github.com/codefresh-io/go-sdk/pkg/codefresh/model/app-proxy"
48+
platmodel "github.com/codefresh-io/go-sdk/pkg/codefresh/model"
49+
apmodel "github.com/codefresh-io/go-sdk/pkg/codefresh/model/app-proxy"
4950
billyUtils "github.com/go-git/go-billy/v5/util"
5051
"github.com/juju/ansiterm"
5152
"github.com/spf13/cobra"
@@ -67,9 +68,9 @@ type (
6768
IngressHost string
6869
IngressClass string
6970
IngressController routingutil.RoutingController
71+
AccessMode platmodel.AccessMode
7072
GatewayName string
7173
GatewayNamespace string
72-
Flow string
7374
GitProvider cfgit.Provider
7475
useGatewayAPI bool
7576
}
@@ -105,6 +106,7 @@ type (
105106
ingressHost string
106107
ingressClass string
107108
ingressController routingutil.RoutingController
109+
accessMode platmodel.AccessMode
108110
gatewayName string
109111
gatewayNamespace string
110112
useGatewayAPI bool
@@ -147,7 +149,6 @@ func NewGitSourceCreateCommand() *cobra.Command {
147149
createRepo bool
148150
include string
149151
exclude string
150-
flow string
151152
)
152153

153154
cmd := &cobra.Command{
@@ -217,7 +218,6 @@ func NewGitSourceCreateCommand() *cobra.Command {
217218
CreateDemoResources: false,
218219
Include: include,
219220
Exclude: exclude,
220-
Flow: flow,
221221
})
222222
},
223223
}
@@ -232,8 +232,6 @@ func NewGitSourceCreateCommand() *cobra.Command {
232232
Optional: true,
233233
})
234234

235-
flow = store.Get().GsCreateFlow
236-
237235
return cmd
238236
}
239237

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

246-
if opts.Flow == store.Get().InstallationFlow {
247-
return legacyGitSourceCreate(ctx, opts)
248-
}
249-
250244
if version.LessThan(appProxyGitSourceSupport) {
251245
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())
252246
return legacyGitSourceCreate(ctx, opts)
@@ -260,7 +254,7 @@ func RunGitSourceCreate(ctx context.Context, opts *GitSourceCreateOptions) error
260254
appSpecifier := opts.GsCloneOpts.Repo
261255
isInternal := util.StringIndexOf(store.Get().CFInternalGitSources, opts.GsName) > -1
262256

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

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

289-
if len(fi) == 0 {
290-
if err = billyUtils.WriteFile(gsFs, "DUMMY", []byte{}, 0666); err != nil {
291-
return fmt.Errorf("failed to write the git-source placeholder file. Err: %w", err)
292-
}
283+
if len(fi) > 0 {
284+
return nil
285+
}
286+
287+
if err = billyUtils.WriteFile(gsFs, "DUMMY", []byte{}, 0666); err != nil {
288+
return fmt.Errorf("failed to write the git-source placeholder file. Err: %w", err)
289+
}
293290

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

296-
log.G(ctx).Info("Pushing placeholder file to the default-git-source repo")
297-
if err := apu.PushWithMessage(ctx, gsRepo, commitMsg); err != nil {
298-
return fmt.Errorf("failed to push placeholder file to git-source repo: %w", err)
299-
}
293+
log.G(ctx).Info("Pushing placeholder file to the default-git-source repo")
294+
if err := apu.PushWithMessage(ctx, gsRepo, commitMsg); err != nil {
295+
return fmt.Errorf("failed to push placeholder file to git-source repo: %w", err)
300296
}
301297

302298
return nil
@@ -569,7 +565,7 @@ func RunGitSourceEdit(ctx context.Context, opts *GitSourceEditOptions) error {
569565
return err
570566
}
571567

572-
err = appProxy.AppProxyGitSources().Edit(ctx, &appProxyModel.EditGitSourceInput{
568+
err = appProxy.AppProxyGitSources().Edit(ctx, &apmodel.EditGitSourceInput{
573569
AppName: opts.GsName,
574570
AppSpecifier: opts.GsCloneOpts.Repo,
575571
Include: opts.Include,
@@ -591,6 +587,7 @@ func createDemoResources(ctx context.Context, opts *GitSourceCreateOptions, gsRe
591587
if err != nil {
592588
return fmt.Errorf("failed to read files in git-source repo. Err: %w", err)
593589
}
590+
594591
if len(fi) == 0 {
595592
wfTemplateFilePath := store.Get().DemoWorkflowTemplateFileName
596593
wfTemplate := createDemoWorkflowTemplate()
@@ -607,21 +604,24 @@ func createDemoResources(ctx context.Context, opts *GitSourceCreateOptions, gsRe
607604
return fmt.Errorf("failed to create calendar example pipeline. Error: %w", err)
608605
}
609606

610-
err = createDemoGitPipeline(&gitSourceGitDemoPipelineOptions{
611-
runtimeName: opts.RuntimeName,
612-
gsCloneOpts: opts.GsCloneOpts,
613-
gitProvider: opts.GitProvider,
614-
gsFs: gsFs,
615-
hostName: opts.HostName,
616-
ingressHost: opts.IngressHost,
617-
ingressClass: opts.IngressClass,
618-
ingressController: opts.IngressController,
619-
gatewayName: opts.GatewayName,
620-
gatewayNamespace: opts.GatewayNamespace,
621-
useGatewayAPI: opts.useGatewayAPI,
622-
})
623-
if err != nil {
624-
return fmt.Errorf("failed to create github example pipeline. Error: %w", err)
607+
if opts.AccessMode == platmodel.AccessModeIngress {
608+
err = createDemoGitPipeline(&gitSourceGitDemoPipelineOptions{
609+
runtimeName: opts.RuntimeName,
610+
gsCloneOpts: opts.GsCloneOpts,
611+
gitProvider: opts.GitProvider,
612+
gsFs: gsFs,
613+
hostName: opts.HostName,
614+
ingressHost: opts.IngressHost,
615+
ingressClass: opts.IngressClass,
616+
ingressController: opts.IngressController,
617+
accessMode: opts.AccessMode,
618+
gatewayName: opts.GatewayName,
619+
gatewayNamespace: opts.GatewayNamespace,
620+
useGatewayAPI: opts.useGatewayAPI,
621+
})
622+
if err != nil {
623+
return fmt.Errorf("failed to create github example pipeline. Error: %w", err)
624+
}
625625
}
626626

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

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

15401540
appDef := &runtime.AppDef{
1541-
Name: opts.GsName,
1542-
Type: application.AppTypeDirectory,
1543-
URL: opts.GsCloneOpts.Repo,
1541+
Name: opts.GsName,
1542+
Type: application.AppTypeDirectory,
1543+
URL: opts.GsCloneOpts.Repo,
1544+
Include: opts.Include,
1545+
Exclude: opts.Exclude,
15441546
}
15451547

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

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

cmd/commands/integrations.go

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
14+
1415
package commands
1516

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

2728
sdk "github.com/codefresh-io/go-sdk/pkg/codefresh"
28-
model "github.com/codefresh-io/go-sdk/pkg/codefresh/model/app-proxy"
29+
apmodel "github.com/codefresh-io/go-sdk/pkg/codefresh/model/app-proxy"
2930
"github.com/ghodss/yaml"
3031
"github.com/juju/ansiterm"
3132
"github.com/spf13/cobra"
@@ -35,8 +36,8 @@ import (
3536
type (
3637
GitIntegrationAddOptions struct {
3738
Name string
38-
Provider model.GitProviders
39-
SharingPolicy model.SharingPolicy
39+
Provider apmodel.GitProviders
40+
SharingPolicy apmodel.SharingPolicy
4041
}
4142

4243
GitIntegrationRegistrationOpts struct {
@@ -46,11 +47,11 @@ type (
4647
}
4748
)
4849

49-
var gitProvidersByName = map[string]model.GitProviders{
50-
"bitbucket": model.GitProvidersBitbucket,
51-
"bitbucket-server": model.GitProvidersBitbucketServer,
52-
"github": model.GitProvidersGithub,
53-
"gitlab": model.GitProvidersGitlab,
50+
var gitProvidersByName = map[string]apmodel.GitProviders{
51+
"bitbucket": apmodel.GitProvidersBitbucket,
52+
"bitbucket-server": apmodel.GitProvidersBitbucketServer,
53+
"github": apmodel.GitProvidersGithub,
54+
"gitlab": apmodel.GitProvidersGitlab,
5455
}
5556

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

200201
func NewGitIntegrationAddCommand(client *sdk.AppProxyAPI) *cobra.Command {
201202
var (
202-
opts model.AddGitIntegrationArgs
203+
opts apmodel.AddGitIntegrationArgs
203204
provider string
204205
apiURL string
205206
accountAdminsOnly bool
@@ -222,9 +223,9 @@ func NewGitIntegrationAddCommand(client *sdk.AppProxyAPI) *cobra.Command {
222223
return err
223224
}
224225

225-
opts.SharingPolicy = model.SharingPolicyAllUsersInAccount
226+
opts.SharingPolicy = apmodel.SharingPolicyAllUsersInAccount
226227
if accountAdminsOnly {
227-
opts.SharingPolicy = model.SharingPolicyAccountAdmins
228+
opts.SharingPolicy = apmodel.SharingPolicyAccountAdmins
228229
}
229230

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

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

255256
func NewGitIntegrationEditCommand(client *sdk.AppProxyAPI) *cobra.Command {
256257
var (
257-
opts model.EditGitIntegrationArgs
258+
opts apmodel.EditGitIntegrationArgs
258259
apiURL string
259260
accountAdminsOnly bool
260261
)
@@ -270,9 +271,9 @@ func NewGitIntegrationEditCommand(client *sdk.AppProxyAPI) *cobra.Command {
270271

271272
opts.APIURL = &apiURL
272273

273-
opts.SharingPolicy = model.SharingPolicyAllUsersInAccount
274+
opts.SharingPolicy = apmodel.SharingPolicyAllUsersInAccount
274275
if accountAdminsOnly {
275-
opts.SharingPolicy = model.SharingPolicyAccountAdmins
276+
opts.SharingPolicy = apmodel.SharingPolicyAccountAdmins
276277
}
277278

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

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

354355
func RunGitIntegrationRegisterCommand(ctx context.Context, client sdk.AppProxyAPI, opts *GitIntegrationRegistrationOpts) error {
355-
regOpts := &model.RegisterToGitIntegrationArgs{
356+
regOpts := &apmodel.RegisterToGitIntegrationArgs{
356357
Token: opts.Token,
357358
}
358359
if opts.Username != "" {
@@ -495,10 +496,10 @@ func verifyOutputFormat(format string, allowedFormats ...string) error {
495496
return fmt.Errorf("invalid output format: %s", format)
496497
}
497498

498-
func parseGitProvider(provider string) (model.GitProviders, error) {
499+
func parseGitProvider(provider string) (apmodel.GitProviders, error) {
499500
p, ok := gitProvidersByName[provider]
500501
if !ok {
501-
return model.GitProviders(""), fmt.Errorf("provider \"%s\" is not a valid provider name", provider)
502+
return apmodel.GitProviders(""), fmt.Errorf("provider \"%s\" is not a valid provider name", provider)
502503
}
503504
return p, nil
504505
}

cmd/commands/runtime.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -682,12 +682,12 @@ func getApplicationChecklistState(name string, a *argocdv1alpha1.Application, ru
682682
}
683683

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

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

0 commit comments

Comments
 (0)