feat: cluster upgrade recommendation#50
Conversation
| if generateMigrationFiles { | ||
| generator := pkg.NewMigrationFileGenerator(migrationOutputDir, noColor) | ||
| if err := generator.GenerateMigrationFiles(aggResults); err != nil { | ||
| log.Fatalf("Failed to generate migration files: %v", err) |
There was a problem hiding this comment.
don't use log.fatal here ,let's just print the error here using log2.Error(err) and return success as false , and let the callee handle the os.Exit part.
| RootCmd.Flags().BoolVar(&generateMigrationFiles, "generate-migration-files", false, "Generate migration files for API version updates") | ||
| RootCmd.Flags().StringVar(&migrationOutputDir, "migration-output-dir", "migrations", "Directory to store generated migration files") |
There was a problem hiding this comment.
are we expecting user to give both these flags to generate manifest files ? can't we just take single flag i.e the path they want to store the generated manifest and check from code that if length of this flag is >0 then user want to generate the manifest file
This'll ensure it's more user friendly as they would need to give single flag to generate manifest.
Also let's change the name of migration-output-dir to --upgraded-manifests-dir , this single flag would be necessary as this will clearly express the intentions of the flag
| success = false | ||
| } | ||
|
|
||
| if generateMigrationFiles { |
There was a problem hiding this comment.
one flag changes are done , check on len() instead of this flag
| Put(r ValidationResult) error | ||
| Flush() error | ||
| GetSummaryValidationResultBulk() []SummaryValidationResult | ||
| GenerateMigrationFiles(results []ValidationResult, outputDir string) error |
There was a problem hiding this comment.
Rename this func. to WriteUpgradedClusterManifests , this clearly shows func's intentions , GenerateMigrationFiles this is vague .
| type MigrationFileGenerator struct { | ||
| outputDir string | ||
| noColor bool | ||
| } |
There was a problem hiding this comment.
change name to ManifestExporter
this can act as generic manifest generator, say for example if we want to generate manifest for old cluster version's data then I can use this struct and it's methods implemented on it . rn it's only for migrated files
| generator := pkg.NewMigrationFileGenerator(migrationOutputDir, noColor) | ||
| if err := generator.GenerateMigrationFiles(results); err != nil { |
There was a problem hiding this comment.
You should use outputManager.GenerateMigrationFiles (aftger renaming this func use renamed func name ) since you have already bound this func to OutputManager
| Deprecated bool | ||
| LatestAPIVersion string | ||
| IsVersionSupported int | ||
| Resource map[string]interface{} `json:"resource,omitempty"` |
There was a problem hiding this comment.
why is json tag necessary here ?
There was a problem hiding this comment.
Also what will this key store ?
There was a problem hiding this comment.
make the different struct ?
| for _, result := range results { | ||
| // Generate migration file for each resource, even if it has errors | ||
| if err := m.generateMigrationFile(result); err != nil { | ||
| return fmt.Errorf("failed to generate migration file for %s/%s: %v", |
There was a problem hiding this comment.
this is not optimal, this error printing in for loop will fill the whole terminal with errors which will also be unreadable , instead of this use struct to store error resp. for each errored result (gvk) and just continue generating manifest for other resources , for errored manifest just iterate over them and maybe generate another file with errored manifest output
There was a problem hiding this comment.
let's disc this on monday I've few more pointers regarding this
| result.ResourceNamespace, | ||
| result.ResourceName, | ||
| strings.ToLower(result.Kind)) |
There was a problem hiding this comment.
strings.ToLower is applied for kind , can we apply it for ResourceNamespace and ResourceName as well as general convention
| } | ||
|
|
||
| func (m *MigrationFileGenerator) GenerateMigrationFiles(results []ValidationResult) error { | ||
| if err := os.MkdirAll(m.outputDir, 0755); err != nil { |
There was a problem hiding this comment.
let's lower the permission level for this file , generally 755 permiossion is given to files or dirs which contains executables , since this only contains files to be read, lets make this 644
Add Migration File Generation Feature
Description
This PR adds a new feature to generate migration files when Kubernetes API versions change between different Kubernetes versions. The feature helps users automatically generate updated manifests with the correct API versions while preserving all other configurations.
Changes
--generate-migration-files: Enable migration file generation--migration-output-dir: Specify output directory for migration files (default: "migrations")Resourcefield toValidationResultstruct to store original resource dataMigrationFileGeneratorto handle migration file creationHow it Works
When the
--generate-migration-filesflag is used, the tool:extensions/v1beta1→apps/v1)Migration files are generated with names following the format:
Each migration file contains:
Example Usage
Testing
Benefits
Related Issues
#13