Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(aws): Fix bug in AWS provider after Groovy 3 upgrade (backport #6142) #6143

Merged
merged 1 commit into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ class AmazonApplicationLoadBalancerCachingAgent extends AbstractAmazonLoadBalanc

@Override
Optional<Map<String, String>> getCacheKeyPatterns() {
return [
return Optional.of([
(LOAD_BALANCERS.ns): Keys.getLoadBalancerKey('*', account.name, region, 'vpc-????????', '*')
]
])
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@
package com.netflix.spinnaker.clouddriver.aws.provider.agent

import com.amazonaws.services.elasticloadbalancing.AmazonElasticLoadBalancing
import com.amazonaws.services.elasticloadbalancing.model.*
import com.amazonaws.services.elasticloadbalancing.model.DescribeLoadBalancerAttributesRequest
import com.amazonaws.services.elasticloadbalancing.model.DescribeLoadBalancersRequest
import com.amazonaws.services.elasticloadbalancing.model.DescribeTagsRequest
import com.amazonaws.services.elasticloadbalancing.model.LoadBalancerAttributes
import com.amazonaws.services.elasticloadbalancing.model.LoadBalancerDescription
import com.amazonaws.services.elasticloadbalancing.model.LoadBalancerNotFoundException
import com.fasterxml.jackson.core.type.TypeReference
import com.fasterxml.jackson.databind.ObjectMapper
import com.netflix.spectator.api.Registry
Expand All @@ -32,9 +37,10 @@ import com.netflix.spinnaker.clouddriver.aws.edda.EddaApi
import com.netflix.spinnaker.clouddriver.aws.security.AmazonClientProvider
import com.netflix.spinnaker.clouddriver.aws.security.NetflixAmazonCredentials
import com.netflix.spinnaker.clouddriver.cache.OnDemandAgent
import com.netflix.spinnaker.clouddriver.model.LoadBalancer

import static com.netflix.spinnaker.clouddriver.core.provider.agent.Namespace.*
import static com.netflix.spinnaker.clouddriver.core.provider.agent.Namespace.INSTANCES
import static com.netflix.spinnaker.clouddriver.core.provider.agent.Namespace.LOAD_BALANCERS
import static com.netflix.spinnaker.clouddriver.core.provider.agent.Namespace.ON_DEMAND

class AmazonLoadBalancerCachingAgent extends AbstractAmazonLoadBalancerCachingAgent {

Expand All @@ -55,9 +61,9 @@ class AmazonLoadBalancerCachingAgent extends AbstractAmazonLoadBalancerCachingAg

@Override
Optional<Map<String, String>> getCacheKeyPatterns() {
return [
return Optional.of([
(LOAD_BALANCERS.ns): Keys.getLoadBalancerKey('*', account.name, region, 'vpc-????????', null)
]
])
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,9 @@ class ClusterCachingAgent implements CachingAgent, OnDemandAgent, AccountAware,

@Override
Optional<Map<String, String>> getCacheKeyPatterns() {
return [
return Optional.of([
(SERVER_GROUPS.ns): Keys.getServerGroupKey('*', '*', account.name, region)
]
])
}

static class AmazonClients {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,20 @@ class AmazonApplicationLoadBalancerCachingAgentSpec extends Specification {
[taggify(".*", "ciao")] | [taggify("hello", ".*")] | buildCacheKeys([])
}

void "should get correct cache key pattern"() {
given:
def agent = getAgent()

when:
def cacheKeyPatterns = agent.getCacheKeyPatterns()

then:
cacheKeyPatterns.isPresent()
cacheKeyPatterns.get() == [
loadBalancers: buildCacheKey("*:vpc-????????:*")
]
}

private static final Map<LoadBalancer, List<TagDescription>> filterableLBs() {
return [
(new LoadBalancer().withLoadBalancerName("test-hello-tag-value").withLoadBalancerArn(buildELBArn("test-hello-tag-value"))) :
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,20 @@ class AmazonLoadBalancerCachingAgentSpec extends Specification {
[taggify(".*", "ciao")] | [taggify("hello", ".*")] | buildCacheKeys([])
}

void "should get correct cache key pattern"() {
given:
def agent = getAgent()

when:
def cacheKeyPatterns = agent.getCacheKeyPatterns()

then:
cacheKeyPatterns.isPresent()
cacheKeyPatterns.get() == [
loadBalancers: buildCacheKey("*:vpc-????????")
]
}

private static final Map<LoadBalancerDescription, List<TagDescription>> filterableLBs() {
return [
(new LoadBalancerDescription().withLoadBalancerName("test-hello-tag-value")):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,18 @@ class AmazonSecurityGroupCachingAgentSpec extends Specification {
cache.cacheResults[SECURITY_GROUPS.ns] == existingCacheData

}

void "should get correct cache key pattern"() {
given:
def agent = getAgent()

when:
def cacheKeyPatterns = agent.getCacheKeyPatterns()

then:
cacheKeyPatterns.isPresent()
cacheKeyPatterns.get() == [
(SECURITY_GROUPS.ns): "aws:securityGroups:*:*:region:account:*"
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ import spock.lang.Shared
import spock.lang.Specification
import spock.lang.Unroll

import static com.netflix.spinnaker.clouddriver.core.provider.agent.Namespace.SERVER_GROUPS

class ClusterCachingAgentSpec extends Specification {
static String region = 'region'
static String accountName = 'accountName'
Expand Down Expand Up @@ -216,6 +218,20 @@ class ClusterCachingAgentSpec extends Specification {
[taggify(".*", "ciao")] | [taggify("hello", ".*")] | []
}

void "should get correct cache key pattern"() {
given:
def agent = getAgent()

when:
def cacheKeyPatterns = agent.getCacheKeyPatterns()

then:
cacheKeyPatterns.isPresent()
cacheKeyPatterns.get() == [
(SERVER_GROUPS.ns): "aws:serverGroups:*:accountName:region:*"
]
}

private static final List<AutoScalingGroup> filterableASGs = [
new AutoScalingGroup()
.withAutoScalingGroupName("test-hello-tag-value")
Expand Down