Skip to content
This repository has been archived by the owner on Jun 19, 2024. It is now read-only.

Commit

Permalink
Merge branch 'master' into jib-refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
rohanKanojia authored Feb 20, 2020
2 parents b056a43 + 291fbdc commit 2083ac1
Show file tree
Hide file tree
Showing 5 changed files with 157 additions and 21 deletions.
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,21 @@ We use semantic versioning in some slight variation until our feature set has st

After this we will switch probably to real [Semantic Versioning 2.0.0](http://semver.org/)

## Extracting changelog portions

We provide a script to extract changelog portions and automatic link building to send notifications
(i.e. e-mail) about new releases
([scripts/extract-changelog-for-version.sh](https://github.com/fabric8io/fabric8-maven-plugin/blob/master/scripts/extract-changelog-for-version.sh))

Usage:
```
# ./scripts/extract-changelog-for-version.sh semanticVersionNumber [linkLabelStartNumber]
./scripts/extract-changelog-for-version.sh 1.3.37 5
```

### 4.5-SNAPSHOT
* Fix #1789: script to extract changelog information for notifications
* Fix #1770: Fixed my mistake, remove constructors from OpenshiftBuildConfig which were causing PluginConfigurationException

### 4.4.0 (2020-02-13)
* Fix #1572: Support maven --batch-mode option
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,6 @@ public class OpenshiftBuildConfig {
private Map<String, String> limits;
private Map<String, String> requests;

public OpenshiftBuildConfig(Map<String, String> limits, Map<String, String> requests) {
this.limits = limits;
this.requests = requests;
}

public Map<String, String> getRequests() {
return requests;
}
Expand All @@ -41,4 +36,33 @@ public Map<String, String> getLimits() {
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;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,15 @@
import io.fabric8.maven.docker.util.Logger;
import io.fabric8.openshift.api.model.Build;
import io.fabric8.openshift.api.model.BuildConfig;
import io.fabric8.openshift.api.model.BuildConfigFluent;
import io.fabric8.openshift.api.model.BuildConfigSpec;
import io.fabric8.openshift.api.model.BuildConfigSpecBuilder;
import io.fabric8.openshift.api.model.BuildOutput;
import io.fabric8.openshift.api.model.BuildOutputBuilder;
import io.fabric8.openshift.api.model.BuildSource;
import io.fabric8.openshift.api.model.BuildStrategy;
import io.fabric8.openshift.api.model.BuildStrategyBuilder;
import io.fabric8.openshift.api.model.DoneableBuildConfig;
import io.fabric8.openshift.client.OpenShiftClient;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.lang3.StringUtils;
Expand Down Expand Up @@ -291,15 +293,12 @@ private BuildConfigSpec getBuildConfigSpec(BuildStrategy buildStrategyResource,
specBuilder.withOutput(buildOutput);
}

if (config.getResourceConfig() != null && config.getResourceConfig().getOpenshiftBuildConfig() != null) {
Map<String, Quantity> limits = KubernetesResourceUtil.getQuantityFromString(config.getResourceConfig().getOpenshiftBuildConfig().getLimits());
if (limits != null && !limits.isEmpty()) {
specBuilder.editOrNewResources().addToLimits(limits).endResources();
}
Map<String, Quantity> requests = KubernetesResourceUtil.getQuantityFromString(config.getResourceConfig().getOpenshiftBuildConfig().getRequests());
if (limits != null && !limits.isEmpty()) {
specBuilder.editOrNewResources().addToRequests(requests).endResources() ;
}
Map<String, Map<String, Quantity>> requestsLimitsMap = getRequestsAndLimits();
if (requestsLimitsMap.containsKey("requests")) {
specBuilder.editOrNewResources().addToRequests(requestsLimitsMap.get("requests")).endResources();
}
if (requestsLimitsMap.containsKey("limits")) {
specBuilder.editOrNewResources().addToLimits(requestsLimitsMap.get("limits")).endResources();
}
return specBuilder.build();
}
Expand All @@ -309,12 +308,19 @@ private String updateBuildConfig(OpenShiftClient client, String buildName, Build
// lets check if the strategy or output has changed and if so lets update the BC
// e.g. the S2I builder image or the output tag and
if (!Objects.equals(buildStrategy, spec.getStrategy()) || !Objects.equals(buildOutput, spec.getOutput())) {
client.buildConfigs().withName(buildName).edit()
.editSpec()
.withStrategy(buildStrategy)
.withOutput(buildOutput)
.endSpec()
.done();
BuildConfigFluent.SpecNested<DoneableBuildConfig> doneableBuildConfig = client.buildConfigs().withName(buildName).edit().editSpec();
doneableBuildConfig.withStrategy(buildStrategy)
.withOutput(buildOutput);

Map<String, Map<String, Quantity>> requestsLimitsMap = getRequestsAndLimits();
if (requestsLimitsMap.containsKey("requests")) {
doneableBuildConfig.editOrNewResources().addToRequests(requestsLimitsMap.get("requests")).endResources();
}
if (requestsLimitsMap.containsKey("limits")) {
doneableBuildConfig.editOrNewResources().addToLimits(requestsLimitsMap.get("limits")).endResources();
}

doneableBuildConfig.endSpec().done();
log.info("Updating BuildServiceConfig %s for %s strategy", buildName, buildStrategy.getType());
} else {
log.info("Using BuildServiceConfig %s for %s strategy", buildName, buildStrategy.getType());
Expand Down Expand Up @@ -761,4 +767,19 @@ private String getMapValueWithDefault(Map<String, String> map, String field, Str
return value != null ? value : defaultValue;
}

private Map<String, Map<String, Quantity>> getRequestsAndLimits() {
Map<String, Map<String, Quantity>> keyToQuantityMap = new HashMap<>();
if (config.getResourceConfig() != null && config.getResourceConfig().getOpenshiftBuildConfig() != null) {
Map<String, Quantity> limits = KubernetesResourceUtil.getQuantityFromString(config.getResourceConfig().getOpenshiftBuildConfig().getLimits());
if (!limits.isEmpty()) {
keyToQuantityMap.put("limits", limits);
}
Map<String, Quantity> requests = KubernetesResourceUtil.getQuantityFromString(config.getResourceConfig().getOpenshiftBuildConfig().getRequests());
if (!requests.isEmpty()) {
keyToQuantityMap.put("requests", requests);
}
}
return keyToQuantityMap;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ public void testBuildConfigResourceConfig() throws Exception {

BuildService.BuildServiceConfig config = defaultConfig
.resourceConfig(new ResourceConfig.Builder()
.withOpenshiftBuildConfig(new OpenshiftBuildConfig(limitsMap, null)).build()).build();
.withOpenshiftBuildConfig(new OpenshiftBuildConfig.Builder().limits(limitsMap).build()).build()).build();
OpenShiftMockServer mockServer = new OpenShiftMockServer();

OpenShiftClient client = mockServer.createOpenShiftClient();
Expand Down
77 changes: 77 additions & 0 deletions scripts/extract-changelog-for-version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#!/bin/bash
#
# Copyright 2016 Red Hat, Inc.
#
# Red Hat licenses this file to you 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.
#

trap 'exit' ERR

START_LINK=10
BASEDIR=$(dirname "$BASH_SOURCE")

function checkInput() {
if [ "$#" -lt 1 ]; then
echo -e "This script extracts chagnelog version contents from CHANGELOG.md"
echo -e "Usage: ./extract-changelog-for-version.sh semVer [startLinkNumber]\n"
echo -e "Must set a valid semantic version number (e.g. 1.3.37)"
exit 1;
fi
dotCount=$(echo "$1" | tr -d -c '.' | wc -c)
if [ "$dotCount" -ne 2 ]; then
echo "Provided version has an invalid format, should be semver compliant (e.g. 1.3.37)"
exit 1;
fi
}

function extractChangelogPortion() {
sed -e "/### ""$1""/,/###/!d" "$BASEDIR/../CHANGELOG.md"
}

function removeLastLine() {
echo "$1" | sed '$d'
}

function replaceBullets() {
echo -e "$1" | sed -e "s/^*/-/"
}

function addLinks() {
lines=""
links=""
currentLink="$START_LINK"
if [ -n "$2" ]; then currentLink="$2" ; fi
while read -r line; do
issueNumber=$(echo "$line" | sed -En 's/.*?#([0-9]+).*/\1/p')
if [ -z "$issueNumber" ]; then
lines+="$line\n";
else
lines+="$line [$currentLink]\n"
links+="[$currentLink]: https://github.com/fabric8io/fabric8-maven-plugin/issues/$issueNumber\n"
currentLink=$((currentLink + 1));
fi
done < <(echo "$1")
echo -e "$lines\n$links";
}

function processChangelog() {
changelog=$1
changelog=$(extractChangelogPortion "$changelog")
changelog=$(removeLastLine "$changelog")
changelog=$(replaceBullets "$changelog")
changelog=$(addLinks "$changelog" "$2")
echo "$changelog";
}

checkInput "$@"
processChangelog "$@"

0 comments on commit 2083ac1

Please sign in to comment.