Skip to content

Commit

Permalink
Merge pull request #187 from pwittrock/fix
Browse files Browse the repository at this point in the history
Support for `update vendor` and `version`
  • Loading branch information
Phillip Wittrock committed Oct 21, 2017
2 parents c7a7c5d + 001493b commit 4c733dd
Show file tree
Hide file tree
Showing 15 changed files with 298 additions and 17 deletions.
1 change: 1 addition & 0 deletions cmd/apiregister-gen/generators/apis_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"text/template"

"fmt"

"k8s.io/gengo/generator"
)

Expand Down
3 changes: 2 additions & 1 deletion cmd/apiregister-gen/generators/install_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ import (
"io"
"text/template"

"k8s.io/gengo/generator"
"path"

"k8s.io/gengo/generator"
)

type installGenerator struct {
Expand Down
4 changes: 3 additions & 1 deletion cmd/apiserver-boot/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ go_library(
"//cmd/apiserver-boot/boot/create:go_default_library",
"//cmd/apiserver-boot/boot/init_repo:go_default_library",
"//cmd/apiserver-boot/boot/run:go_default_library",
"//cmd/apiserver-boot/boot/update:go_default_library",
"//cmd/apiserver-boot/boot/util:go_default_library",
"//cmd/vendor/github.com/spf13/cobra:go_default_library",
"//cmd/apiserver-boot/boot/version:go_default_library",
"//vendor/github.com/spf13/cobra:go_default_library",
],
)

Expand Down
3 changes: 2 additions & 1 deletion cmd/apiserver-boot/boot/build/build_container.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ import (
"os"
"path/filepath"

"io/ioutil"

"github.com/kubernetes-incubator/apiserver-builder/cmd/apiserver-boot/boot/util"
"github.com/spf13/cobra"
"io/ioutil"
)

var Image string
Expand Down
12 changes: 6 additions & 6 deletions cmd/apiserver-boot/boot/build/build_resource_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,9 @@ func buildResourceConfig() {
ControllerSecretMount: ControllerSecretMount,
ControllerSecret: ControllerSecret,
ControllerSecretEnv: ControllerSecretEnv,
LocalIp: LocalIp,
ImagePullSecrets: ImagePullSecrets,
ServiceAccount: ServiceAccount,
LocalIp: LocalIp,
ImagePullSecrets: ImagePullSecrets,
ServiceAccount: ServiceAccount,
}
path := filepath.Join(ResourceConfigDir, "apiserver.yaml")

Expand Down Expand Up @@ -260,9 +260,9 @@ type resourceConfigTemplateArgs struct {
ControllerSecret string
ControllerSecretMount string
ControllerSecretEnv []string
LocalIp string
ServiceAccount string
ImagePullSecrets []string
LocalIp string
ServiceAccount string
ImagePullSecrets []string
}

