-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(provider/kubernetes): v2 cache & surface events per-resource (#2464
- Loading branch information
Showing
5 changed files
with
162 additions
and
0 deletions.
There are no files selected for viewing
90 changes: 90 additions & 0 deletions
90
...etflix/spinnaker/clouddriver/kubernetes/v2/caching/agent/KubernetesEventCachingAgent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/* | ||
* Copyright 2018 Google, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
|
||
package com.netflix.spinnaker.clouddriver.kubernetes.v2.caching.agent; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.netflix.spectator.api.Registry; | ||
import com.netflix.spinnaker.cats.agent.AgentDataType; | ||
import com.netflix.spinnaker.clouddriver.kubernetes.security.KubernetesNamedAccountCredentials; | ||
import com.netflix.spinnaker.clouddriver.kubernetes.v2.description.manifest.KubernetesApiVersion; | ||
import com.netflix.spinnaker.clouddriver.kubernetes.v2.description.manifest.KubernetesKind; | ||
import com.netflix.spinnaker.clouddriver.kubernetes.v2.description.manifest.KubernetesManifest; | ||
import com.netflix.spinnaker.clouddriver.kubernetes.v2.security.KubernetesV2Credentials; | ||
import io.kubernetes.client.models.V1Event; | ||
import io.kubernetes.client.models.V1ObjectReference; | ||
import lombok.Getter; | ||
import org.apache.commons.lang3.tuple.ImmutablePair; | ||
|
||
import java.util.Arrays; | ||
import java.util.Collection; | ||
import java.util.Collections; | ||
import java.util.HashMap; | ||
import java.util.HashSet; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.stream.Collectors; | ||
|
||
import static com.netflix.spinnaker.cats.agent.AgentDataType.Authority.AUTHORITATIVE; | ||
|
||
public class KubernetesEventCachingAgent extends KubernetesV2CachingAgent { | ||
KubernetesEventCachingAgent(KubernetesNamedAccountCredentials<KubernetesV2Credentials> namedAccountCredentials, | ||
ObjectMapper objectMapper, | ||
Registry registry, | ||
int agentIndex, | ||
int agentCount) { | ||
super(namedAccountCredentials, objectMapper, registry, agentIndex, agentCount); | ||
} | ||
|
||
@Getter | ||
final private Collection<AgentDataType> providedDataTypes = Collections.unmodifiableSet( | ||
new HashSet<>(Arrays.asList( | ||
AUTHORITATIVE.forType(KubernetesKind.EVENT.toString()) | ||
)) | ||
); | ||
|
||
@Override | ||
protected boolean hasClusterRelationship() { | ||
return false; | ||
} | ||
|
||
@Override | ||
protected KubernetesKind primaryKind() { | ||
return KubernetesKind.EVENT; | ||
} | ||
|
||
@Override | ||
protected Map<KubernetesManifest, List<KubernetesManifest>> loadSecondaryResourceRelationships(List<KubernetesManifest> primaryResourceList) { | ||
Map<KubernetesManifest, List<KubernetesManifest>> result = primaryResourceList.stream() | ||
.map(m -> ImmutablePair.of(m, KubernetesCacheDataConverter.getResource(m, V1Event.class))) | ||
.collect(Collectors.toMap(ImmutablePair::getLeft, p -> Collections.singletonList(involvedManifest(p.getRight())))); | ||
|
||
return result; | ||
} | ||
|
||
private KubernetesManifest involvedManifest(V1Event event) { | ||
V1ObjectReference ref = event.getInvolvedObject(); | ||
KubernetesManifest result = new KubernetesManifest(); | ||
result.put("metadata", new HashMap<String, Object>()); | ||
|
||
result.setApiVersion(KubernetesApiVersion.fromString(ref.getApiVersion())); | ||
result.setKind(KubernetesKind.fromString(ref.getKind())); | ||
result.setNamespace(ref.getNamespace()); | ||
result.setName(ref.getName()); | ||
return result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
...vy/com/netflix/spinnaker/clouddriver/kubernetes/v2/op/handler/KubernetesEventHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* Copyright 2018 Google, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
|
||
package com.netflix.spinnaker.clouddriver.kubernetes.v2.op.handler; | ||
|
||
import com.netflix.spinnaker.clouddriver.kubernetes.v2.caching.agent.KubernetesEventCachingAgent; | ||
import com.netflix.spinnaker.clouddriver.kubernetes.v2.caching.agent.KubernetesV2CachingAgent; | ||
import com.netflix.spinnaker.clouddriver.kubernetes.v2.description.KubernetesSpinnakerKindMap; | ||
import com.netflix.spinnaker.clouddriver.kubernetes.v2.description.manifest.KubernetesKind; | ||
import com.netflix.spinnaker.clouddriver.kubernetes.v2.description.manifest.KubernetesManifest; | ||
import com.netflix.spinnaker.clouddriver.model.Manifest; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class KubernetesEventHandler extends KubernetesHandler { | ||
@Override | ||
public KubernetesKind kind() { | ||
return KubernetesKind.EVENT; | ||
} | ||
|
||
@Override | ||
public boolean versioned() { | ||
return false; | ||
} | ||
|
||
@Override | ||
public KubernetesSpinnakerKindMap.SpinnakerKind spinnakerKind() { | ||
return KubernetesSpinnakerKindMap.SpinnakerKind.UNCLASSIFIED; | ||
} | ||
|
||
@Override | ||
public Manifest.Status status(KubernetesManifest manifest) { | ||
return new Manifest.Status(); | ||
} | ||
|
||
@Override | ||
public Class<? extends KubernetesV2CachingAgent> cachingAgentClass() { | ||
return KubernetesEventCachingAgent.class; | ||
} | ||
} |