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

feat(AdditionnalRef): implement multi ref #6

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.List;


@Data
Expand All @@ -15,6 +16,7 @@
@ApiModel(description = "GitHubDeployment spec part.")
public class GitHubDeploymentSpec {
private NamespacedObject sourceRef;
private List<NamespacedObject> additionnalRef;
private ExtractRule extract;
private RepositoryDetail repository;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package com.decathlon.github.kubernetesstatus.service;

import com.decathlon.github.kubernetesstatus.model.v1beta1.GitHubDeployment;
import com.decathlon.github.kubernetesstatus.model.v1beta1.GitHubDeploymentSpec;
import com.decathlon.github.kubernetesstatus.model.v1beta1.GitHubDeploymentStatus;
import com.decathlon.github.kubernetesstatus.service.kstatus.Status;
import com.decathlon.github.kubernetesstatus.service.kstatus.data.KubeObjectResult;
import com.decathlon.github.kubernetesstatus.service.kstatus.data.KubeObjectStatus;
import com.decathlon.github.kubernetesstatus.service.kubernetes.DynamicObjectExtractor;
import com.decathlon.github.kubernetesstatus.service.kubernetes.EventManager;
import com.google.gson.JsonArray;
Expand All @@ -18,9 +20,7 @@
import org.apache.logging.log4j.util.Strings;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.HashMap;
import java.util.Objects;
import java.util.*;
import java.util.regex.Pattern;

@Service
Expand All @@ -35,26 +35,41 @@ public class CaptureService {


public void capture(GitHubDeployment deployment) {
List<DynamicKubernetesObject> dynamicKubernetesObjects = new ArrayList<>();
KubeObjectResult status = null;


log.debug("[{}/{}] Observing GitHub Deployment", deployment.getMetadata().getNamespace(), deployment.getMetadata().getName());

var kobj=dynamicObjectExtractor.extractKubeObject(deployment.getSpec().getSourceRef());
if (kobj==null) {
dynamicKubernetesObjects.add(dynamicObjectExtractor.extractKubeObject(deployment.getSpec().getSourceRef()));
if (dynamicKubernetesObjects.isEmpty() || dynamicKubernetesObjects.get(0) ==null) {
return;
}

log.info("[{}/{}] Will check {}/{} kubernetes object", deployment.getMetadata().getNamespace(), deployment.getMetadata().getName(), kobj.getMetadata().getNamespace(), kobj.getMetadata().getName());
for(GitHubDeploymentSpec.NamespacedObject namespacedObject : deployment.getSpec().getAdditionnalRef()) {
dynamicKubernetesObjects.add(dynamicObjectExtractor.extractKubeObject(namespacedObject));
}

var ref=extractRef(deployment, kobj);
for(DynamicKubernetesObject dynamicKubernetesObject : dynamicKubernetesObjects) {
log.info("[{}/{}] Will check {}/{} kubernetes object", deployment.getMetadata().getNamespace(), deployment.getMetadata().getName(), dynamicKubernetesObject.getMetadata().getNamespace(), dynamicKubernetesObject.getMetadata().getName());
KubeObjectResult statusTemp = Status.compute(dynamicKubernetesObject);

if(status == null || status.status().canMoveTo(statusTemp.status())) {
status = statusTemp;
}
if(status.status().compareTo(KubeObjectStatus.CURRENT) != 0 ) break;
}


var ref=extractRef(deployment, dynamicKubernetesObjects.get(0));
if (ref==null){
log.warn("[{}/{}] Cannot extract ref from kube object with extract rule {}", deployment.getMetadata().getNamespace(), deployment.getMetadata().getName(), deployment.getSpec().getExtract());
return;
}

var status=Status.compute(kobj);

log.info("[{}/{}] ref found is {}, computed status is {}", deployment.getMetadata().getNamespace(), deployment.getMetadata().getName(), ref, status);

updateGhd(deployment, kobj.getMetadata(), status, ref);
updateGhd(deployment, dynamicKubernetesObjects.get(0).getMetadata(), status, ref);
}

private void updateGhd(GitHubDeployment deployment, V1ObjectMeta metadata, KubeObjectResult status, String ref) {
Expand Down