Skip to content

Commit

Permalink
fix fabric8io#3745: checks the namespace for require operations
Browse files Browse the repository at this point in the history
  • Loading branch information
shawkins committed Jan 18, 2022
1 parent 28151ed commit 8b4696c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
* Fix #3679: output additionalProperties field with correct value type for map-like fields (CRD Generator)
* Fix #3648: `Serialization.unmarshal` fails to deserialize YAML with single document in presence of document delimiter(`---`)
* Fix #3568: Pod file upload fails if the path is `/`
* Fix #3745: updating require logic to account for item namespace

#### Improvements
* Fix #3674: allows the connect and websocket timeouts to apply to watches instead of a hardcoded timeout
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,19 +114,25 @@ protected T requireFromServer() {
* Get the current item from the server, consulting the metadata for the name if needed
* <br>Will always return non-null or throw an exception.
*/
protected T requireFromServer(ObjectMeta metadata) {
protected T requireFromServer(T item) {
try {
BaseOperation<T, L, R> withItem = withItem(null);
ObjectMeta metadata = null;
if (item != null) {
metadata = item.getMetadata();
}
withItem.setNamespace(checkNamespace(item));
if (Utils.isNotNullOrEmpty(getName())) {
return withItem(null).require();
return withItem.require();
}
if (getItem() != null) {
String name = KubernetesResourceUtil.getName(getItem());
if (Utils.isNotNullOrEmpty(name)) {
return withItem(null).withName(name).require();
return withItem.withName(name).require();
}
}
if (metadata != null && Utils.isNotNullOrEmpty(metadata.getName())) {
return withItem(null).withName(metadata.getName()).require();
return withItem.withName(metadata.getName()).require();
}
} catch (ResourceNotFoundException e) {
if (e.getCause() instanceof KubernetesClientException) {
Expand Down Expand Up @@ -168,8 +174,8 @@ protected T replace(T item, boolean status) {
}
if (!status) {
try {
ObjectMeta metadata = item.getMetadata();
item = modifyItemForReplaceOrPatch(() -> requireFromServer(metadata), item);
final T finalItem = item;
item = modifyItemForReplaceOrPatch(() -> requireFromServer(finalItem), item);
} catch (Exception e) {
throw KubernetesClientException.launderThrowable(forOperationType(REPLACE_OPERATION), e);
}
Expand All @@ -184,7 +190,7 @@ protected T replace(T item, boolean status) {
// if a resourceVersion is already there, try it first
resourceVersion = existingResourceVersion;
} else {
T got = requireFromServer(item.getMetadata());
T got = requireFromServer(item);
resourceVersion = KubernetesResourceUtil.getResourceVersion(got);
}

Expand Down Expand Up @@ -221,7 +227,7 @@ protected T replace(T item, boolean status) {

protected T patch(PatchContext context, T base, T item, boolean status) {
if (base == null && context != null && context.getPatchType() == PatchType.JSON) {
base = requireFromServer(item.getMetadata());
base = requireFromServer(item);
if (base.getMetadata() != null) {
// prevent the resourceVersion from being modified in the patch
if (item.getMetadata() == null) {
Expand Down

0 comments on commit 8b4696c

Please sign in to comment.