Spring Boot with Kubernetes Java Client API - Edit Namespace

Here is the EditNamespaceRequest shown below
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@JsonIgnoreProperties(ignoreUnknown = true)
public class EditNamespaceRequest {
private String name;
}
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@JsonIgnoreProperties(ignoreUnknown = true)
public class EditNamespaceRequest {
private String name;
}
Here is the updateNamespace method of my Service
public V1Namespace updateNamespace(String currentName, EditNamespaceRequest editNamespaceRequest) throws ApiException {

try {
// Retrieve the existing namespace
V1Namespace existingNamespace = coreV1Api.readNamespace(currentName, null);

// Update the existing namespace with the new values
existingNamespace.metadata(new V1ObjectMeta().name(editNamespaceRequest.getName()));

// Perform the update
coreV1Api.replaceNamespace(currentName, existingNamespace, null, null, null,null);

return existingNamespace;
} catch (ApiException e) {
// Handle API exception (e.g., namespace not found, permission issues, etc.)
throw new RuntimeException("Failed to update namespace: " + e.getResponseBody(), e);
}

}
public V1Namespace updateNamespace(String currentName, EditNamespaceRequest editNamespaceRequest) throws ApiException {

try {
// Retrieve the existing namespace
V1Namespace existingNamespace = coreV1Api.readNamespace(currentName, null);

// Update the existing namespace with the new values
existingNamespace.metadata(new V1ObjectMeta().name(editNamespaceRequest.getName()));

// Perform the update
coreV1Api.replaceNamespace(currentName, existingNamespace, null, null, null,null);

return existingNamespace;
} catch (ApiException e) {
// Handle API exception (e.g., namespace not found, permission issues, etc.)
throw new RuntimeException("Failed to update namespace: " + e.getResponseBody(), e);
}

}
I have a problem to update Namespace by name through Kubernetes Java Client API. this error message is shown below when I run
{"kind":"Status","apiVersion":"v1","metadata":{},"status":"Failure","message":"the name of the object (kupeteer-namespace-update) does not match the name on the URL (kupeteer-namespace-new)","reason":"BadRequest","code":400}
{"kind":"Status","apiVersion":"v1","metadata":{},"status":"Failure","message":"the name of the object (kupeteer-namespace-update) does not match the name on the URL (kupeteer-namespace-new)","reason":"BadRequest","code":400}
How can I fix it?
1 Reply
JavaBot
JavaBot12mo ago
This post has been reserved for your question.
Hey @direct_x_34! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here. 💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one. In case your post is not getting any attention, you can try to use /help ping. Warning: abusing this will result in moderative actions taken against you.
Want results from more Discord servers?
Add your server