-
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
Changes from 21 commits
0d7b820
47aa3de
6237647
e065f45
5ea1872
35dc79c
d2328de
6907123
a391d7b
c803874
f4b7b7b
4b8a086
59d4469
77ef8ba
df42857
9f0e756
41c0d37
1832682
61f81f7
1eee3c5
8eebfbb
c2ad40e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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.
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" | ||
} | ||
} |
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" | ||
] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package comparator | ||
|
||
import ( | ||
"github.com/gardener/gardener/pkg/apis/core/v1beta1" | ||
"github.com/kyma-project/infrastructure-manager/hack/shoot-comparator/pkg/shoot" | ||
) | ||
|
||
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 { | ||
diff := Difference{ | ||
ShootName: leftShoot.Name, // assumption that leftShoot and rightShoot have the same name | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should that assumption be checked? If this is supposed to be always true, maybe it's safer to even crash if it ever isn't? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thx, I will add the step with checking if left == right |
||
LeftShoot: leftShoot, | ||
RightShoot: rightShoot, | ||
Message: matcher.FailureMessage(nil), | ||
} | ||
differences = append(differences, diff) | ||
} | ||
return differences, nil | ||
} |
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 | ||
} |
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