send the status of the revision Using the aid of latest build number and latest deployment number, not the first in the queue
@@ -83,6 +83,7 @@ import io.fabric8.kubernetes.api.model.ObjectMeta;
import io.fabric8.kubernetes.api.model.Pod;
import io.fabric8.kubernetes.api.model.Quantity;
import io.fabric8.kubernetes.api.model.ReplicationController;
+import io.fabric8.kubernetes.api.model.ReplicationControllerList;
import io.fabric8.kubernetes.api.model.Secret;
import io.fabric8.kubernetes.api.model.SecretBuilder;
import io.fabric8.kubernetes.api.model.Service;
@@ -1382,13 +1383,48 @@ public class TeiidOpenShiftClient implements StringConstants {
}
}
+ private Build findBuildWithNumber(long number, BuildList buildList) {
+ for (Build b: buildList.getItems()) {
+ String buildNumber = b.getMetadata().getAnnotations().get("openshift.io/build.number");
+ if (buildNumber != null && Long.parseLong(buildNumber) == number) {
+ return b;
+ }
+ }
+ return buildList.getItems().get(0);
+ }
+
+ private long getDeployedRevision(DeploymentConfig dc, long defaultNumber, final OpenShiftClient client) {
+ long latestVersion = dc.getStatus().getLatestVersion().longValue();
+ ReplicationControllerList list = client.replicationControllers().inNamespace(dc.getMetadata().getNamespace())
+ .withLabel("application", dc.getMetadata().getName()).list();
+
+ for (ReplicationController rc : list.getItems()) {
+ String version = rc.getMetadata().getAnnotations().get("openshift.io/deployment-config.latest-version");
+ if (version != null && Long.parseLong(version) == latestVersion) {
+ String deployedVersion = rc.getSpec().getTemplate().getMetadata().getLabels().get(DEPLOYMENT_VERSION_LABEL);
+ if (deployedVersion != null) {
+ try {
+ return Long.parseLong(deployedVersion);
+ } catch (NumberFormatException e) {
+ LOGGER.error("unexpected value for deployment-version", e);
+ }
+ }
+ }
+ }
+ return defaultNumber;
+ }
private BuildStatus getVDBService(String openShiftName, String namespace, final OpenShiftClient client) {
BuildStatus status = new BuildStatus(openShiftName);
status.setNamespace(namespace);
+ long lastVersion = 1L;
+ BuildConfig bc = client.buildConfigs().inNamespace(namespace).withName(getBuildConfigName(openShiftName)).get();
+ if (bc != null) {
+ lastVersion = bc.getStatus().getLastVersion().longValue();
+ }
BuildList buildList = client.builds().inNamespace(namespace).withLabel("application", openShiftName).list();
if ((buildList !=null) && !buildList.getItems().isEmpty()) {
- Build build = buildList.getItems().get(0);
+ Build build = findBuildWithNumber(lastVersion, buildList);
status.setName(build.getMetadata().getName());
String deploymentVersion = build.getMetadata().getLabels().get(DEPLOYMENT_VERSION_LABEL);
if (deploymentVersion != null) {
@@ -1437,6 +1473,7 @@ public class TeiidOpenShiftClient implements StringConstants {
DeploymentCondition cond = getDeploymentConfigStatus(dc);
if (cond != null) {
status.setStatusMessage(cond.getMessage());
+ status.setDeploymentVersion(getDeployedRevision(dc, status.getDeploymentVersion(), client));
} else {
status.setStatusMessage("Available condition not found in deployment, delete the service and re-deploy?");
}
