Skip to content

Commit

Permalink
Check for new skaffold version when skaffold.yaml parsing fails
Browse files Browse the repository at this point in the history
Signed-off-by: Cornelius Weig <[email protected]>
  • Loading branch information
Cornelius Weig committed Feb 1, 2019
1 parent f5dbcb3 commit da9e7d8
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 17 deletions.
11 changes: 3 additions & 8 deletions cmd/skaffold/app/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ limitations under the License.
package cmd

import (
"context"
"fmt"
"io"
"os"
Expand Down Expand Up @@ -98,15 +97,11 @@ func updateCheck(ch chan string) error {
logrus.Debugf("Update check not enabled, skipping.")
return nil
}
current, err := version.ParseVersion(version.Get().Version)
latest, isAhead, err := update.VersionCheck()
if err != nil {
return errors.Wrap(err, "parsing current semver, skipping update check")
return errors.Wrap(err, "version check")
}
latest, err := update.GetLatestVersion(context.Background())
if err != nil {
return errors.Wrap(err, "getting latest version")
}
if latest.GT(current) {
if isAhead {
ch <- fmt.Sprintf("There is a new version (%s) of Skaffold available. Download it at %s\n", latest, constants.LatestDownloadURL)
}
return nil
Expand Down
7 changes: 7 additions & 0 deletions cmd/skaffold/app/cmd/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,25 @@ package cmd
import (
configutil "github.com/GoogleContainerTools/skaffold/cmd/skaffold/app/cmd/config"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/config"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/constants"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/runner"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/defaults"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/update"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/util"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
)

// newRunner creates a SkaffoldRunner and returns the SkaffoldPipeline associated with it.
func newRunner(opts *config.SkaffoldOptions) (*runner.SkaffoldRunner, *latest.SkaffoldPipeline, error) {
parsed, err := schema.ParseConfig(opts.ConfigurationFile, true)
if err != nil {
version, isAhead, versionErr := update.VersionCheck()
if versionErr == nil && isAhead {
logrus.Warnf("Your Skaffold version might be too old. Download the latest version (%s) at %s\n", version, constants.LatestDownloadURL)
}
return nil, nil, errors.Wrap(err, "parsing skaffold config")
}

Expand Down
22 changes: 13 additions & 9 deletions pkg/skaffold/update/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ limitations under the License.
package update

import (
"context"
"io/ioutil"
"net/http"
"os"
Expand All @@ -43,23 +42,28 @@ func IsUpdateCheckEnabled() bool {
return v == "" || strings.ToLower(v) == "true"
}

// GetLatestVersion uses a VERSION file stored on GCS to determine the latest released version of skaffold
func GetLatestVersion(ctx context.Context) (semver.Version, error) {
// VersionCheck uses a VERSION file stored on GCS to determine the latest released version of skaffold
func VersionCheck() (semver.Version, bool, error) {
resp, err := http.Get(latestVersionURL)
if err != nil {
return semver.Version{}, errors.Wrap(err, "getting latest version info from GCS")
return semver.Version{}, false, errors.Wrap(err, "getting latest version info from GCS")
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
return semver.Version{}, errors.Wrapf(err, "http %d, error: %s", resp.StatusCode, resp.Status)
return semver.Version{}, false, errors.Wrapf(err, "http %d, error: %s", resp.StatusCode, resp.Status)
}
versionBytes, err := ioutil.ReadAll(resp.Body)
if err != nil {
return semver.Version{}, errors.Wrap(err, "reading version file from GCS")
return semver.Version{}, false, errors.Wrap(err, "reading version file from GCS")
}
v, err := version.ParseVersion(string(versionBytes))
latest, err := version.ParseVersion(string(versionBytes))
if err != nil {
return semver.Version{}, errors.Wrap(err, "parsing latest version from GCS")
return semver.Version{}, false, errors.Wrap(err, "parsing latest version from GCS")
}
return v, nil
current, err := version.ParseVersion(version.Get().Version)
if err != nil {
return semver.Version{}, false, errors.Wrap(err, "parsing current semver, skipping update check")
}
isAhead := latest.GT(current)
return latest, isAhead, nil
}
1 change: 1 addition & 0 deletions pkg/webhook/kubernetes/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ func WaitForDeploymentToStabilize(d *appsv1.Deployment, ip string) error {
if err != nil {
return false, nil
}
defer resp.Body.Close()
return resp.StatusCode == http.StatusOK, nil
})
}
Expand Down

0 comments on commit da9e7d8

Please sign in to comment.