Skip to content
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

Correctly migrate sync config in profiles #2415

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 32 additions & 17 deletions pkg/skaffold/schema/v1beta9/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,26 +52,23 @@ func (config *SkaffoldConfig) Upgrade() (util.VersionedConfig, error) {

// convert Profiles (should be the same)
var newProfiles []next.Profile
if config.Profiles != nil {
if err := pkgutil.CloneThroughJSON(config.Profiles, &newProfiles); err != nil {
for _, p := range config.Profiles {
var newProfile next.Profile
if err := pkgutil.CloneThroughJSON(p, &newProfile); err != nil {
return nil, errors.Wrap(err, "converting new profile")
}
newProfileBuild, err := convertBuildConfig(p.Build)
if err != nil {
return nil, errors.Wrap(err, "converting new profile build")
}
newProfile.Build = newProfileBuild
newProfiles = append(newProfiles, newProfile)
}

newSyncRules := config.convertSyncRules()
// convert Build (should be same)
var newBuild next.BuildConfig
if err := pkgutil.CloneThroughJSON(config.Build, &newBuild); err != nil {
newBuild, err := convertBuildConfig(config.Build)
if err != nil {
return nil, errors.Wrap(err, "converting new build")
}
// set Sync in newBuild
for i, a := range newBuild.Artifacts {
if len(newSyncRules[i]) > 0 {
a.Sync = &next.Sync{
Manual: newSyncRules[i],
}
}
}

// convert Test (should be the same)
var newTest []*next.TestCase
Expand All @@ -91,12 +88,30 @@ func (config *SkaffoldConfig) Upgrade() (util.VersionedConfig, error) {
}, nil
}

func convertBuildConfig(build BuildConfig) (next.BuildConfig, error) {
// convert Build (should be same)
var newBuild next.BuildConfig
if err := pkgutil.CloneThroughJSON(build, &newBuild); err != nil {
return next.BuildConfig{}, err
}
// set Sync in newBuild
newSyncRules := convertSyncRules(build.Artifacts)
for i, a := range newBuild.Artifacts {
if len(newSyncRules[i]) > 0 {
a.Sync = &next.Sync{
Manual: newSyncRules[i],
}
}
}
return newBuild, nil
}

// convertSyncRules converts the old sync map into sync rules.
// It also prints a warning message when some rules can not be upgraded.
func (config *SkaffoldConfig) convertSyncRules() [][]*next.SyncRule {
func convertSyncRules(artifacts []*Artifact) [][]*next.SyncRule {
var incompatiblePatterns []string
newSync := make([][]*next.SyncRule, len(config.Build.Artifacts))
for i, a := range config.Build.Artifacts {
newSync := make([][]*next.SyncRule, len(artifacts))
for i, a := range artifacts {
newRules := make([]*next.SyncRule, 0, len(a.Sync))
for src, dest := range a.Sync {
var syncRule *next.SyncRule
Expand Down
16 changes: 16 additions & 0 deletions pkg/skaffold/schema/v1beta9/upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,13 @@ build:
sync:
'src/***/*.js': app/
- image: nginx
profiles:
- name: test-profile-migration
build:
artifacts:
- image: gcr.io/k8s-skaffold/node-example
sync:
'**/*.js': .
deploy:
kubectl:
manifests:
Expand Down Expand Up @@ -236,6 +243,15 @@ build:
dest: app/
strip: src/
- image: nginx
profiles:
- name: test-profile-migration
build:
artifacts:
- image: gcr.io/k8s-skaffold/node-example
sync:
manual:
- src: '**/*.js'
dest: .
deploy:
kubectl:
manifests:
Expand Down