var resourceConfigTemplate = `
Expand Down
3 changes: 2 additions & 1 deletion cmd/apiserver-boot/boot/create/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ import (
"os"
"path/filepath"

"strings"

"github.com/kubernetes-incubator/apiserver-builder/cmd/apiserver-boot/boot/util"
"github.com/spf13/cobra"
"strings"
)

var createGroupCmd = &cobra.Command{
Expand Down
69 changes: 65 additions & 4 deletions cmd/apiserver-boot/boot/init_repo/glide.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ import (
"path/filepath"
"strings"

"io/ioutil"

"github.com/kubernetes-incubator/apiserver-builder/cmd/apiserver-boot/boot/util"
"github.com/spf13/cobra"
"io/ioutil"
)

var glideInstallCmd = &cobra.Command{
Expand All @@ -45,10 +46,12 @@ apiserver-boot init glide --fetch

var fetch bool
var builderCommit string
var Update bool

func AddGlideInstallCmd(cmd *cobra.Command) {
glideInstallCmd.Flags().BoolVar(&fetch, "fetch", true, "if true, fetch new glide deps instead of copying the ones packaged with the tools")
glideInstallCmd.Flags().StringVar(&builderCommit, "commit", "", "if specified with fetch, use this commit for the apiserver-builder deps")
glideInstallCmd.Flags().BoolVar(&Update, "update", false, "if true, don't touch glide.yaml or glide.lock, and replace versions of packages managed by apiserver-boot.")
cmd.AddCommand(glideInstallCmd)
}

Expand Down Expand Up @@ -104,7 +107,12 @@ func fetchGlide() {
}
}

func copyGlide() {
func CopyGlide() {
// Delete old versions of the packages we manage before installing the new ones
if Update {
DeleteOld()
}

// Move up two directories from the location of the `apiserver-boot`
// executable to find the `vendor` directory we package with our
// releases.
Expand Down Expand Up @@ -135,6 +143,11 @@ func copyGlide() {

for file, err := tr.Next(); err == nil; file, err = tr.Next() {
p := filepath.Join(".", file.Name)

if Update && filepath.Dir(p) == "." {
continue
}

err := os.MkdirAll(filepath.Dir(p), 0700)
if err != nil {
log.Fatalf("Could not create directory %s: %v", filepath.Dir(p), err)
Expand All @@ -150,12 +163,60 @@ func copyGlide() {
}
}

// DeleteOld delete all the versions for all packages it is going to untar
func DeleteOld() {
// Move up two directories from the location of the `apiserver-boot`
// executable to find the `vendor` directory we package with our
// releases.
e, err := os.Executable()
if err != nil {
log.Fatal("unable to get directory of apiserver-builder tools")
}

e = filepath.Dir(filepath.Dir(e))

// read the file
f := filepath.Join(e, "bin", "glide.tar.gz")
fr, err := os.Open(f)
if err != nil {
log.Fatalf("failed to read vendor tar file %s %v", f, err)
}
defer fr.Close()

// setup gzip of tar
gr, err := gzip.NewReader(fr)
if err != nil {
log.Fatalf("failed to read vendor tar file %s %v", f, err)
}
defer gr.Close()

// setup tar reader
tr := tar.NewReader(gr)

for file, err := tr.Next(); err == nil; file, err = tr.Next() {
p := filepath.Join(".", file.Name)
// Delete existing directory first if upgrading
if filepath.Dir(p) != "." {
dir := filepath.Base(filepath.Dir(p))
parent := filepath.Base(filepath.Dir(filepath.Dir(p)))
gparent := filepath.Base(filepath.Dir(filepath.Dir(filepath.Dir(p))))

// Delete the directory if it is a repo or package in a repo
if dir != "vendor" && parent != "vendor" && !(gparent == "vendor" && parent == "github.com") {
os.RemoveAll(filepath.Dir(p))
}
}
}
}

func RunGlideInstall(cmd *cobra.Command, args []string) {
createGlide()
if !Update {
createGlide()
}
if fetch {
fetchGlide()
} else {
copyGlide()
CopyGlide()
}
}

Expand Down
4 changes: 3 additions & 1 deletion cmd/apiserver-boot/boot/init_repo/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ func AddInitRepo(cmd *cobra.Command) {
repoCmd.Flags().StringVar(&copyright, "copyright", "boilerplate.go.txt", "Location of copyright boilerplate file.")
repoCmd.Flags().
BoolVar(&installDeps, "install-deps", true, "if true, install the vendored deps packaged with apiserver-boot.")
repoCmd.Flags().
BoolVar(&Update, "update", false, "if true, don't touch glide.yaml or glide.lock, and replace versions of packages managed by apiserver-boot.")
repoCmd.Flags().MarkHidden("install-deps")
}

Expand All @@ -68,7 +70,7 @@ func RunInitRepo(cmd *cobra.Command, args []string) {

if installDeps {
log.Printf("installing godeps. To disable this, run with --install-deps=false.")
copyGlide()
CopyGlide()
}
}

Expand Down
16 changes: 16 additions & 0 deletions cmd/apiserver-boot/boot/update/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library")

go_library(
name = "go_default_library",
srcs = [
"update.go",
"vendor.go",
],
importpath = "github.com/kubernetes-incubator/apiserver-builder/cmd/apiserver-boot/boot/update",
visibility = ["//visibility:public"],
deps = [
"//cmd/apiserver-boot/boot/init_repo:go_default_library",
"//vendor/github.com/emicklei/go-restful/log:go_default_library",
"//vendor/github.com/spf13/cobra:go_default_library",
],
)
41 changes: 41 additions & 0 deletions cmd/apiserver-boot/boot/update/update.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
Copyright 2017 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package update

import (
"github.com/spf13/cobra"
)

var updateCmd = &cobra.Command{
Use: "update",
Short: "Command group for updating the apiserver-builder version.",
Long: `Command group for updating the apiserver-builder version.`,
Example: `
# Update the vendored dependencies under vendor/
apiserver-boot update vendor
`,
Run: RunUpdate,
}

func AddUpdate(cmd *cobra.Command) {
cmd.AddCommand(updateCmd)
AddUpdateVendorCmd(updateCmd)
}

func RunUpdate(cmd *cobra.Command, args []string) {
cmd.Help()
}
44 changes: 44 additions & 0 deletions cmd/apiserver-boot/boot/update/vendor.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
Copyright 2017 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package update

import (
"github.com/spf13/cobra"

"github.com/emicklei/go-restful/log"
"github.com/kubernetes-incubator/apiserver-builder/cmd/apiserver-boot/boot/init_repo"
)

var vendorCmd = &cobra.Command{
Use: "vendor",
Short: "Update the vendor packages managed by apiserver-builder.",
Long: `Update the vendor packages managed by apiserver-builder.`,
Example: `# Replace the vendor packages managed by apiserver-builder with versions for the current install.
apiserver-boot update vendor
`,
Run: RunUpdateVendor,
}

func AddUpdateVendorCmd(cmd *cobra.Command) {
cmd.AddCommand(vendorCmd)
}

func RunUpdateVendor(cmd *cobra.Command, args []string) {
init_repo.Update = true
log.Printf("Replacing vendored libraries managed by apiserver-builder with the current version.")
init_repo.CopyGlide()
}
9 changes: 9 additions & 0 deletions cmd/apiserver-boot/boot/version/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library")

go_library(
name = "go_default_library",
srcs = ["version.go"],
importpath = "github.com/kubernetes-incubator/apiserver-builder/cmd/apiserver-boot/boot/version",
visibility = ["//visibility:public"],
deps = ["//cmd/vendor/github.com/spf13/cobra:go_default_library"],
)
Loading

0 comments on commit 4c733dd

Please sign in to comment.