Skip to content

Commit

Permalink
feat(google): Add support for labels. (#1501)
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt Duftler committed Mar 8, 2017
1 parent cf4d031 commit fde1339
Show file tree
Hide file tree
Showing 11 changed files with 28 additions and 0 deletions.
Expand Up @@ -30,6 +30,7 @@ class BaseGoogleInstanceDescription extends AbstractGoogleCredentialsDescription
List<GoogleDisk> disks
Map<String, String> instanceMetadata
List<String> tags
Map<String, String> labels
String network
String subnet
// This will be treated as true if it is null to preserve backwards-compatibility with existing pipelines.
Expand Down
Expand Up @@ -124,6 +124,7 @@ class BasicGoogleDeployHandler implements DeployHandler<BasicGoogleDeployDescrip
def region = description.region ?: credentials.regionFromZone(zone)
def location = isRegional ? region : zone
def instanceMetadata = description.instanceMetadata
def labels = description.labels

def serverGroupNameResolver = new GCEServerGroupNameResolver(project, region, credentials, safeRetry, this)
def clusterName = serverGroupNameResolver.combineAppStackDetail(description.application, description.stack, description.freeFormDetails)
Expand Down Expand Up @@ -308,6 +309,7 @@ class BasicGoogleDeployHandler implements DeployHandler<BasicGoogleDeployDescrip
networkInterfaces: [networkInterface],
metadata: metadata,
tags: tags,
labels: labels,
scheduling: scheduling,
serviceAccounts: serviceAccount)

Expand Down
Expand Up @@ -163,6 +163,12 @@ class CopyLastGoogleServerGroupAtomicOperation extends GoogleAtomicOperation<Dep
newDescription.tags = description.tags != null ? description.tags : tags.items
}

def labels = ancestorInstanceProperties.labels

if (labels != null) {
newDescription.labels = description.labels != null ? description.labels : labels
}

def scheduling = ancestorInstanceProperties.scheduling

if (scheduling) {
Expand Down
Expand Up @@ -131,6 +131,7 @@ class CreateGoogleInstanceAtomicOperation extends GoogleAtomicOperation<Deployme
networkInterfaces: [networkInterface],
metadata: metadata,
tags: tags,
labels: description.labels,
scheduling: scheduling,
serviceAccounts: serviceAccount)

Expand Down
Expand Up @@ -205,6 +205,11 @@ class ModifyGoogleServerGroupInstanceTemplateAtomicOperation extends GoogleAtomi
instanceTemplateProperties.setTags(tags)
}

// Override the instance template's labels if labels was specified.
if (overriddenProperties.labels) {
instanceTemplateProperties.setLabels(description.labels)
}

