-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add nodeSelector capabilities to DeploymentSpec
Signed-off-by: Vincent Sourin <[email protected]>
- Loading branch information
Showing
27 changed files
with
791 additions
and
8 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
...tions/src/main/java/io/dekorate/knative/decorator/AddNodeSelectorToRevisionDecorator.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 2018 The original authors. | ||
* | ||
* 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.dekorate.knative.decorator; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.Objects; | ||
|
||
import io.dekorate.kubernetes.config.NodeSelector; | ||
import io.dekorate.kubernetes.decorator.NamedResourceDecorator; | ||
import io.dekorate.utils.Strings; | ||
import io.fabric8.knative.serving.v1.RevisionSpecFluent; | ||
import io.fabric8.kubernetes.api.model.ObjectMeta; | ||
|
||
public class AddNodeSelectorToRevisionDecorator extends NamedResourceDecorator<RevisionSpecFluent<?>> { | ||
|
||
private final NodeSelector nodeSelector; | ||
|
||
public AddNodeSelectorToRevisionDecorator(NodeSelector nodeSelector) { | ||
this(ANY, nodeSelector); | ||
} | ||
|
||
public AddNodeSelectorToRevisionDecorator(String deploymentName, NodeSelector nodeSelector) { | ||
super(deploymentName); | ||
this.nodeSelector = nodeSelector; | ||
} | ||
|
||
public void andThenVisit(RevisionSpecFluent<?> revisionSpec, ObjectMeta resourceMeta) { | ||
if (Strings.isNotNullOrEmpty(nodeSelector.getKey()) && Strings.isNotNullOrEmpty(nodeSelector.getValue())) { | ||
Map<String, String> existing = revisionSpec.getNodeSelector(); | ||
|
||
if (existing == null) | ||
existing = new HashMap<>(); | ||
else | ||
existing.clear(); | ||
|
||
existing.put(nodeSelector.getKey(), nodeSelector.getValue()); | ||
revisionSpec.withNodeSelector(existing); | ||
} | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) | ||
return true; | ||
if (o == null || getClass() != o.getClass()) | ||
return false; | ||
AddNodeSelectorToRevisionDecorator that = (AddNodeSelectorToRevisionDecorator) o; | ||
return Objects.equals(nodeSelector, that.nodeSelector); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(nodeSelector); | ||
} | ||
} |
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
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
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
23 changes: 23 additions & 0 deletions
23
core/src/main/java/io/dekorate/kubernetes/annotation/NodeSelector.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,23 @@ | ||
/** | ||
* Copyright 2018 The original authors. | ||
* | ||
* 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.dekorate.kubernetes.annotation; | ||
|
||
public @interface NodeSelector { | ||
|
||
String key() default ""; | ||
|
||
String value() default ""; | ||
} |
57 changes: 57 additions & 0 deletions
57
core/src/main/java/io/dekorate/kubernetes/decorator/AddNodeSelectorDecorator.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,57 @@ | ||
/** | ||
* Copyright 2018 The original authors. | ||
* | ||
* 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.dekorate.kubernetes.decorator; | ||
|
||
import java.util.Objects; | ||
|
||
import io.dekorate.kubernetes.config.NodeSelector; | ||
import io.dekorate.utils.Strings; | ||
import io.fabric8.kubernetes.api.model.ObjectMeta; | ||
import io.fabric8.kubernetes.api.model.PodSpecFluent; | ||
|
||
public class AddNodeSelectorDecorator extends NamedResourceDecorator<PodSpecFluent<?>> { | ||
|
||
private final NodeSelector nodeSelector; | ||
|
||
public AddNodeSelectorDecorator(String deploymentName, NodeSelector nodeSelector) { | ||
super(deploymentName); | ||
this.nodeSelector = nodeSelector; | ||
} | ||
|
||
public void andThenVisit(PodSpecFluent<?> podSpec, ObjectMeta resourceMeta) { | ||
if (Strings.isNotNullOrEmpty(nodeSelector.getKey()) && Strings.isNotNullOrEmpty(nodeSelector.getValue())) { | ||
podSpec.removeFromNodeSelector(nodeSelector.getKey()); | ||
podSpec.addToNodeSelector(nodeSelector.getKey(), nodeSelector.getValue()); | ||
} | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) | ||
return true; | ||
if (o == null || getClass() != o.getClass()) | ||
return false; | ||
AddNodeSelectorDecorator that = (AddNodeSelectorDecorator) o; | ||
return Objects.equals(nodeSelector, that.nodeSelector); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(nodeSelector); | ||
} | ||
} |
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,4 @@ | ||
FROM openjdk:8u171-alpine3.7 | ||
RUN apk --no-cache add curl | ||
COPY target/*.jar kubernetes-with-nodeselectors-example.jar | ||
CMD java ${JAVA_OPTS} -jar kubernetes-with-nodeselectors-example.jar |
Oops, something went wrong.