use of io.fabric8.kubernetes.api.model.ObjectReference in project fabric8-maven-plugin by fabric8io.
the class OpenshiftBuildService method logBuildBuildFailedDetails.
private void logBuildBuildFailedDetails(OpenShiftClient client, String buildName) {
try {
BuildConfig build = client.buildConfigs().withName(buildName).get();
ObjectReference ref = build.getSpec().getStrategy().getSourceStrategy().getFrom();
String kind = ref.getKind();
String name = ref.getName();
if ("DockerImage".equals(kind)) {
log.error("Please, ensure that the Docker image '%s' exists and is accessible by OpenShift", name);
} else if ("ImageStreamTag".equals(kind)) {
String namespace = ref.getNamespace();
String namespaceInfo = "current";
String namespaceParams = "";
if (namespace != null && !namespace.isEmpty()) {
namespaceInfo = "'" + namespace + "'";
namespaceParams = " -n " + namespace;
}
log.error("Please, ensure that the ImageStream Tag '%s' exists in the %s namespace (with 'oc get is%s')", name, namespaceInfo, namespaceParams);
}
} catch (Exception ex) {
log.error("Unable to get detailed information from the BuildServiceConfig: " + ex.getMessage());
}
}
use of io.fabric8.kubernetes.api.model.ObjectReference in project strimzi by strimzi.
the class KafkaConnectS2ICluster method generateSourceImageStream.
/**
* Generate new source ImageStream
*
* @return Source ImageStream resource definition
*/
public ImageStream generateSourceImageStream() {
ObjectReference image = new ObjectReference();
image.setKind("DockerImage");
image.setName(sourceImageBaseName + ":" + sourceImageTag);
TagReference sourceTag = new TagReference();
sourceTag.setName(sourceImageTag);
sourceTag.setFrom(image);
ImageStream imageStream = new ImageStreamBuilder().withNewMetadata().withName(getSourceImageStreamName()).withNamespace(namespace).withLabels(getLabelsWithName(getSourceImageStreamName())).endMetadata().withNewSpec().withLookupPolicy(new ImageLookupPolicyBuilder().withLocal(false).build()).withTags(sourceTag).endSpec().build();
return imageStream;
}
use of io.fabric8.kubernetes.api.model.ObjectReference in project fabric8 by fabric8io.
the class SessionListener method generateServiceAccount.
private void generateServiceAccount(KubernetesClient client, Session session, Set<Secret> secrets, String serviceAccountName) {
List<ObjectReference> secretRefs = new ArrayList<>();
for (Secret secret : secrets) {
secretRefs.add(new ObjectReferenceBuilder().withNamespace(session.getNamespace()).withName(KubernetesHelper.getName(secret)).build());
}
SecurityContextConstraints securityContextConstraints = client.securityContextConstraints().withName(session.getNamespace()).get();
if (securityContextConstraints == null) {
client.securityContextConstraints().createNew().withNewMetadata().withName(session.getNamespace()).endMetadata().withAllowHostDirVolumePlugin(true).withAllowPrivilegedContainer(true).withNewRunAsUser().withType("RunAsAny").endRunAsUser().withNewSeLinuxContext().withType("RunAsAny").endSeLinuxContext().withUsers("system:serviceaccount:" + session.getNamespace() + ":" + serviceAccountName).done();
}
ServiceAccount serviceAccount = client.serviceAccounts().inNamespace(session.getNamespace()).withName(serviceAccountName).get();
if (serviceAccount == null) {
client.serviceAccounts().inNamespace(session.getNamespace()).createNew().withNewMetadata().withName(serviceAccountName).endMetadata().withSecrets(secretRefs).done();
} else {
client.serviceAccounts().inNamespace(session.getNamespace()).withName(serviceAccountName).replace(new ServiceAccountBuilder(serviceAccount).withNewMetadata().withName(serviceAccountName).endMetadata().addToSecrets(secretRefs.toArray(new ObjectReference[secretRefs.size()])).build());
}
}
Aggregations