-
Notifications
You must be signed in to change notification settings - Fork 2k
Description
Describe the bug
We are using some managed fields to provide information on Deployment
objects on a custom dashboard. For this, we are getting a V1DeploymentList
, like so:
public V1DeploymentList getKubernetesDeploymentList(String context) throws ApiException {
KubeConfig kubeConfig = this.kubernetesConfiguration.getKubeConfig();
AppsV1Api appsApi = new AppsV1Api(this.getApiClient(context));
return appsApi.listNamespacedDeployment(kubeConfig.getNamespace())
.labelSelector("app.kubernetes.io/name=our-base-chart")
.execute();
}
From this, we iterate over the V1Deployment
s, converting them to our representation (class Deployment
):
public List<Deployment> getDeployments(String cluster) {
try {
V1DeploymentList deploymentList = this.getKubernetesDeploymentList(cluster);
List<Deployment> deployments = new ArrayList<>();
if (deploymentList != null) {
for (V1Deployment item : deploymentList.getItems()) {
deployments.add(DeploymentMapper.mapToDeployment(item));
}
}
return deployments;
} catch (ApiException e) {
log.error("Couldn't retrieve deployments.", e);
}
return Collections.emptyList();
}
To populate our object, we use:
public static Deployment mapToDeployment(V1Deployment v1deployment) {
Deployment deployment = new Deployment();
V1DeploymentSpec spec = Objects.requireNonNull(v1deployment.getSpec());
V1ObjectMeta metadata = Objects.requireNonNull(v1deployment.getMetadata());
List<V1ManagedFieldsEntry> managedFields = Objects.requireNonNull(metadata.getManagedFields());
log.debug("Managed Fields count: {}", managedFields.size());
String image = Objects.requireNonNull(spec.getTemplate().getSpec()).getContainers().get(0).getImage();
deployment.setName(metadata.getName());
deployment.setStatus(getDeploymentStatus(v1deployment));
deployment.setVersion(getVersionFromImage(image));
List<V1ManagedFieldsEntry> fleetFields = managedFields.stream()
.filter(field -> Objects.equals(field.getManager(), "fleetagent"))
.toList();
if (!fleetFields.isEmpty()) {
LocalDateTime lastUpdated = Objects.requireNonNull(fleetFields.getFirst().getTime()).atZoneSameInstant(ZoneId.systemDefault()).toLocalDateTime();
deployment.setLastUpdatedAt(lastUpdated.atZone(ZoneId.systemDefault()).toLocalDateTime());
}
deployment.setReplicas(spec.getReplicas());
return deployment;
}
Now, with client version 21.0.2
this works against Kubernetes 1.28.15 and 1.30.10. But with client version 22.0.0 onwards, this does not work anymore (against both Kubernetes versions), as the managed fields are empty, according to the log:
Managed Fields count: 3
vs
Managed Fields count: 0
As I couldn't find a changelog indicating this change in behavior, I'd assume this is unintentional. If it isn't, I'd find it very helpful if you could point me to the right location in the docs.
So far I have verified that the HTTP response from the API still contains the fields, and those are still present, when the JSON parsing occurs in https://github.com/kubernetes-client/java/blob/release-23/kubernetes/src/main/java/io/kubernetes/client/openapi/JSON.java#L791
Client Version
22.0.0
, but still the case in 23.0.0
. It worked in 21.0.2
.
Kubernetes Version
1.30.10
, but also v1.28.15
Java Version
Temurin Java 21
To Reproduce
- Get V1DeploymentList for specific namespace
- Try to get values from getMetadata().getManagedFields()
Expected behavior
I expect the managed fields to be populated just like in earlier releases.
Server:
- OS: Ubuntu Linux
- Platform: Rancher