forked from eclipse-jkube/jkube
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Provide support for setting BuildConfig memory/CPU requests and limits
Ported PR fabric8io/fabric8-maven-plugin#1772
- Loading branch information
1 parent
374816b
commit 8da1dc9
Showing
10 changed files
with
387 additions
and
10 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
58 changes: 58 additions & 0 deletions
58
jkube-kit/common/src/test/java/org/eclipse/jkube/kit/common/util/KubernetesHelperTest.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,58 @@ | ||
/** | ||
* Copyright (c) 2019 Red Hat, Inc. | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at: | ||
* | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Red Hat, Inc. - initial API and implementation | ||
*/ | ||
package org.eclipse.jkube.kit.common.util; | ||
|
||
import mockit.Mocked; | ||
import org.eclipse.jkube.kit.common.KitLogger; | ||
import org.junit.Test; | ||
|
||
import java.io.File; | ||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
public class KubernetesHelperTest { | ||
@Mocked | ||
KitLogger logger; | ||
|
||
@Test | ||
public void testListResourceFragments() { | ||
File localResourceDir = new File(getClass().getResource("/util/fragments").getPath()); | ||
|
||
assertLocalFragments(KubernetesHelper.listResourceFragments(localResourceDir, null, logger), 2); | ||
} | ||
|
||
@Test | ||
public void testResourceFragmentsWithRemotes() { | ||
List<String> remoteStrList = new ArrayList<>(); | ||
|
||
remoteStrList.add("https://gist.githubusercontent.com/lordofthejars/ac2823cec7831697d09444bbaa76cd50/raw/e4b43f1b6494766dfc635b5959af7730c1a58a93/deployment.yaml"); | ||
remoteStrList.add("https://gist.githubusercontent.com/rohanKanojia/c4ac4ae5533f0bf0dd77d13c905face7/raw/8a7de1e27c1f437c1ccbd186ed247efd967953ee/sa.yml"); | ||
File localResourceDir = new File(getClass().getResource("/util/fragments").getPath()); | ||
|
||
File[] fragments = KubernetesHelper.listResourceFragments(localResourceDir, remoteStrList, logger); | ||
assertLocalFragments(fragments, 4); | ||
assertTrue(Arrays.stream(fragments).anyMatch( f -> f.getName().equals("deployment.yaml"))); | ||
assertTrue(Arrays.stream(fragments).anyMatch( f -> f.getName().equals("sa.yml"))); | ||
} | ||
|
||
private void assertLocalFragments(File[] fragments, int expectedSize) { | ||
assertEquals(expectedSize, fragments.length); | ||
assertTrue(Arrays.stream(fragments).anyMatch( f -> f.getName().equals("deployment.yml"))); | ||
assertTrue(Arrays.stream(fragments).anyMatch( f -> f.getName().equals("service.yml"))); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
jkube-kit/common/src/test/resources/util/fragments/deployment.yml
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,35 @@ | ||
# | ||
# Copyright (c) 2019 Red Hat, Inc. | ||
# This program and the accompanying materials are made | ||
# available under the terms of the Eclipse Public License 2.0 | ||
# which is available at: | ||
# | ||
# https://www.eclipse.org/legal/epl-2.0/ | ||
# | ||
# SPDX-License-Identifier: EPL-2.0 | ||
# | ||
# Contributors: | ||
# Red Hat, Inc. - initial API and implementation | ||
# | ||
|
||
spec: | ||
replicas: 1 | ||
template: | ||
spec: | ||
volumes: | ||
- name: config | ||
gitRepo: | ||
repository: 'https://github.com/jstrachan/sample-springboot-config.git' | ||
revision: 667ee4db6bc842b127825351e5c9bae5a4fb2147 | ||
directory: . | ||
containers: | ||
- volumeMounts: | ||
- name: config | ||
mountPath: /app/config | ||
env: | ||
- name: KUBERNETES_NAMESPACE | ||
valueFrom: | ||
fieldRef: | ||
apiVersion: v1 | ||
fieldPath: metadata.namespace | ||
serviceAccount: ribbon |
19 changes: 19 additions & 0 deletions
19
jkube-kit/common/src/test/resources/util/fragments/service.yml
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,19 @@ | ||
# | ||
# Copyright (c) 2019 Red Hat, Inc. | ||
# This program and the accompanying materials are made | ||
# available under the terms of the Eclipse Public License 2.0 | ||
# which is available at: | ||
# | ||
# https://www.eclipse.org/legal/epl-2.0/ | ||
# | ||
# SPDX-License-Identifier: EPL-2.0 | ||
# | ||
# Contributors: | ||
# Red Hat, Inc. - initial API and implementation | ||
# | ||
|
||
metadata: | ||
annotations: | ||
api.service.kubernetes.io/path: /hello | ||
spec: | ||
type: LoadBalancer |
66 changes: 66 additions & 0 deletions
66
...ig/resource/src/main/java/org/eclipse/jkube/kit/config/resource/OpenshiftBuildConfig.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,66 @@ | ||
/** | ||
* Copyright (c) 2019 Red Hat, Inc. | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at: | ||
* | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Red Hat, Inc. - initial API and implementation | ||
*/ | ||
package org.eclipse.jkube.kit.config.resource; | ||
|
||
import java.util.Map; | ||
|
||
public class OpenshiftBuildConfig { | ||
private Map<String, String> limits; | ||
private Map<String, String> requests; | ||
|
||
public Map<String, String> getRequests() { | ||
return requests; | ||
} | ||
|
||
public void setRequests(Map<String, String> requests) { | ||
this.requests = requests; | ||
} | ||
|
||
public Map<String, String> getLimits() { | ||
return limits; | ||
} | ||
|
||
public void setLimits(Map<String, String> resourceLimits) { | ||
this.limits = resourceLimits; | ||
} | ||
|
||
public static class Builder { | ||
private OpenshiftBuildConfig openshiftBuildConfig; | ||
|
||
public Builder() { | ||
this.openshiftBuildConfig = new OpenshiftBuildConfig(); | ||
} | ||
|
||
public Builder(OpenshiftBuildConfig openshiftBuildConfig) { | ||
if (openshiftBuildConfig != null) { | ||
this.openshiftBuildConfig.limits = openshiftBuildConfig.limits; | ||
this.openshiftBuildConfig.requests = openshiftBuildConfig.requests; | ||
} | ||
} | ||
|
||
public Builder limits(Map<String, String> limits) { | ||
this.openshiftBuildConfig.limits = limits; | ||
return this; | ||
} | ||
|
||
public Builder requests(Map<String, String> requests) { | ||
this.openshiftBuildConfig.requests = requests; | ||
return this; | ||
} | ||
|
||
public OpenshiftBuildConfig build() { | ||
return this.openshiftBuildConfig; | ||
} | ||
} | ||
} |
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
Oops, something went wrong.