Skip to content

Commit

Permalink
Fix eclipse-jkube#224: RoleBinding Resources Not Supported by Kuberne…
Browse files Browse the repository at this point in the history
…tes Cluster Configurations

Signed-off-by: James Carman <jwcarman@gmail.com>
  • Loading branch information
jwcarman committed Jun 2, 2020
1 parent 0ad9712 commit fedc744
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 41 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ Usage:
* Fix #209: WildFlySwarmGenerator includes required env variables + java options
* Fix #214: fix: KarafGenerator update (Created Karaf Quickstart #188, fix FileSet problems, upgraded base images)
* Fix #220: Remove Red Hat specific image support
* Fix #224: RoleBinding Resources Not Supported by Kubernetes Cluster Configurations

### 1.0.0-alpha-3 (2020-05-06)
* Fix #167: Add CMD for wildfly based applications
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -729,57 +729,52 @@ public void doCreateBuildConfig(BuildConfig entity, String namespace , String so
}

public void applyRoleBinding(RoleBinding entity, String sourceName) {
OpenShiftClient openShiftClient = getOpenShiftClient();
if (openShiftClient != null) {
String id = getName(entity);
String id = getName(entity);

Objects.requireNonNull(id, "No name for " + entity + " " + sourceName);
String namespace = KubernetesHelper.getNamespace(entity);
if (StringUtils.isBlank(namespace)) {
namespace = getNamespace();
}
applyNamespace(namespace);
RoleBinding old = openShiftClient.rbac().roleBindings().inNamespace(namespace).withName(id).get();
if (isRunning(old)) {
if (UserConfigurationCompare.configEqual(entity, old)) {
log.info("RoleBinding has not changed so not doing anything");
Objects.requireNonNull(id, "No name for " + entity + " " + sourceName);
String namespace = KubernetesHelper.getNamespace(entity);
if (StringUtils.isBlank(namespace)) {
namespace = getNamespace();
}
applyNamespace(namespace);
RoleBinding old = kubernetesClient.rbac().roleBindings().inNamespace(namespace).withName(id).get();
if (isRunning(old)) {
if (UserConfigurationCompare.configEqual(entity, old)) {
log.info("RoleBinding has not changed so not doing anything");
} else {
if (isRecreateMode()) {
log.info("Deleting RoleBinding: " + id);
kubernetesClient.rbac().roleBindings().inNamespace(namespace).withName(id).delete();
doCreateRoleBinding(entity, namespace, sourceName);
} else {
if (isRecreateMode()) {
log.info("Deleting RoleBinding: " + id);
openShiftClient.roleBindings().inNamespace(namespace).withName(id).delete();
doCreateRoleBinding(entity, namespace, sourceName);
} else {
log.info("Updating RoleBinding from " + sourceName);
try {
String resourceVersion = KubernetesHelper.getResourceVersion(old);
ObjectMeta metadata = getOrCreateMetadata(entity);
metadata.setNamespace(namespace);
metadata.setResourceVersion(resourceVersion);
Object answer = openShiftClient.rbac().roleBindings().inNamespace(namespace).withName(id).replace(entity);
logGeneratedEntity("Updated RoleBinding: ", namespace, entity, answer);
} catch (Exception e) {
onApplyError("Failed to update RoleBinding from " + sourceName + ". " + e + ". " + entity, e);
}
log.info("Updating RoleBinding from " + sourceName);
try {
String resourceVersion = KubernetesHelper.getResourceVersion(old);
ObjectMeta metadata = getOrCreateMetadata(entity);
metadata.setNamespace(namespace);
metadata.setResourceVersion(resourceVersion);
Object answer = kubernetesClient.rbac().roleBindings().inNamespace(namespace).withName(id).replace(entity);
logGeneratedEntity("Updated RoleBinding: ", namespace, entity, answer);
} catch (Exception e) {
onApplyError("Failed to update RoleBinding from " + sourceName + ". " + e + ". " + entity, e);
}
}
}
} else {
if (!isAllowCreate()) {
log.warn("Creation disabled so not creating RoleBinding from " + sourceName + " namespace " + namespace + " name " + getName(entity));
} else {
if (!isAllowCreate()) {
log.warn("Creation disabled so not creating RoleBinding from " + sourceName + " namespace " + namespace + " name " + getName(entity));
} else {
doCreateRoleBinding(entity, namespace, sourceName);
}
doCreateRoleBinding(entity, namespace, sourceName);
}
}
}

public void doCreateRoleBinding(RoleBinding entity, String namespace , String sourceName) {
OpenShiftClient openShiftClient = getOpenShiftClient();
if (openShiftClient != null) {
try {
openShiftClient.rbac().roleBindings().inNamespace(namespace).create(entity);
} catch (Exception e) {
onApplyError("Failed to create RoleBinding from " + sourceName + ". " + e, e);
}
try {
log.info("Creating RoleBinding from " + sourceName + " namespace " + namespace + " name " + getName(entity));
kubernetesClient.rbac().roleBindings().inNamespace(namespace).create(entity);
} catch (Exception e) {
onApplyError("Failed to create RoleBinding from " + sourceName + ". " + e, e);
}
}

Expand Down

0 comments on commit fedc744

Please sign in to comment.