-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix #3144: making the crud mock logic more crd aware
also working around making the namespace and kind available from the path
- Loading branch information
Showing
10 changed files
with
270 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
...main/java/io/fabric8/kubernetes/client/server/mock/CustomResourceDefinitionProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/** | ||
* Copyright (C) 2015 Red Hat, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.fabric8.kubernetes.client.server.mock; | ||
|
||
import io.fabric8.kubernetes.api.model.apiextensions.v1.CustomResourceDefinition; | ||
import io.fabric8.kubernetes.client.dsl.base.CustomResourceDefinitionContext; | ||
import io.fabric8.kubernetes.client.utils.Serialization; | ||
|
||
import java.util.Optional; | ||
|
||
/** | ||
* Holds state related to crds by manipulating the crds known to the attributes extractor | ||
*/ | ||
public class CustomResourceDefinitionProcessor { | ||
|
||
private static final String V1BETA1_PATH = "/apis/apiextensions.k8s.io/v1beta1/customresourcedefinitions"; | ||
private static final String V1_PATH = "/apis/apiextensions.k8s.io/v1/customresourcedefinitions"; | ||
|
||
private KubernetesAttributesExtractor extractor; | ||
|
||
public CustomResourceDefinitionProcessor(KubernetesAttributesExtractor extractor) { | ||
this.extractor = extractor; | ||
} | ||
|
||
public void process(String path, String crdString, boolean delete) { | ||
CustomResourceDefinitionContext context = null; | ||
if (path.startsWith(V1BETA1_PATH)) { | ||
io.fabric8.kubernetes.api.model.apiextensions.v1beta1.CustomResourceDefinition crd = Serialization | ||
.unmarshal(crdString, io.fabric8.kubernetes.api.model.apiextensions.v1beta1.CustomResourceDefinition.class); | ||
context = CustomResourceDefinitionContext.fromCrd(crd); | ||
} else if (path.startsWith(V1_PATH)) { | ||
CustomResourceDefinition crd = Serialization.unmarshal(crdString, CustomResourceDefinition.class); | ||
context = CustomResourceDefinitionContext.fromCrd(crd); | ||
} else { | ||
return; | ||
} | ||
if (delete) { | ||
extractor.getCrdContexts().remove(context.getPlural()); | ||
} else { | ||
extractor.getCrdContexts().put(context.getPlural(), context); | ||
} | ||
} | ||
|
||
public boolean isStatusSubresource(String kind) { | ||
if (kind == null) { | ||
return false; | ||
} | ||
// we are only holding by plural, lookup now by kind | ||
Optional<CustomResourceDefinitionContext> context = | ||
extractor.getCrdContexts().values().stream().filter(c -> kind.equalsIgnoreCase(c.getKind())).findFirst(); | ||
if (!context.isPresent()) { | ||
return false; | ||
} | ||
return context.get().isStatusSubresource(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.