github.com/GoogleContainerTools/skaffold@v1.39.18/pkg/skaffold/schema/v1alpha3/upgrade.go (about)

     1  /*
     2  Copyright 2019 The Skaffold Authors
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package v1alpha3
    18  
    19  import (
    20  	"github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/util"
    21  	next "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/v1alpha4"
    22  	pkgutil "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util"
    23  )
    24  
    25  // Upgrade upgrades a configuration to the next version.
    26  // Config changes from v1alpha3 to v1alpha4:
    27  // 1. Additions:
    28  //   - SkaffoldConfig.Test, Profile.Test, TestCase, TestConfig
    29  //   - KanikoBuildContext.LocalDir, LocalDir
    30  //   - KanikoBuild.Image
    31  //   - Artifact.Sync
    32  //   - JibMavenArtifact, JibGradleArtifact
    33  //
    34  // 2. No removal
    35  // 3. Updates
    36  //   - EnvTemplate.Template is now optional in yaml
    37  //   - LocalBuild.SkipPush=false (v1alpha3) -> LocalBuild.Push=true (v1alpha4)_
    38  //   - kustomizePath -> path in yaml
    39  //   - HelmRelease, HelmPackaged, HelmFQNConfig fields are optional in yaml,
    40  //   - Artifact.imageName -> image, workspace -> context in yaml
    41  //   - DockerArtifact.dockerfilePath -> dockerfile in yaml
    42  //   - BazelArtifact.BuildTarget is optional in yaml
    43  func (c *SkaffoldConfig) Upgrade() (util.VersionedConfig, error) {
    44  	// convert Deploy (should be the same)
    45  	var newDeploy next.DeployConfig
    46  	pkgutil.CloneThroughJSON(c.Deploy, &newDeploy)
    47  
    48  	// convert Profiles (should be the same)
    49  	var newProfiles []next.Profile
    50  	if c.Profiles != nil {
    51  		pkgutil.CloneThroughJSON(c.Profiles, &newProfiles)
    52  
    53  		for i, oldProfile := range c.Profiles {
    54  			convertBuild(oldProfile.Build, newProfiles[i].Build)
    55  		}
    56  	}
    57  
    58  	// convert Build (should be the same)
    59  	var newBuild next.BuildConfig
    60  	oldBuild := c.Build
    61  	pkgutil.CloneThroughJSON(oldBuild, &newBuild)
    62  	convertBuild(oldBuild, newBuild)
    63  
    64  	return &next.SkaffoldConfig{
    65  		APIVersion: next.Version,
    66  		Kind:       c.Kind,
    67  		Deploy:     newDeploy,
    68  		Build:      newBuild,
    69  		Profiles:   newProfiles,
    70  	}, nil
    71  }
    72  
    73  func convertBuild(oldBuild BuildConfig, newBuild next.BuildConfig) {
    74  	if oldBuild.LocalBuild != nil && oldBuild.LocalBuild.SkipPush != nil {
    75  		push := !*oldBuild.LocalBuild.SkipPush
    76  		newBuild.LocalBuild.Push = &push
    77  	}
    78  }