-
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: Added Smart Mode that Automatically detects changed Environment… #62
Conversation
At a first look, this looks very good and powerful 😎. |
…s and Applications
9fac770
to
6fe1ca6
Compare
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.
Wow, that's solid!
But could we get a description of this mode? To better understand edge cases and application areas. For example, what if there are several base branches (main←development←feature)? What if I want to apply smart mode locally for all commits on my feature branch (like it's done for CI)?
We will then be able to use it for help and documentation.
cmd/root.go
Outdated
if targetEnvironments == nil && targetApplications == nil { | ||
log.Warn().Err(err).Msg("Smart Mode does not identify changes. Rendering everything.") | ||
} |
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.
Would it make sense to skip processing if nothing changed? To process forcefully, we can add a flag or use positional arguments.
myks sync --force
# or
myks sync ALL
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.
Was thinking about that..let's do it.
internal/myks/git.go
Outdated
func extractChangedFilePathsWithStatus(cfs []ChangedFile, status string) []string { | ||
var paths []string | ||
for _, cf := range cfs { | ||
if status == "" || cf.status == status { | ||
paths = append(paths, cf.path) | ||
} | ||
} | ||
return paths | ||
} | ||
|
||
func extractChangedFilePathsWithoutStatus(cfs []ChangedFile, status string) []string { | ||
var paths []string | ||
for _, cf := range cfs { | ||
if status == "" || cf.status != status { | ||
paths = append(paths, cf.path) | ||
} | ||
} | ||
return paths | ||
} |
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.
- Checking for
status
can be moved out of the loop. - I think checking for status should be done outside the function.
- I'd use a more generic function, which accepts a test callback:
func filter[T any](ss []T, test func(T) bool) (ret []T) {
for _, s := range ss {
if test(s) {
ret = append(ret, s)
}
}
return
}
(borrowed from here)
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.
But I'm not blocking you with this suggestion, we can refactor this 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.
Like it, functions are first class citizens in go after all
internal/myks/globe.go
Outdated
g.environments[path] = env | ||
} else { | ||
log.Warn().Str("path", path).Msg("Unable to collect environment, skipping") | ||
if path != g.EnvironmentBaseDir { |
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.
Is it to remove the warning from logs?
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.
yes. Otherwise we always get a warning on the root level env-data.ytt.yaml
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.
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.
Sure, lets set it to debug
log.Warn().Msg("Unable to find data schema file, creating one") | ||
if err := os.MkdirAll(filepath.Dir(dataSchemaFileName), 0o750); err != nil { | ||
log.Fatal().Err(err).Msg("Unable to create data schema file directory") | ||
} | ||
if err := os.WriteFile(dataSchemaFileName, dataSchema, 0o600); err != nil { |
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.
I think thins won't be necessary after merging from release-2.0.
…s and Applications
# Conflicts: # internal/myks/globe.go
@fritzduchardt for auto mode we have also some issue rendering and detecting rendered files
|
Fair point - will look into it |
Let's not over complicate the smart mode. |
Agreed - a stab at coding this reveals that the complexity increase would be substantial, especially, because the env structure in the rendered folder is flattened. So, once @Zebradil gives me his well, I am happy to merge this. |
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.
🚀
# [1.3.0](v1.2.0...v1.3.0) (2023-09-19) ### Bug Fixes * Add documentation the myks sync step ([#38](#38)) ([e61a10c](e61a10c)), closes [#37](#37) * apply smart mode logic only to supported commands ([#83](#83)) ([2bc754f](2bc754f)) * argocd source plugin config type in schema ([520156d](520156d)) * cleanup vendir folder ([#90](#90)) ([a20df1a](a20df1a)) * consistent behavior on rendering ALL applications ([#79](#79)) ([2aab516](2aab516)) * correct sources for the global-ytt rendering step ([#50](#50)) ([5a0e4d7](5a0e4d7)) * create myks data schema file on init and on every run ([#84](#84)) ([976291e](976291e)) * data values of prototype of argocd app ([b5d7ff9](b5d7ff9)) * do not fail on absent rendered directory ([eaf1202](eaf1202)) * do not fail without vendir configs ([2f73cda](2f73cda)) * do not override ArgoCD defaults set by user ([#74](#74)) ([f2cf4ce](f2cf4ce)), closes [#70](#70) * **docker:** do not build arm64, it is not supported ([3971ae7](3971ae7)) * **docker:** specify full image tag ([f3222e5](f3222e5)) * formatting ([fd65f05](fd65f05)) * generate ArgoCD secret only if enabled ([4b3ed11](4b3ed11)) * helm value file merge ([#33](#33)) ([3c9c0ea](3c9c0ea)), closes [#32](#32) * init Globe core attributes earlier ([#85](#85)) ([20c48fd](20c48fd)) * log errors during vendir sync ([5dc1b5e](5dc1b5e)) * make render errors appear in the log with full error message ([c325da2](c325da2)) * process map keys instead of values ([3b86a03](3b86a03)) * reduce usage of pointers to cope with race conditions ([#88](#88)) ([d734933](d734933)) * search in the default envs directory ([ef4a75e](ef4a75e)) * skip helm rendering ([80a8eb5](80a8eb5)) * **smart-mode:** detect changes when myks root is in subdirectory ([0522b67](0522b67)) * update data-schema.ytt.yaml according to the latest Myks changes ([5ef9d34](5ef9d34)) * use ArgoCD application path relatively to git root ([92f0617](92f0617)) ### Features * add a finalizer to ArgoCD project CR ([acf67fd](acf67fd)) * add argocd-apps prototype ([6772744](6772744)) * add arm binaries ([a74d63e](a74d63e)) * add common overlays example to assets ([39965c5](39965c5)) * add example environment configs ([8edba12](8edba12)) * add flag to control parallelism ([#40](#40)) ([144f5fd](144f5fd)) * add git branch detection and refactor data schema ([05e41d4](05e41d4)) * add init command and a data schema file ([c11c27a](c11c27a)) * add prototypes in the init command ([f31471e](f31471e)) * add step for rendering ytt packages ([#36](#36)) ([d1078c6](d1078c6)) * Add vendir authentication via environment ([b0c50c2](b0c50c2)) * Add vendir sync caching ([24ff41c](24ff41c)) * Added docker image ([ae8988d](ae8988d)) * Added Smart Mode that Automatically detects changed Environment… ([#62](#62)) ([e404b6b](e404b6b)) * always write data-schema file ([fa83bee](fa83bee)) * ArgoCD support ([#41](#41)) ([e45d585](e45d585)) * configure ArgoCD Application finalizers and source.plugin ([#56](#56)) ([80940aa](80940aa)) * create initial .myks.yaml and print configs ([#87](#87)) ([215ccd3](215ccd3)) * detect additional and missing applications ([#89](#89)) ([2c7e101](2c7e101)) * do not convert git URL protocol ([2823eb6](2823eb6)) * dump configuration as ytt values ([af65436](af65436)) * fail on non existing apps ([#52](#52)) ([87aafa3](87aafa3)), closes [#3](#3) * fine-grained ArgoCD project destination ([04d3b78](04d3b78)) * get git repo URL ([c9b726a](c9b726a)) * **helm:** add support for helm capabilities ([#48](#48)) ([1a13ee1](1a13ee1)), closes [#31](#31) * **init:** allow overwriting of data ([#49](#49)) ([f3f5983](f3f5983)) * provide argocd-specific configuration with prototypes ([06e5e5c](06e5e5c)) * provide example default values for all environments ([0f9cab6](0f9cab6)) * Push images to docker hub and ghcr ([#65](#65)) ([10bdc63](10bdc63)) * Refactoring to make log output more intelligible. ([#39](#39)) ([71cd34c](71cd34c)) * **smart-mode:** configuration option for smart-mode base revision ([#95](#95)) ([4400184](4400184)) * **smart-mode:** precisely select envs and apps for processing ([#96](#96)) ([ffb47ad](ffb47ad)) * support multiple content items in vendir configs ([#92](#92)) ([fc50be0](fc50be0)) * tweak prefix logic on argo cr to allow for project names like "… ([#72](#72)) ([af01180](af01180)) * validate root directory ([f81b719](f81b719)) * vendir sync caching ([7279cc7](7279cc7)) ### Performance Improvements * **docker:** ignore not needed files ([3479804](3479804))
# [2.0.0](v1.2.0...v2.0.0) (2023-09-19) ### Bug Fixes * Add documentation the myks sync step ([#38](#38)) ([e61a10c](e61a10c)), closes [#37](#37) * apply smart mode logic only to supported commands ([#83](#83)) ([2bc754f](2bc754f)) * argocd source plugin config type in schema ([520156d](520156d)) * cleanup vendir folder ([#90](#90)) ([a20df1a](a20df1a)) * consistent behavior on rendering ALL applications ([#79](#79)) ([2aab516](2aab516)) * correct sources for the global-ytt rendering step ([#50](#50)) ([5a0e4d7](5a0e4d7)) * create myks data schema file on init and on every run ([#84](#84)) ([976291e](976291e)) * data values of prototype of argocd app ([b5d7ff9](b5d7ff9)) * do not fail on absent rendered directory ([eaf1202](eaf1202)) * do not fail without vendir configs ([2f73cda](2f73cda)) * do not override ArgoCD defaults set by user ([#74](#74)) ([f2cf4ce](f2cf4ce)), closes [#70](#70) * **docker:** do not build arm64, it is not supported ([3971ae7](3971ae7)) * **docker:** specify full image tag ([f3222e5](f3222e5)) * formatting ([fd65f05](fd65f05)) * generate ArgoCD secret only if enabled ([4b3ed11](4b3ed11)) * helm value file merge ([#33](#33)) ([3c9c0ea](3c9c0ea)), closes [#32](#32) * init Globe core attributes earlier ([#85](#85)) ([20c48fd](20c48fd)) * log errors during vendir sync ([5dc1b5e](5dc1b5e)) * make render errors appear in the log with full error message ([c325da2](c325da2)) * process map keys instead of values ([3b86a03](3b86a03)) * reduce usage of pointers to cope with race conditions ([#88](#88)) ([d734933](d734933)) * search in the default envs directory ([ef4a75e](ef4a75e)) * skip helm rendering ([80a8eb5](80a8eb5)) * **smart-mode:** detect changes when myks root is in subdirectory ([0522b67](0522b67)) * update data-schema.ytt.yaml according to the latest Myks changes ([5ef9d34](5ef9d34)) * use ArgoCD application path relatively to git root ([92f0617](92f0617)) ### Features * add a finalizer to ArgoCD project CR ([acf67fd](acf67fd)) * add argocd-apps prototype ([6772744](6772744)) * add arm binaries ([a74d63e](a74d63e)) * add common overlays example to assets ([39965c5](39965c5)) * add example environment configs ([8edba12](8edba12)) * add flag to control parallelism ([#40](#40)) ([144f5fd](144f5fd)) * add git branch detection and refactor data schema ([05e41d4](05e41d4)) * add init command and a data schema file ([c11c27a](c11c27a)) * add prototypes in the init command ([f31471e](f31471e)) * add step for rendering ytt packages ([#36](#36)) ([d1078c6](d1078c6)) * Add vendir authentication via environment ([b0c50c2](b0c50c2)) * Add vendir sync caching ([24ff41c](24ff41c)) * Added docker image ([ae8988d](ae8988d)) * Added Smart Mode that Automatically detects changed Environment… ([#62](#62)) ([e404b6b](e404b6b)) * always write data-schema file ([fa83bee](fa83bee)) * ArgoCD support ([#41](#41)) ([e45d585](e45d585)) * configure ArgoCD Application finalizers and source.plugin ([#56](#56)) ([80940aa](80940aa)) * create initial .myks.yaml and print configs ([#87](#87)) ([215ccd3](215ccd3)) * detect additional and missing applications ([#89](#89)) ([2c7e101](2c7e101)) * do not convert git URL protocol ([2823eb6](2823eb6)) * dump configuration as ytt values ([af65436](af65436)) * fail on non existing apps ([#52](#52)) ([87aafa3](87aafa3)), closes [#3](#3) * fine-grained ArgoCD project destination ([04d3b78](04d3b78)) * get git repo URL ([c9b726a](c9b726a)) * **helm:** add support for helm capabilities ([#48](#48)) ([1a13ee1](1a13ee1)), closes [#31](#31) * **init:** allow overwriting of data ([#49](#49)) ([f3f5983](f3f5983)) * provide argocd-specific configuration with prototypes ([06e5e5c](06e5e5c)) * provide example default values for all environments ([0f9cab6](0f9cab6)) * Push images to docker hub and ghcr ([#65](#65)) ([10bdc63](10bdc63)) * Refactoring to make log output more intelligible. ([#39](#39)) ([71cd34c](71cd34c)) * release 2.0 ([b7b486d](b7b486d)) * **smart-mode:** configuration option for smart-mode base revision ([#95](#95)) ([4400184](4400184)) * **smart-mode:** precisely select envs and apps for processing ([#96](#96)) ([ffb47ad](ffb47ad)) * support multiple content items in vendir configs ([#92](#92)) ([fc50be0](fc50be0)) * tweak prefix logic on argo cr to allow for project names like "… ([#72](#72)) ([af01180](af01180)) * validate root directory ([f81b719](f81b719)) * vendir sync caching ([7279cc7](7279cc7)) ### Performance Improvements * **docker:** ignore not needed files ([3479804](3479804)) ### BREAKING CHANGES * release 2.0 This is an empty commit to trigger a major release.
# [2.0.0](v1.2.0...v2.0.0) (2023-09-19) ### Bug Fixes * Add documentation the myks sync step ([#38](#38)) ([e61a10c](e61a10c)), closes [#37](#37) * apply smart mode logic only to supported commands ([#83](#83)) ([2bc754f](2bc754f)) * argocd source plugin config type in schema ([520156d](520156d)) * cleanup vendir folder ([#90](#90)) ([a20df1a](a20df1a)) * consistent behavior on rendering ALL applications ([#79](#79)) ([2aab516](2aab516)) * correct sources for the global-ytt rendering step ([#50](#50)) ([5a0e4d7](5a0e4d7)) * create myks data schema file on init and on every run ([#84](#84)) ([976291e](976291e)) * data values of prototype of argocd app ([b5d7ff9](b5d7ff9)) * do not fail on absent rendered directory ([eaf1202](eaf1202)) * do not fail without vendir configs ([2f73cda](2f73cda)) * do not override ArgoCD defaults set by user ([#74](#74)) ([f2cf4ce](f2cf4ce)), closes [#70](#70) * **docker:** do not build arm64, it is not supported ([3971ae7](3971ae7)) * **docker:** specify full image tag ([f3222e5](f3222e5)) * formatting ([fd65f05](fd65f05)) * generate ArgoCD secret only if enabled ([4b3ed11](4b3ed11)) * helm value file merge ([#33](#33)) ([3c9c0ea](3c9c0ea)), closes [#32](#32) * init Globe core attributes earlier ([#85](#85)) ([20c48fd](20c48fd)) * log errors during vendir sync ([5dc1b5e](5dc1b5e)) * make render errors appear in the log with full error message ([c325da2](c325da2)) * process map keys instead of values ([3b86a03](3b86a03)) * reduce usage of pointers to cope with race conditions ([#88](#88)) ([d734933](d734933)) * search in the default envs directory ([ef4a75e](ef4a75e)) * skip helm rendering ([80a8eb5](80a8eb5)) * **smart-mode:** detect changes when myks root is in subdirectory ([0522b67](0522b67)) * update data-schema.ytt.yaml according to the latest Myks changes ([5ef9d34](5ef9d34)) * use ArgoCD application path relatively to git root ([92f0617](92f0617)) ### Features * add a finalizer to ArgoCD project CR ([acf67fd](acf67fd)) * add argocd-apps prototype ([6772744](6772744)) * add arm binaries ([a74d63e](a74d63e)) * add common overlays example to assets ([39965c5](39965c5)) * add example environment configs ([8edba12](8edba12)) * add flag to control parallelism ([#40](#40)) ([144f5fd](144f5fd)) * add git branch detection and refactor data schema ([05e41d4](05e41d4)) * add init command and a data schema file ([c11c27a](c11c27a)) * add prototypes in the init command ([f31471e](f31471e)) * add step for rendering ytt packages ([#36](#36)) ([d1078c6](d1078c6)) * Add vendir authentication via environment ([b0c50c2](b0c50c2)) * Add vendir sync caching ([24ff41c](24ff41c)) * Added docker image ([ae8988d](ae8988d)) * Added Smart Mode that Automatically detects changed Environment… ([#62](#62)) ([e404b6b](e404b6b)) * always write data-schema file ([fa83bee](fa83bee)) * ArgoCD support ([#41](#41)) ([e45d585](e45d585)) * configure ArgoCD Application finalizers and source.plugin ([#56](#56)) ([80940aa](80940aa)) * create initial .myks.yaml and print configs ([#87](#87)) ([215ccd3](215ccd3)) * detect additional and missing applications ([#89](#89)) ([2c7e101](2c7e101)) * do not convert git URL protocol ([2823eb6](2823eb6)) * dump configuration as ytt values ([af65436](af65436)) * fail on non existing apps ([#52](#52)) ([87aafa3](87aafa3)), closes [#3](#3) * fine-grained ArgoCD project destination ([04d3b78](04d3b78)) * get git repo URL ([c9b726a](c9b726a)) * **helm:** add support for helm capabilities ([#48](#48)) ([1a13ee1](1a13ee1)), closes [#31](#31) * **init:** allow overwriting of data ([#49](#49)) ([f3f5983](f3f5983)) * provide argocd-specific configuration with prototypes ([06e5e5c](06e5e5c)) * provide example default values for all environments ([0f9cab6](0f9cab6)) * Push images to docker hub and ghcr ([#65](#65)) ([10bdc63](10bdc63)) * Refactoring to make log output more intelligible. ([#39](#39)) ([71cd34c](71cd34c)) * release 2.0 ([b7b486d](b7b486d)) * **smart-mode:** configuration option for smart-mode base revision ([#95](#95)) ([4400184](4400184)) * **smart-mode:** precisely select envs and apps for processing ([#96](#96)) ([ffb47ad](ffb47ad)) * support multiple content items in vendir configs ([#92](#92)) ([fc50be0](fc50be0)) * tweak prefix logic on argo cr to allow for project names like "… ([#72](#72)) ([af01180](af01180)) * validate root directory ([f81b719](f81b719)) * vendir sync caching ([7279cc7](7279cc7)) ### Performance Improvements * **docker:** ignore not needed files ([3479804](3479804)) ### BREAKING CHANGES * release 2.0 This is an empty commit to trigger a major release.
…s and Applications