Skip to content

Commit

Permalink
updating with original phase stuff for asset builder
Browse files Browse the repository at this point in the history
  • Loading branch information
chrislovecnm committed Nov 1, 2017
1 parent 8cc20ab commit 85af765
Show file tree
Hide file tree
Showing 18 changed files with 72 additions and 72 deletions.
2 changes: 1 addition & 1 deletion cmd/kops/create_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -965,7 +965,7 @@ func RunCreateCluster(f *util.Factory, out io.Writer, c *CreateClusterOptions) e
return err
}

assetBuilder := assets.NewAssetBuilder(cluster.Spec.Assets)
assetBuilder := assets.NewAssetBuilder(cluster.Spec.Assets, "")
fullCluster, err := cloudup.PopulateClusterSpec(clientset, cluster, assetBuilder)
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion cmd/kops/edit_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ func RunEditCluster(f *util.Factory, cmd *cobra.Command, args []string, out io.W
return preservedFile(fmt.Errorf("error populating configuration: %v", err), file, out)
}

assetBuilder := assets.NewAssetBuilder(newCluster.Spec.Assets)
assetBuilder := assets.NewAssetBuilder(newCluster.Spec.Assets, "")
fullCluster, err := cloudup.PopulateClusterSpec(clientset, newCluster, assetBuilder)
if err != nil {
results = editResults{
Expand Down
2 changes: 1 addition & 1 deletion cmd/kops/edit_instancegroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ func RunEditInstanceGroup(f *util.Factory, cmd *cobra.Command, args []string, ou
return fmt.Errorf("error populating configuration: %v", err)
}

assetBuilder := assets.NewAssetBuilder(cluster.Spec.Assets)
assetBuilder := assets.NewAssetBuilder(cluster.Spec.Assets, "")
fullCluster, err := cloudup.PopulateClusterSpec(clientset, cluster, assetBuilder)
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion cmd/kops/upgrade_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ func (c *UpgradeClusterCmd) Run(args []string) error {
return fmt.Errorf("error populating configuration: %v", err)
}

assetBuilder := assets.NewAssetBuilder(cluster.Spec.Assets)
assetBuilder := assets.NewAssetBuilder(cluster.Spec.Assets, "")
fullCluster, err := cloudup.PopulateClusterSpec(clientset, cluster, assetBuilder)
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion nodeup/pkg/model/protokube.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ func (t *ProtokubeBuilder) ProtokubeFlags(k8sVersion semver.Version) (*Protokube

// TODO this is dupicate code with etcd model
image := fmt.Sprintf("gcr.io/google_containers/etcd:%s", imageVersion)
assets := assets.NewAssetBuilder(t.Cluster.Spec.Assets)
assets := assets.NewAssetBuilder(t.Cluster.Spec.Assets, "")
remapped, err := assets.RemapImage(image)
if err != nil {
return nil, fmt.Errorf("unable to remap container %q: %v", image, err)
Expand Down
4 changes: 2 additions & 2 deletions pkg/assets/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@ type FileAsset struct {
}

// NewAssetBuilder creates a new AssetBuilder.
func NewAssetBuilder(assets *kops.Assets) *AssetBuilder {
func NewAssetBuilder(assets *kops.Assets, phase string) *AssetBuilder {
return &AssetBuilder{
AssetsLocation: assets,
Phase: "",
Phase: phase,
}
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/assets/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func TestRemap_File(t *testing.T) {

for _, g := range grid {
// TODO FIXME
builder := NewAssetBuilder(g.kopsAssets)
builder := NewAssetBuilder(g.kopsAssets, "")

actual, _, err := builder.RemapFileAndSHA(g.testFile, g.sha)
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions pkg/model/components/kubecontrollermanager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func buildCluster() *api.Cluster {

func Test_Build_KCM_Builder_Lower_Version(t *testing.T) {
versions := []string{"v1.4.0", "v1.4.7", "v1.5.0"}
b := assets.NewAssetBuilder(nil)
b := assets.NewAssetBuilder(nil, "")

for _, v := range versions {

Expand Down Expand Up @@ -73,7 +73,7 @@ func Test_Build_KCM_Builder_Lower_Version(t *testing.T) {

func Test_Build_KCM_Builder_High_Enough_Version(t *testing.T) {
versions := []string{"v1.4.8", "v1.5.2", "v1.9.0", "v2.4.0"}
b := assets.NewAssetBuilder(nil)
b := assets.NewAssetBuilder(nil, "")
for _, v := range versions {

c := buildCluster()
Expand Down Expand Up @@ -104,7 +104,7 @@ func Test_Build_KCM_Builder_Change_Duration(t *testing.T) {
c := buildCluster()
c.Spec.KubernetesVersion = "v1.5.2"

b := assets.NewAssetBuilder(nil)
b := assets.NewAssetBuilder(nil, "")
kcm := &KubeControllerManagerOptionsBuilder{
Context: &OptionsContext{
AssetBuilder: b,
Expand Down
2 changes: 1 addition & 1 deletion pkg/model/components/kubelet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func buildSpec() *kops.ClusterSpec {
}

func buildOptions(spec *kops.ClusterSpec) error {
ab := assets.NewAssetBuilder(nil)
ab := assets.NewAssetBuilder(nil, "")

ver, err := KubernetesVersion(spec)
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions pkg/model/components/kubescheduler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func buildSchedulerConfigMapCluster() *api.Cluster {

func Test_Build_Scheduler_Without_PolicyConfigMap(t *testing.T) {
versions := []string{"v1.6.0", "v1.6.4", "v1.7.0", "v1.7.4"}
b := assets.NewAssetBuilder(nil)
b := assets.NewAssetBuilder(nil, "")

for _, v := range versions {

Expand Down Expand Up @@ -72,7 +72,7 @@ func Test_Build_Scheduler_Without_PolicyConfigMap(t *testing.T) {
}
func Test_Build_Scheduler_PolicyConfigMap_Unsupported_Version(t *testing.T) {
versions := []string{"v1.6.0", "v1.6.4"}
b := assets.NewAssetBuilder(nil)
b := assets.NewAssetBuilder(nil, "")

for _, v := range versions {

Expand Down Expand Up @@ -105,7 +105,7 @@ func Test_Build_Scheduler_PolicyConfigMap_Unsupported_Version(t *testing.T) {

func Test_Build_Scheduler_PolicyConfigMap_Supported_Version(t *testing.T) {
versions := []string{"v1.7.0", "v1.7.4", "v1.8.0"}
b := assets.NewAssetBuilder(nil)
b := assets.NewAssetBuilder(nil, "")

for _, v := range versions {

Expand Down
94 changes: 47 additions & 47 deletions upup/pkg/fi/cloudup/apply_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,53 @@ func (c *ApplyClusterCmd) Run() error {
}
c.channel = channel

stageAssetsLifecycle := fi.LifecycleSync
securityLifecycle := fi.LifecycleSync
networkLifecycle := fi.LifecycleSync
clusterLifecycle := fi.LifecycleSync

switch c.Phase {
case Phase(""):
// Everything ... the default
case PhaseStageAssets:
networkLifecycle = fi.LifecycleIgnore
securityLifecycle = fi.LifecycleIgnore
clusterLifecycle = fi.LifecycleIgnore

case PhaseNetwork:
stageAssetsLifecycle = fi.LifecycleIgnore
securityLifecycle = fi.LifecycleIgnore
clusterLifecycle = fi.LifecycleIgnore

case PhaseSecurity:
stageAssetsLifecycle = fi.LifecycleIgnore
networkLifecycle = fi.LifecycleIgnore
clusterLifecycle = fi.LifecycleIgnore

case PhaseCluster:
if c.TargetName == TargetDryRun {
stageAssetsLifecycle = fi.LifecycleExistsAndWarnIfChanges
securityLifecycle = fi.LifecycleExistsAndWarnIfChanges
networkLifecycle = fi.LifecycleExistsAndWarnIfChanges
} else {
stageAssetsLifecycle = fi.LifecycleIgnore
networkLifecycle = fi.LifecycleExistsAndValidates
securityLifecycle = fi.LifecycleExistsAndValidates
}

default:
return fmt.Errorf("unknown phase %q", c.Phase)
}

// FIXME this is an ugly hack. Need to move lifecycles out of phases
life := stageAssetsLifecycle
phase := string(life)
assetBuilder := assets.NewAssetBuilder(c.Cluster.Spec.Assets, phase)
err = c.upgradeSpecs(assetBuilder)
if err != nil {
return err
}

err = c.validateKopsVersion()
if err != nil {
return err
Expand Down Expand Up @@ -213,53 +260,6 @@ func (c *ApplyClusterCmd) Run() error {
cluster.Spec.KubernetesVersion = versionWithoutV
}

stageAssetsLifecycle := fi.LifecycleSync
securityLifecycle := fi.LifecycleSync
networkLifecycle := fi.LifecycleSync
clusterLifecycle := fi.LifecycleSync

switch c.Phase {
case Phase(""):
// Everything ... the default
case PhaseStageAssets:
networkLifecycle = fi.LifecycleIgnore
securityLifecycle = fi.LifecycleIgnore
clusterLifecycle = fi.LifecycleIgnore

case PhaseNetwork:
stageAssetsLifecycle = fi.LifecycleIgnore
securityLifecycle = fi.LifecycleIgnore
clusterLifecycle = fi.LifecycleIgnore

case PhaseSecurity:
stageAssetsLifecycle = fi.LifecycleIgnore
networkLifecycle = fi.LifecycleIgnore
clusterLifecycle = fi.LifecycleIgnore

case PhaseCluster:
if c.TargetName == TargetDryRun {
stageAssetsLifecycle = fi.LifecycleExistsAndWarnIfChanges
securityLifecycle = fi.LifecycleExistsAndWarnIfChanges
networkLifecycle = fi.LifecycleExistsAndWarnIfChanges
} else {
stageAssetsLifecycle = fi.LifecycleIgnore
networkLifecycle = fi.LifecycleExistsAndValidates
securityLifecycle = fi.LifecycleExistsAndValidates
}

default:
return fmt.Errorf("unknown phase %q", c.Phase)
}

// FIXME this is an ugly hack. Need to move lifecycles out of phases
//life := stageAssetsLifecycle
////phase := string(life)
assetBuilder := assets.NewAssetBuilder(c.Cluster.Spec.Assets)
err = c.upgradeSpecs(assetBuilder)
if err != nil {
return err
}

// TODO refactor this into a loop. This is 80 lines of code that can easily be a loop
// TODO that loops over strings like "/bin/linux/amd64/kubelet"
if len(c.Assets) == 0 {
Expand Down
2 changes: 1 addition & 1 deletion upup/pkg/fi/cloudup/awstasks/elastic_ip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func TestElasticIPCreate(t *testing.T) {
}

func checkNoChanges(t *testing.T, cloud fi.Cloud, allTasks map[string]fi.Task) {
assetBuilder := assets.NewAssetBuilder(nil)
assetBuilder := assets.NewAssetBuilder(nil, "")
target := fi.NewDryRunTarget(assetBuilder, os.Stderr)
context, err := fi.NewContext(target, nil, cloud, nil, nil, nil, true, allTasks)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions upup/pkg/fi/cloudup/awstasks/subnet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func TestSubnetCreate(t *testing.T) {
Cloud: cloud,
}

context, err := fi.NewContext(target, cloud, nil, nil, nil, true, allTasks)
context, err := fi.NewContext(target, nil, cloud, nil, nil, nil, true, allTasks)
if err != nil {
t.Fatalf("error building context: %v", err)
}
Expand Down Expand Up @@ -214,7 +214,7 @@ func TestSharedSubnetCreateDoesNotCreateNew(t *testing.T) {
Cloud: cloud,
}

context, err := fi.NewContext(target, cloud, nil, nil, nil, true, allTasks)
context, err := fi.NewContext(target, nil, cloud, nil, nil, nil, true, allTasks)
if err != nil {
t.Fatalf("error building context: %v", err)
}
Expand Down
2 changes: 1 addition & 1 deletion upup/pkg/fi/cloudup/bootstrapchannelbuilder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func runChannelBuilderTest(t *testing.T, key string) {
bcb := BootstrapChannelBuilder{
cluster: cluster,
templates: templates,
assetBuilder: assets.NewAssetBuilder(nil),
assetBuilder: assets.NewAssetBuilder(nil, ""),
}

context := &fi.ModelBuilderContext{
Expand Down
6 changes: 3 additions & 3 deletions upup/pkg/fi/cloudup/networking_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func Test_FindCNIAssetFromEnvironmentVariable(t *testing.T) {
}()

cluster := &api.Cluster{}
assetBuilder := assets.NewAssetBuilder(nil)
assetBuilder := assets.NewAssetBuilder(nil, "")
cniAsset, cniAssetHashString, err := findCNIAssets(cluster, assetBuilder)

if err != nil {
Expand All @@ -53,7 +53,7 @@ func Test_FindCNIAssetDefaultValue1_6(t *testing.T) {

cluster := &api.Cluster{Spec: api.ClusterSpec{}}
cluster.Spec.KubernetesVersion = "v1.7.0"
assetBuilder := assets.NewAssetBuilder(nil)
assetBuilder := assets.NewAssetBuilder(nil, "")
cniAsset, cniAssetHashString, err := findCNIAssets(cluster, assetBuilder)

if err != nil {
Expand All @@ -74,7 +74,7 @@ func Test_FindCNIAssetDefaultValue1_5(t *testing.T) {

cluster := &api.Cluster{Spec: api.ClusterSpec{}}
cluster.Spec.KubernetesVersion = "v1.5.12"
assetBuilder := assets.NewAssetBuilder(nil)
assetBuilder := assets.NewAssetBuilder(nil, "")
cniAsset, cniAssetHashString, err := findCNIAssets(cluster, assetBuilder)

if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion upup/pkg/fi/cloudup/populatecluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func TestPopulateCluster_Default_NoError(t *testing.T) {
func mockedPopulateClusterSpec(c *api.Cluster) (*api.Cluster, error) {
vfs.Context.ResetMemfsContext(true)

assetBuilder := assets.NewAssetBuilder(nil)
assetBuilder := assets.NewAssetBuilder(nil, "")
basePath, err := vfs.Context.BuildVfsPath("memfs://tests")
if err != nil {
return nil, fmt.Errorf("error building vfspath: %v", err)
Expand Down
2 changes: 1 addition & 1 deletion upup/pkg/fi/nodeup/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ func (c *NodeUpCommand) Run(out io.Writer) error {
Tags: nodeTags,
}
case "dryrun":
assetBuilder := assets.NewAssetBuilder(c.cluster.Spec.Assets)
assetBuilder := assets.NewAssetBuilder(c.cluster.Spec.Assets, "")
target = fi.NewDryRunTarget(assetBuilder, out)
case "cloudinit":
checkExisting = false
Expand Down
2 changes: 1 addition & 1 deletion upup/pkg/kutil/convert_kubeup_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func (x *ConvertKubeupCluster) Upgrade() error {
delete(cluster.ObjectMeta.Annotations, api.AnnotationNameManagement)
}

assetBuilder := assets.NewAssetBuilder(cluster.Spec.Assets)
assetBuilder := assets.NewAssetBuilder(cluster.Spec.Assets, "")
fullCluster, err := cloudup.PopulateClusterSpec(x.Clientset, cluster, assetBuilder)
if err != nil {
return err
Expand Down

0 comments on commit 85af765

Please sign in to comment.