Merge pull request #65 from justinsb/upup_fi_comparison

upup: Add back in CompareWithID functions
This commit is contained in:
Justin Santa Barbara 2016-06-07 15:39:51 -04:00
commit fd554601a8
11 changed files with 64 additions and 15 deletions

View File

@ -10,14 +10,8 @@ import (
"k8s.io/kube-deploy/upup/pkg/fi"
"k8s.io/kube-deploy/upup/pkg/fi/cloudup/awsup"
"strings"
"time"
)
func buildTimestampString() string {
now := time.Now()
return now.UTC().Format("20060102T150405Z")
}
// This one is a little weird because we can't update a launch configuration
// So we have to create the launch configuration as part of the group
//go:generate fitask -type=AutoscalingGroup
@ -157,7 +151,7 @@ func (e *AutoscalingGroup) buildTags(cloud fi.Cloud) map[string]string {
func (_ *AutoscalingGroup) RenderAWS(t *awsup.AWSAPITarget, a, e, changes *AutoscalingGroup) error {
if a == nil {
launchConfigurationName := *e.Name + "-" + buildTimestampString()
launchConfigurationName := *e.Name + "-" + fi.BuildTimestampString()
glog.V(2).Infof("Creating autoscaling LaunchConfiguration with Name:%q", launchConfigurationName)
err := renderAutoscalingLaunchConfigurationAWS(t, launchConfigurationName, e)
@ -196,7 +190,7 @@ func (_ *AutoscalingGroup) RenderAWS(t *awsup.AWSAPITarget, a, e, changes *Autos
}
} else {
if changes.UserData != nil {
launchConfigurationName := *e.Name + "-" + buildTimestampString()
launchConfigurationName := *e.Name + "-" + fi.BuildTimestampString()
glog.V(2).Infof("Creating autoscaling LaunchConfiguration with Name:%q", launchConfigurationName)
err := renderAutoscalingLaunchConfigurationAWS(t, launchConfigurationName, e)

View File

@ -19,6 +19,12 @@ type DHCPOptions struct {
DomainNameServers *string
}
var _ fi.CompareWithID = &DHCPOptions{}
func (e *DHCPOptions) CompareWithID() *string {
return e.ID
}
func (e *DHCPOptions) Find(c *fi.Context) (*DHCPOptions, error) {
cloud := c.Cloud.(*awsup.AWSCloud)

View File

@ -41,12 +41,14 @@ func (e *DNSName) Find(c *fi.Context) (*DNSName, error) {
err := cloud.Route53.ListResourceRecordSetsPages(request, func(p *route53.ListResourceRecordSetsOutput, lastPage bool) (shouldContinue bool) {
for _, rr := range p.ResourceRecordSets {
resourceType := aws.StringValue(rr.Type)
name := aws.StringValue(rr.Name)
glog.V(4).Infof("Found DNS resource %q %q", resourceType, name)
if findType != resourceType {
continue
}
name := aws.StringValue(rr.Name)
name = strings.TrimSuffix(name, ".")
if name == findName {
@ -92,6 +94,7 @@ func (s *DNSName) CheckChanges(a, e, changes *DNSName) error {
func (_ *DNSName) RenderAWS(t *awsup.AWSAPITarget, a, e, changes *DNSName) error {
rrs := &route53.ResourceRecordSet{
Name: e.Name,
Type: aws.String(e.ResourceType),
}
if e.TargetLoadBalancer != nil {
@ -100,7 +103,6 @@ func (_ *DNSName) RenderAWS(t *awsup.AWSAPITarget, a, e, changes *DNSName) error
EvaluateTargetHealth: aws.Bool(false),
HostedZoneId: e.TargetLoadBalancer.HostedZoneId,
}
rrs.Type = aws.String("A")
}
change := &route53.Change{

View File

@ -17,6 +17,12 @@ type DNSZone struct {
ID *string
}
var _ fi.CompareWithID = &DNSZone{}
func (e *DNSZone) CompareWithID() *string {
return e.Name
}
func (e *DNSZone) Find(c *fi.Context) (*DNSZone, error) {
cloud := c.Cloud.(*awsup.AWSCloud)

View File

@ -11,14 +11,20 @@ import (
//go:generate fitask -type=EBSVolume
type EBSVolume struct {
Name *string
ID *string
AvailabilityZone *string
VolumeType *string
SizeGB *int64
Name *string
Tags map[string]string
}
var _ fi.CompareWithID = &EBSVolume{}
func (e *EBSVolume) CompareWithID() *string {
return e.ID
}
type TaggableResource interface {
FindResourceID(c fi.Cloud) (*string, error)
}

View File

@ -12,8 +12,14 @@ import (
//go:generate fitask -type=IAMInstanceProfile
type IAMInstanceProfile struct {
ID *string
Name *string
ID *string
}
var _ fi.CompareWithID = &IAMInstanceProfile{}
func (e *IAMInstanceProfile) CompareWithID() *string {
return e.Name
}
func (e *IAMInstanceProfile) Find(c *fi.Context) (*IAMInstanceProfile, error) {

View File

@ -22,6 +22,12 @@ type IAMRole struct {
RolePolicyDocument *fi.ResourceHolder // "inline" IAM policy
}
var _ fi.CompareWithID = &IAMRole{}
func (e *IAMRole) CompareWithID() *string {
return e.ID
}
func (e *IAMRole) Find(c *fi.Context) (*IAMRole, error) {
cloud := c.Cloud.(*awsup.AWSCloud)

View File

@ -15,6 +15,12 @@ type InternetGateway struct {
ID *string
}
var _ fi.CompareWithID = &InternetGateway{}
func (e *InternetGateway) CompareWithID() *string {
return e.ID
}
func (e *InternetGateway) Find(c *fi.Context) (*InternetGateway, error) {
cloud := c.Cloud.(*awsup.AWSCloud)

View File

@ -16,6 +16,12 @@ type RouteTable struct {
VPC *VPC
}
var _ fi.CompareWithID = &RouteTable{}
func (e *RouteTable) CompareWithID() *string {
return e.ID
}
func (e *RouteTable) Find(c *fi.Context) (*RouteTable, error) {
cloud := c.Cloud.(*awsup.AWSCloud)

View File

@ -27,11 +27,15 @@ type SSHKey struct {
PublicKey *fi.ResourceHolder
ID *string
KeyFingerprint *string
}
var _ fi.CompareWithID = &SSHKey{}
func (e *SSHKey) CompareWithID() *string {
return e.Name
}
func (e *SSHKey) Find(c *fi.Context) (*SSHKey, error) {
cloud := c.Cloud.(*awsup.AWSCloud)
@ -61,7 +65,6 @@ func (e *SSHKey) Find(c *fi.Context) (*SSHKey, error) {
actual := &SSHKey{
Name: k.KeyName,
ID: k.KeyName,
KeyFingerprint: k.KeyFingerprint,
}

8
upup/pkg/fi/timestamp.go Normal file
View File

@ -0,0 +1,8 @@
package fi
import "time"
func BuildTimestampString() string {
now := time.Now()
return now.UTC().Format("20060102150405")
}