-
Notifications
You must be signed in to change notification settings - Fork 93
Non-kube network observer installation #2532
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
nluaces
wants to merge
17
commits into
skupperproject:main
Choose a base branch
from
nluaces:add-network-observer-to-non-kube-env
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,067
−55
Open
Changes from 2 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
f452dc8
non kube network observer installation
nluaces 8da7426
fix redundancy
nluaces c82d0fd
upgrade crypto dependency
nluaces df4bf49
add local router address to initiate the network-observer container i…
nluaces 7ec371b
add fallback getting the user home dir
nluaces 8769979
fix harcoded router endpoint and add podman userns flag if the select…
nluaces 559bfb3
generate password before installing the nginx container
nluaces 0934b33
add timeout for pulling images
nluaces 83720a7
remove nginx deployment for network-observer in non-kube environments
nluaces 8bd5f0d
remove network observer if when running system uninstall --force
nluaces 57d524e
attaching containers to systemd services instead of recreating them
nluaces 620df14
configure localhost only
nluaces 7ba9509
fix example
nluaces 7149bae
add log message when skipping network observer uninstall
nluaces 9571861
improve systemd services enablement and creation
nluaces 11473be
fix formatting
nluaces deddbcc
uninstall netobs only if it was installed
nluaces File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
internal/cmd/skupper/system/kube/system_network-observer.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| package kube | ||
|
|
||
| import ( | ||
| "fmt" | ||
|
|
||
| "github.com/skupperproject/skupper/internal/cmd/skupper/common" | ||
| "github.com/spf13/cobra" | ||
| ) | ||
|
|
||
| type CmdSystemNetworkObserver struct { | ||
| CobraCmd *cobra.Command | ||
| Flags *common.CommandNetworkObserverFlags | ||
| namespace string | ||
| user string | ||
| password string | ||
| } | ||
|
|
||
| func NewCmdCmdSystemNetworkObserver() *CmdSystemNetworkObserver { | ||
| return &CmdSystemNetworkObserver{} | ||
| } | ||
|
|
||
| func (cmd *CmdSystemNetworkObserver) NewClient(cobraCommand *cobra.Command, args []string) {} | ||
|
|
||
| func (cmd *CmdSystemNetworkObserver) ValidateInput(args []string) error { | ||
| return nil | ||
| } | ||
|
|
||
| func (cmd *CmdSystemNetworkObserver) InputToOptions() { | ||
|
|
||
| } | ||
|
|
||
| func (cmd *CmdSystemNetworkObserver) Run() error { | ||
| fmt.Println("This command does not support kubernetes platforms.") | ||
| return nil | ||
| } | ||
|
|
||
| func (cmd *CmdSystemNetworkObserver) WaitUntil() error { | ||
| return nil | ||
| } |
100 changes: 100 additions & 0 deletions
100
internal/cmd/skupper/system/nonkube/system_network-observer.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| package nonkube | ||
|
|
||
| import ( | ||
| "errors" | ||
| "fmt" | ||
|
|
||
| "github.com/skupperproject/skupper/internal/cmd/skupper/common" | ||
| networkobserver "github.com/skupperproject/skupper/internal/nonkube/network-observer" | ||
| "github.com/spf13/cobra" | ||
| ) | ||
|
|
||
| type CmdSystemNetworkObserver struct { | ||
| CobraCmd *cobra.Command | ||
| Flags *common.CommandNetworkObserverFlags | ||
| namespace string | ||
| user string | ||
| password string | ||
| } | ||
|
|
||
| func NewCmdSystemNetworkObserver() *CmdSystemNetworkObserver { | ||
| return &CmdSystemNetworkObserver{} | ||
| } | ||
|
|
||
| func (cmd *CmdSystemNetworkObserver) NewClient(cobraCommand *cobra.Command, args []string) { | ||
| if cmd.CobraCmd != nil && cmd.CobraCmd.Flag(common.FlagNameNamespace) != nil { | ||
| cmd.namespace = cmd.CobraCmd.Flag(common.FlagNameNamespace).Value.String() | ||
| } | ||
| if cmd.namespace == "" { | ||
| cmd.namespace = "default" | ||
| } | ||
| } | ||
|
|
||
| func (cmd *CmdSystemNetworkObserver) ValidateInput(args []string) error { | ||
| var validationErrors []error | ||
|
|
||
| if len(args) > 0 { | ||
| validationErrors = append(validationErrors, fmt.Errorf("this command does not accept arguments")) | ||
| } | ||
|
|
||
| if cmd.Flags != nil && cmd.Flags.Uninstall { | ||
| if cmd.Flags.Password != "" { | ||
| validationErrors = append(validationErrors, fmt.Errorf("--%s cannot be used with --%s", common.FlagNameNetworkObserverPassword, common.FlagNameNetworkObserverUninstall)) | ||
| } | ||
| } | ||
|
|
||
| return errors.Join(validationErrors...) | ||
| } | ||
|
|
||
| func (cmd *CmdSystemNetworkObserver) InputToOptions() { | ||
|
|
||
| if cmd.Flags.Username != "" { | ||
| cmd.user = cmd.Flags.Username | ||
| } | ||
|
|
||
| if cmd.Flags.Password != "" { | ||
| cmd.password = cmd.Flags.Password | ||
| } | ||
|
|
||
| } | ||
|
|
||
| func (cmd *CmdSystemNetworkObserver) Run() error { | ||
| installer, err := networkobserver.NewInstaller(cmd.namespace, cmd.user, cmd.password) | ||
| if err != nil { | ||
| return fmt.Errorf("failed to create installer: %w", err) | ||
| } | ||
|
|
||
| if cmd.Flags.Uninstall { | ||
|
|
||
| if err := installer.ValidatePrerequisitesForUninstall(); err != nil { | ||
| return err | ||
| } | ||
|
|
||
| if err := installer.Uninstall(); err != nil { | ||
| return fmt.Errorf("uninstallation failed: %w", err) | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
| if err := installer.ValidatePrerequisitesForInstall(); err != nil { | ||
| return fmt.Errorf("prerequisite validation failed: %w", err) | ||
| } | ||
|
|
||
| result, err := installer.Install() | ||
| if err != nil { | ||
| return fmt.Errorf("installation failed: %w", err) | ||
| } | ||
|
|
||
| fmt.Println("Network observer installed successfully!") | ||
| fmt.Printf("\nAccess URL: %s\n", result.URL) | ||
| fmt.Printf("Username: %s\n", result.Username) | ||
| fmt.Printf("Password: %s\n", result.Password) | ||
| fmt.Println("\nNote: Save these credentials securely.") | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
| func (cmd *CmdSystemNetworkObserver) WaitUntil() error { | ||
| return nil | ||
| } |
156 changes: 156 additions & 0 deletions
156
internal/cmd/skupper/system/nonkube/system_network-observer_test.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,156 @@ | ||
| package nonkube | ||
|
|
||
| import ( | ||
| "strings" | ||
| "testing" | ||
|
|
||
| "github.com/skupperproject/skupper/internal/cmd/skupper/common" | ||
| "github.com/spf13/cobra" | ||
| ) | ||
|
|
||
| func TestCmdSystemNetworkObserverValidateInput(t *testing.T) { | ||
| tests := []struct { | ||
| name string | ||
| args []string | ||
| flags *common.CommandNetworkObserverFlags | ||
| expectedError []string | ||
| }{ | ||
| { | ||
| name: "rejects arguments", | ||
| args: []string{"extra"}, | ||
| expectedError: []string{"this command does not accept arguments"}, | ||
| }, | ||
| { | ||
| name: "rejects credentials with uninstall", | ||
| flags: &common.CommandNetworkObserverFlags{ | ||
| Uninstall: true, | ||
| Password: "password", | ||
| }, | ||
| expectedError: []string{ | ||
| "--password cannot be used with --uninstall", | ||
| }, | ||
| }, | ||
| { | ||
| name: "allows install credentials", | ||
| flags: &common.CommandNetworkObserverFlags{ | ||
| Username: "user", | ||
| Password: "password", | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| for _, test := range tests { | ||
| t.Run(test.name, func(t *testing.T) { | ||
| cmd := &CmdSystemNetworkObserver{Flags: test.flags} | ||
|
|
||
| err := cmd.ValidateInput(test.args) | ||
| if len(test.expectedError) == 0 { | ||
| if err != nil { | ||
| t.Fatalf("expected no error, got %q", err.Error()) | ||
| } | ||
| return | ||
| } | ||
|
|
||
| if err == nil { | ||
| t.Fatal("expected error") | ||
| } | ||
| for _, expected := range test.expectedError { | ||
| if !strings.Contains(err.Error(), expected) { | ||
| t.Fatalf("expected validation error %q, got %q", expected, err.Error()) | ||
| } | ||
| } | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| func TestCmdSystemNetworkObserverNewClient(t *testing.T) { | ||
| tests := []struct { | ||
| name string | ||
| flagNamespace string | ||
| initialNamespace string | ||
| expectedNamespace string | ||
| }{ | ||
| { | ||
| name: "uses namespace flag", | ||
| flagNamespace: "west", | ||
| expectedNamespace: "west", | ||
| }, | ||
| { | ||
| name: "defaults namespace", | ||
| expectedNamespace: "default", | ||
| }, | ||
| { | ||
| name: "defaults even when namespace was preset without flag", | ||
| initialNamespace: "east", | ||
| expectedNamespace: "default", | ||
| }, | ||
| } | ||
|
|
||
| for _, test := range tests { | ||
| t.Run(test.name, func(t *testing.T) { | ||
| cobraCmd := &cobra.Command{} | ||
| cobraCmd.Flags().String(common.FlagNameNamespace, "", "") | ||
| if test.flagNamespace != "" { | ||
| if err := cobraCmd.Flags().Set(common.FlagNameNamespace, test.flagNamespace); err != nil { | ||
| t.Fatalf("failed to set namespace flag: %v", err) | ||
| } | ||
| } | ||
|
|
||
| cmd := &CmdSystemNetworkObserver{ | ||
| CobraCmd: cobraCmd, | ||
| namespace: test.initialNamespace, | ||
| } | ||
|
|
||
| cmd.NewClient(cobraCmd, nil) | ||
|
|
||
| if cmd.namespace != test.expectedNamespace { | ||
| t.Fatalf("expected namespace %q, got %q", test.expectedNamespace, cmd.namespace) | ||
| } | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| func TestCmdSystemNetworkObserverInputToOptions(t *testing.T) { | ||
| tests := []struct { | ||
| name string | ||
| flags *common.CommandNetworkObserverFlags | ||
| initialUser string | ||
| initialPassword string | ||
| expectedUser string | ||
| expectedPassword string | ||
| }{ | ||
| { | ||
| name: "copies credentials from flags", | ||
| flags: &common.CommandNetworkObserverFlags{Username: "user", Password: "password"}, | ||
| expectedUser: "user", | ||
| expectedPassword: "password", | ||
| }, | ||
| { | ||
| name: "leaves existing values when flags are empty", | ||
| flags: &common.CommandNetworkObserverFlags{}, | ||
| initialUser: "existing-user", | ||
| initialPassword: "existing-password", | ||
| expectedUser: "existing-user", | ||
| expectedPassword: "existing-password", | ||
| }, | ||
| } | ||
|
|
||
| for _, test := range tests { | ||
| t.Run(test.name, func(t *testing.T) { | ||
| cmd := &CmdSystemNetworkObserver{ | ||
| Flags: test.flags, | ||
| user: test.initialUser, | ||
| password: test.initialPassword, | ||
| } | ||
|
|
||
| cmd.InputToOptions() | ||
|
|
||
| if cmd.user != test.expectedUser { | ||
| t.Fatalf("expected user %q, got %q", test.expectedUser, cmd.user) | ||
| } | ||
| if cmd.password != test.expectedPassword { | ||
| t.Fatalf("expected password %q, got %q", test.expectedPassword, cmd.password) | ||
| } | ||
| }) | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.