generated from kyma-project/template-repository
-
Notifications
You must be signed in to change notification settings - Fork 10
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
Prevent incompatible migration of Shoot to Runtime CR #405
Merged
Merged
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
0d7b820
Prevent incompatible migration
mvshao 47aa3de
Add stop condtition
mvshao 6237647
Prevent incompatible migration
mvshao e065f45
Add stop condtition
mvshao 5ea1872
Merge branch 'main' into migration-fuse
mvshao 35dc79c
Merge remote-tracking branch 'refs/remotes/origin/migration-fuse' int…
mvshao d2328de
Rename package name due to import problem
mvshao 6907123
Align expecte shoot to nil fields that converter does not configure
mvshao a391d7b
Create new matchers
mvshao c803874
Remove worker zones sorting
mvshao f4b7b7b
goimports
mvshao 4b8a086
Merge remote-tracking branch 'refs/remotes/origin/remove-zone-sort' i…
mvshao 59d4469
Merge branch 'main' into migration-fuse
mvshao 77ef8ba
Merge remote-tracking branch 'refs/remotes/origin/migration-fuse' int…
mvshao df42857
Update package version
mvshao 9f0e756
Cleanup code base
mvshao 41c0d37
Remove unnecessary hashing
mvshao 1832682
Use the mathers from another source
mvshao 61f81f7
Fix app logic
mvshao 1eee3c5
Merge branch 'main' into migration-fuse
mvshao 8eebfbb
Merge branch 'main' into migration-fuse
mvshao c2ad40e
Apply review sugestions
mvshao 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,62 @@ | ||
module github.com/kyma-project/infrastructure-manager/hack/runtime-migrator-app | ||
|
||
go 1.23.1 | ||
|
||
require ( | ||
github.com/gardener/gardener v1.100.0 | ||
github.com/kyma-project/infrastructure-manager v0.0.0-20241010165136-c9d296aadebd | ||
github.com/kyma-project/infrastructure-manager/hack/shoot-comparator v0.0.0-20241010165136-c9d296aadebd | ||
github.com/pkg/errors v0.9.1 | ||
k8s.io/api v0.31.1 | ||
k8s.io/apimachinery v0.31.1 | ||
k8s.io/client-go v0.31.1 | ||
sigs.k8s.io/controller-runtime v0.19.0 | ||
sigs.k8s.io/yaml v1.4.0 | ||
) | ||
|
||
require ( | ||
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect | ||
github.com/emicklei/go-restful/v3 v3.11.0 // indirect | ||
github.com/evanphx/json-patch/v5 v5.9.0 // indirect | ||
github.com/fxamacker/cbor/v2 v2.7.0 // indirect | ||
github.com/gardener/gardener-extension-provider-aws v1.56.1 // indirect | ||
github.com/gardener/gardener-extension-provider-gcp v1.37.0 // indirect | ||
github.com/gardener/gardener-extension-provider-openstack v1.41.0 // indirect | ||
github.com/go-logr/logr v1.4.2 // indirect | ||
github.com/go-openapi/jsonpointer v0.21.0 // indirect | ||
github.com/go-openapi/jsonreference v0.20.2 // indirect | ||
github.com/go-openapi/swag v0.23.0 // indirect | ||
github.com/gogo/protobuf v1.3.2 // indirect | ||
github.com/golang/protobuf v1.5.4 // indirect | ||
github.com/google/gnostic-models v0.6.8 // indirect | ||
github.com/google/go-cmp v0.6.0 // indirect | ||
github.com/google/gofuzz v1.2.0 // indirect | ||
github.com/google/uuid v1.6.0 // indirect | ||
github.com/imdario/mergo v0.3.16 // indirect | ||
github.com/josharian/intern v1.0.0 // indirect | ||
github.com/json-iterator/go v1.1.12 // indirect | ||
github.com/mailru/easyjson v0.7.7 // indirect | ||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect | ||
github.com/modern-go/reflect2 v1.0.2 // indirect | ||
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect | ||
github.com/onsi/gomega v1.34.1 // indirect | ||
github.com/spf13/pflag v1.0.5 // indirect | ||
github.com/x448/float16 v0.8.4 // indirect | ||
golang.org/x/exp v0.0.0-20240909161429-701f63a606c0 // indirect | ||
golang.org/x/net v0.29.0 // indirect | ||
golang.org/x/oauth2 v0.22.0 // indirect | ||
golang.org/x/sys v0.25.0 // indirect | ||
golang.org/x/term v0.24.0 // indirect | ||
golang.org/x/text v0.18.0 // indirect | ||
golang.org/x/time v0.6.0 // indirect | ||
google.golang.org/protobuf v1.34.2 // indirect | ||
gopkg.in/inf.v0 v0.9.1 // indirect | ||
gopkg.in/yaml.v2 v2.4.0 // indirect | ||
gopkg.in/yaml.v3 v3.0.1 // indirect | ||
k8s.io/apiextensions-apiserver v0.31.0 // indirect | ||
k8s.io/klog/v2 v2.130.1 // indirect | ||
k8s.io/kube-openapi v0.0.0-20240228011516-70dd3763d340 // indirect | ||
k8s.io/utils v0.0.0-20240902221715-702e33fdd3c3 // indirect | ||
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect | ||
sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect | ||
) |
Large diffs are not rendered by default.
Oops, something went wrong.
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,26 @@ | ||
{ | ||
"kubernetes": { | ||
"defaultVersion": "1.29", | ||
"enableKubernetesVersionAutoUpdate": true, | ||
"enableMachineImageVersionAutoUpdate": false | ||
}, | ||
"dns": { | ||
"secretName": "aws-route53-secret-dev", | ||
"domainPrefix": "dev.kyma.ondemand.com", | ||
"providerType": "aws-route53" | ||
}, | ||
"aws": { | ||
"enableIMDSv2": "true" | ||
}, | ||
"machineImage": { | ||
"defaultName" : "gardenlinux", | ||
"defaultVersion": "1592.1.0" | ||
}, | ||
"auditLogging": { | ||
"policyConfigMapName": "auditPlaceholder", | ||
"tenantConfigPath": "placeholder.json" | ||
}, | ||
"gardener": { | ||
"projectName": "kyma-dev" | ||
} | ||
} |
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
{ | ||
7c6b4bd3-09d3-462f-b27c-992727b62eec, | ||
} | ||
[ | ||
"7c6b4bd3-09d3-462f-b27c-992727b62eec", | ||
"another-id" | ||
] |
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,58 @@ | ||
package comparator | ||
|
||
import ( | ||
"github.com/gardener/gardener/pkg/apis/core/v1beta1" | ||
"github.com/kyma-project/infrastructure-manager/hack/shoot-comparator/pkg/shoot" | ||
"github.com/pkg/errors" | ||
) | ||
|
||
type Result struct { | ||
Equal bool | ||
Diff []Difference | ||
} | ||
|
||
type Difference struct { | ||
ShootName string | ||
LeftShoot v1beta1.Shoot | ||
RightShoot v1beta1.Shoot | ||
Message string | ||
} | ||
|
||
func CompareShoots(leftShoot, rightShoot v1beta1.Shoot) (Result, error) { | ||
|
||
differences, err := compare(leftShoot, rightShoot) | ||
if err != nil { | ||
return Result{}, err | ||
} | ||
|
||
equal := len(differences) == 0 | ||
|
||
return Result{ | ||
Equal: equal, | ||
Diff: differences, | ||
}, nil | ||
} | ||
|
||
func compare(leftShoot, rightShoot v1beta1.Shoot) ([]Difference, error) { | ||
var differences []Difference | ||
|
||
matcher := shoot.NewMatcher(leftShoot) | ||
equal, err := matcher.Match(rightShoot) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if !equal { | ||
if leftShoot.Name != rightShoot.Name { | ||
return nil, errors.New("shoot names are different, stopping comparison") | ||
} | ||
diff := Difference{ | ||
ShootName: leftShoot.Name, | ||
LeftShoot: leftShoot, | ||
RightShoot: rightShoot, | ||
Message: matcher.FailureMessage(nil), | ||
} | ||
differences = append(differences, diff) | ||
} | ||
return differences, nil | ||
} |
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,151 @@ | ||
package comparator | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"os" | ||
"path" | ||
) | ||
|
||
type Report struct { | ||
reportFile *os.File | ||
contents string | ||
} | ||
|
||
func SaveComparisonReport(comparisonResult Result, outputDir string, shootName string) (string, error) { | ||
resultsDir, err := createOutputDir(outputDir, shootName) | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
report, err := newReport(resultsDir) | ||
if err != nil { | ||
return "", err | ||
} | ||
defer func() { | ||
if err := report.Close(); err != nil { | ||
log.Printf("Failed to close report file: %q", err) | ||
} | ||
}() | ||
|
||
writeSummary(&report, comparisonResult, shootName) | ||
|
||
if !comparisonResult.Equal { | ||
err = writeDifferencesToReport(&report, comparisonResult.Diff) | ||
if err != nil { | ||
return "", fmt.Errorf("failed to write results to file: %v", err) | ||
} | ||
|
||
err = writeResultsToDiffFiles(comparisonResult.Diff, resultsDir) | ||
if err != nil { | ||
return "", fmt.Errorf("failed to write files with detected differences: %v", err) | ||
} | ||
} | ||
|
||
return resultsDir, report.Save() | ||
} | ||
|
||
func newReport(resultsDir string) (Report, error) { | ||
resultsFile := path.Join(resultsDir, "results.txt") | ||
|
||
file, err := os.Create(resultsFile) | ||
if err != nil { | ||
return Report{}, fmt.Errorf("failed to create results file: %v", err) | ||
} | ||
|
||
return Report{ | ||
reportFile: file, | ||
}, nil | ||
} | ||
|
||
func createOutputDir(outputDir, shootName string) (string, error) { | ||
resultsDir := path.Join(outputDir, shootName) | ||
|
||
err := os.MkdirAll(resultsDir, os.ModePerm) | ||
if err != nil { | ||
return "", fmt.Errorf("failed to create results directory: %v", err) | ||
} | ||
|
||
return resultsDir, nil | ||
} | ||
|
||
func (rw *Report) Save() error { | ||
_, err := rw.reportFile.Write([]byte(rw.contents)) | ||
|
||
return err | ||
} | ||
|
||
func (rw *Report) Close() error { | ||
if rw.reportFile != nil { | ||
return rw.reportFile.Close() | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (rw *Report) AddLine(line string) { | ||
rw.contents += line + "\n" | ||
} | ||
|
||
func writeSummary(report *Report, comparisonResult Result, shootName string) { | ||
report.AddLine(fmt.Sprintf("Comparing generated Shoot with Shoot from Gardener, name: %s", shootName)) | ||
report.AddLine("") | ||
|
||
if comparisonResult.Equal { | ||
report.AddLine("No differences found.") | ||
} else { | ||
report.AddLine("Differences found.") | ||
} | ||
} | ||
|
||
func writeDifferencesToReport(report *Report, differences []Difference) error { | ||
if len(differences) == 0 { | ||
return nil | ||
} | ||
|
||
report.AddLine("") | ||
report.AddLine("------------------------------------------------------------------------------------------") | ||
report.AddLine("Shoot that differ: ") | ||
|
||
for _, difference := range differences { | ||
msg := fmt.Sprintf("-%s", difference.ShootName) | ||
|
||
report.AddLine(msg) | ||
} | ||
|
||
report.AddLine("------------------------------------------------------------------------------------------") | ||
|
||
return nil | ||
} | ||
|
||
func writeResultsToDiffFiles(differences []Difference, resultsDir string) error { | ||
writeAndCloseFunc := func(filePath string, text string) error { | ||
file, err := os.Create(filePath) | ||
if err != nil { | ||
return err | ||
} | ||
defer func() { | ||
if file != nil { | ||
err := file.Close() | ||
if err != nil { | ||
fmt.Printf("failed to close file: %v", err) | ||
} | ||
} | ||
}() | ||
|
||
_, err = file.Write([]byte(text)) | ||
|
||
return err | ||
} | ||
|
||
for _, difference := range differences { | ||
diffFile := path.Join(resultsDir, fmt.Sprintf("%s.diff", difference.ShootName)) | ||
|
||
err := writeAndCloseFunc(diffFile, difference.Message) | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
|
||
return nil | ||
} |
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
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.
equal
could be a method that returnslen(this.differences) == 0
, but this is fine too, although easier to break