// Override the instance template's service account if serviceAccountEmail or authScopes was specified.
// Note that we want to explicitly allow for either the service account or auth scopes to be empty, but non-null.
if (overriddenProperties.serviceAccountEmail != null || overriddenProperties.authScopes != null) {
Expand Down
Expand Up @@ -53,6 +53,7 @@ class GoogleInstance {
List<ServiceAccount> serviceAccounts
String selfLink
Tags tags
Map<String, String> labels

// Non-serialized values built up by providers
@JsonIgnore
Expand Down Expand Up @@ -90,6 +91,7 @@ class GoogleInstance {
String selfLink = GoogleInstance.this.selfLink
String serverGroup = GoogleInstance.this.serverGroup
Tags tags = GoogleInstance.this.tags
Map<String, String> labels = GoogleInstance.this.labels
ConsulNode consulNode = GoogleInstance.this.consulNode

List<Map<String, String>> getSecurityGroups() {
Expand Down
Expand Up @@ -48,6 +48,7 @@ class GoogleServerGroup {
Boolean discovery = false
String networkName
Set<String> instanceTemplateTags = []
Map<String, String> instanceTemplateLabels = [:]
String selfLink
InstanceGroupManagerActionsSummary currentActions

Expand Down Expand Up @@ -92,6 +93,7 @@ class GoogleServerGroup {
Boolean disabled = GoogleServerGroup.this.disabled
String networkName = GoogleServerGroup.this.networkName
Set<String> instanceTemplateTags = GoogleServerGroup.this.instanceTemplateTags
Map<String, String> instanceTemplateLabels = GoogleServerGroup.this.instanceTemplateLabels
String selfLink = GoogleServerGroup.this.selfLink
Boolean discovery = GoogleServerGroup.this.discovery
InstanceGroupManagerActionsSummary currentActions = GoogleServerGroup.this.currentActions
Expand Down
Expand Up @@ -114,6 +114,7 @@ class GoogleInstanceCachingAgent extends AbstractGoogleCachingAgent {
serviceAccounts: instance.serviceAccounts,
selfLink: instance.selfLink,
tags: instance.tags,
labels: instance.labels,
consulNode: consulNode,
instanceHealth: new GoogleInstanceHealth(
status: GoogleInstanceHealth.Status.valueOf(instance.getStatus())
Expand Down
Expand Up @@ -472,6 +472,7 @@ class GoogleRegionalServerGroupCachingAgent extends AbstractGoogleCachingAgent i
serverGroup.with {
networkName = Utils.getNetworkNameFromInstanceTemplate(instanceTemplate)
instanceTemplateTags = instanceTemplate?.properties?.tags?.items
instanceTemplateLabels = instanceTemplate?.properties?.labels
launchConfig.with {
launchConfigurationName = instanceTemplate?.name
instanceType = instanceTemplate?.properties?.machineType
Expand Down
Expand Up @@ -500,6 +500,7 @@ class GoogleZonalServerGroupCachingAgent extends AbstractGoogleCachingAgent impl
serverGroup.with {
networkName = Utils.getNetworkNameFromInstanceTemplate(instanceTemplate)
instanceTemplateTags = instanceTemplate?.properties?.tags?.items
instanceTemplateLabels = instanceTemplate?.properties?.labels
launchConfig.with {
launchConfigurationName = instanceTemplate?.name
instanceType = instanceTemplate?.properties?.machineType
Expand Down
Expand Up @@ -58,6 +58,9 @@ class CopyLastGoogleServerGroupAtomicOperationUnitSpec extends Specification {
private static final String HTTP_SERVER_TAG = "http-server"
private static final String HTTPS_SERVER_TAG = "https-server"
private static final List<String> TAGS = ["orig-tag-1", "orig-tag-2", HTTP_SERVER_TAG, HTTPS_SERVER_TAG]
private static final Map<String, String> LABELS =
["orig-label-key-1": "orig-label-value-1",
"orig-label-key-2": "orig-label-value-2"]
private static final String SERVICE_ACCOUNT_EMAIL = "default"
private static final List<String> AUTH_SCOPES = ["compute", "logging.write"]
private static final List<String> DECORATED_AUTH_SCOPES =
Expand Down Expand Up @@ -124,6 +127,7 @@ class CopyLastGoogleServerGroupAtomicOperationUnitSpec extends Specification {
networkInterfaces: [networkInterface],
metadata: instanceMetadata,
tags: tags,
labels: LABELS,
scheduling: scheduling,
serviceAccounts: serviceAccount)
instanceTemplate = new InstanceTemplate(name: INSTANCE_TEMPLATE_NAME,
Expand Down Expand Up @@ -155,6 +159,7 @@ class CopyLastGoogleServerGroupAtomicOperationUnitSpec extends Specification {
zone: ZONE,
instanceMetadata: ["differentKey": "differentValue"],
tags: ["new-tag-1", "new-tag-2"],
labels: ["new-label-key-1": "new-label-value-1"],
preemptible: true,
automaticRestart: false,
onHostMaintenance: BaseGoogleInstanceDescription.OnHostMaintenance.TERMINATE,
Expand Down Expand Up @@ -222,6 +227,7 @@ class CopyLastGoogleServerGroupAtomicOperationUnitSpec extends Specification {
newDescription.zone = ZONE
newDescription.instanceMetadata = INSTANCE_METADATA
newDescription.tags = TAGS
newDescription.labels = LABELS
newDescription.preemptible = false
newDescription.automaticRestart = true
newDescription.onHostMaintenance = BaseGoogleInstanceDescription.OnHostMaintenance.MIGRATE
Expand Down

0 comments on commit fde1339

Please sign in to comment.