Start collecting assets

This commit is contained in:
Justin Santa Barbara 2017-06-17 13:34:27 -04:00
parent 9a8fcd64e4
commit 973492b678
5 changed files with 34 additions and 6 deletions

View File

@ -10,6 +10,12 @@ import (
// AssetBuilder discovers and remaps assets
type AssetBuilder struct {
Assets []*Asset
}
type Asset struct {
Origin string
Mirror string
}
func NewAssetBuilder() *AssetBuilder {
@ -39,6 +45,10 @@ func (a *AssetBuilder) RemapManifest(data []byte) ([]byte, error) {
}
func (a *AssetBuilder) remapImage(image string) (string, error) {
asset := &Asset{}
asset.Origin = image
if strings.HasPrefix(image, "kope/dns-controller:") {
// To use user-defined DNS Controller:
// 1. DOCKER_REGISTRY=[your docker hub repo] make dns-controller-push
@ -46,9 +56,13 @@ func (a *AssetBuilder) remapImage(image string) (string, error) {
// 3. make kops and create/apply cluster
override := os.Getenv("DNSCONTROLLER_IMAGE")
if override != "" {
return override, nil
image = override
}
}
asset.Mirror = image
a.Assets = append(a.Assets, asset)
return image, nil
}

View File

@ -1,4 +1,4 @@
package assets
package templates
import (
"bytes"

View File

@ -53,6 +53,7 @@ import (
"k8s.io/kops/upup/pkg/fi/fitasks"
"k8s.io/kops/util/pkg/hashing"
"k8s.io/kops/util/pkg/vfs"
"k8s.io/kops/pkg/templates"
)
const DefaultMaxTaskDuration = 10 * time.Minute
@ -429,7 +430,7 @@ func (c *ApplyClusterCmd) Run() error {
// No proto code options; no file model
case "cloudup":
templates, err := assets.LoadTemplates(cluster, models.NewAssetPath("cloudup/resources"))
templates, err := templates.LoadTemplates(cluster, models.NewAssetPath("cloudup/resources"))
if err != nil {
return fmt.Errorf("error loading templates: %v", err)
}
@ -705,7 +706,7 @@ func (c *ApplyClusterCmd) Run() error {
shouldPrecreateDNS = false
case TargetDryRun:
target = fi.NewDryRunTarget(os.Stdout)
target = fi.NewDryRunTarget(assetBuilder, os.Stdout)
dryRun = true
// Avoid making changes on a dry-run

View File

@ -26,11 +26,12 @@ import (
"k8s.io/kops/upup/pkg/fi"
"k8s.io/kops/upup/pkg/fi/fitasks"
"k8s.io/kops/upup/pkg/fi/utils"
"k8s.io/kops/pkg/templates"
)
type BootstrapChannelBuilder struct {
cluster *kops.Cluster
templates *assets.Templates
templates *templates.Templates
assetBuilder *assets.AssetBuilder
}

View File

@ -28,6 +28,7 @@ import (
"k8s.io/kops/pkg/diff"
"k8s.io/kops/upup/pkg/fi/utils"
"sort"
"k8s.io/kops/pkg/assets"
)
// DryRunTarget is a special Target that does not execute anything, but instead tracks all changes.
@ -41,6 +42,9 @@ type DryRunTarget struct {
// The destination to which the final report will be printed on Finish()
out io.Writer
// assetBuilder records all assets used
assetBuilder *assets.AssetBuilder
}
type render struct {
@ -70,9 +74,10 @@ func (a DeletionByTaskName) Less(i, j int) bool {
var _ Target = &DryRunTarget{}
func NewDryRunTarget(out io.Writer) *DryRunTarget {
func NewDryRunTarget(assetBuilder *assets.AssetBuilder, out io.Writer) *DryRunTarget {
t := &DryRunTarget{}
t.out = out
t.assetBuilder = assetBuilder
return t
}
@ -309,6 +314,13 @@ func (t *DryRunTarget) PrintReport(taskMap map[string]Task, out io.Writer) error
}
}
if len(t.assetBuilder.Assets) != 0 {
fmt.Fprintf(b, "Assets:\n")
for _, a := range t.assetBuilder.Assets {
fmt.Fprintf(b, " %-20s %s\n", a.Origin, a.Mirror)
}
}
_, err := out.Write(b.Bytes())
return err
}