-
Notifications
You must be signed in to change notification settings - Fork 3
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
feat: local apply #142
Closed
Closed
feat: local apply #142
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
cfedbde
fix(clean-up): Call env cleanup method when executing render and sync…
fritzduchardt fad2197
Merge remote-tracking branch 'origin/dev' into dev
fritzduchardt 3725d6e
Merge remote-tracking branch 'origin/dev' into dev
fritzduchardt 68f28b4
Merge remote-tracking branch 'origin/dev' into dev
fritzduchardt f0397c1
feat: local apply with kubectl in adherence with argo or helm namespa…
fritzduchardt 3f11ae1
linting
fritzduchardt 1a277c4
formatting
fritzduchardt b8fc55a
Merge fix
fritzduchardt 34ddc10
Make local apply apply namespaces and crds first
fritzduchardt dd9dc70
Added validation to ensure that a specific environment is selected wh…
fritzduchardt 10ec522
Improve logging for local apply
fritzduchardt 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 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,41 @@ | ||
package cmd | ||
|
||
import ( | ||
"github.com/rs/zerolog/log" | ||
"github.com/spf13/cobra" | ||
|
||
"github.com/mykso/myks/internal/myks" | ||
) | ||
|
||
func init() { | ||
cmd := &cobra.Command{ | ||
Use: "apply", | ||
Short: "Apply k8s manifests to current context", | ||
Long: `TODO`, | ||
Annotations: map[string]string{ | ||
ANNOTATION_SMART_MODE: ANNOTATION_TRUE, | ||
}, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
log.Info().Msg("Applying k8s manifests") | ||
g := myks.New(".") | ||
|
||
if err := g.ValidateRootDir(); err != nil { | ||
log.Fatal().Err(err).Msg("Root directory is not suitable for myks") | ||
} | ||
|
||
if err := g.Init(asyncLevel, envAppMap); err != nil { | ||
log.Fatal().Err(err).Msg("Unable to initialize myks's globe") | ||
} | ||
|
||
if !g.SingleEnv() { | ||
log.Fatal().Msg("Local apply can only be used with a specific environment. Make sure you are connected to the right cluster.") | ||
} | ||
|
||
if err := g.Apply(asyncLevel); err != nil { | ||
log.Fatal().Err(err).Msg("Unable to apply k8s manifests") | ||
} | ||
}, | ||
} | ||
|
||
rootCmd.AddCommand(cmd) | ||
} |
This file contains 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 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 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 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 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,28 @@ | ||
package myks | ||
|
||
import "testing" | ||
|
||
func TestGlobe_SingleEnv(t *testing.T) { | ||
type fields struct { | ||
environments map[string]*Environment | ||
} | ||
tests := []struct { | ||
name string | ||
fields fields | ||
want bool | ||
}{ | ||
{"before init", fields{map[string]*Environment{}}, false}, | ||
{"happy path", fields{map[string]*Environment{"test-env": {}}}, true}, | ||
{"sad path", fields{map[string]*Environment{"test-env": {}, "test-env2": {}}}, false}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
g := &Globe{ | ||
environments: tt.fields.environments, | ||
} | ||
if got := g.SingleEnv(); got != tt.want { | ||
t.Errorf("SingleEnv() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Following the "source of truth" and "explicit better than implicit" ideas, I'd rather force users to explicitly define namespaces in their resources.
We can provide an overlay with the logic similar to the logic currently implemented in this code. Something similar to this:
We should consider providing an explicit way to set the namespace for the application. Before it was not needed, because we were setting the namespace via the ArgoCD part of the configuration. Now, when we make ArgoCD optional, we should have another way. In the past, I remember using just
.application.namespace
when needed. This can be sufficient, but I'm not entirely sure if we should invade this "user-defined" area of configuration with pre-defined options.Another minor point is about the usage of
kubectl
. Instead of changing the current namespace, one can simply use--namespace
flag ofkubectl
.