generated from kyma-project/template-repository
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #405 from mvshao/migration-fuse
Prevent incompatible migration of Shoot to Runtime CR
- Loading branch information
Showing
8 changed files
with
580 additions
and
7 deletions.
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.