use of io.fabric8.kubernetes.api.model.HasMetadata in project fabric8-maven-plugin by fabric8io.
the class ResourceMojo method createTemplateWithObjects.
private static Template createTemplateWithObjects(KubernetesList kubernetesResources, Template template) {
List<io.fabric8.openshift.api.model.Parameter> parameters = template.getParameters();
List<HasMetadata> items = kubernetesResources.getItems();
Template tempTemplate = null;
if (parameters != null && parameters.size() > 0 && items != null && items.size() > 0) {
tempTemplate = new Template();
tempTemplate.setMetadata(template.getMetadata());
tempTemplate.setParameters(parameters);
tempTemplate.setObjects(items);
}
return tempTemplate;
}
use of io.fabric8.kubernetes.api.model.HasMetadata in project fabric8-maven-plugin by fabric8io.
the class DebugMojo method applyEntities.
@Override
protected void applyEntities(Controller controller, KubernetesClient kubernetes, String namespace, String fileName, Set<HasMetadata> entities) throws Exception {
LabelSelector firstSelector = null;
for (HasMetadata entity : entities) {
String name = getName(entity);
LabelSelector selector = null;
if (entity instanceof Deployment) {
Deployment resource = (Deployment) entity;
DeploymentSpec spec = resource.getSpec();
if (spec != null) {
if (enableDebugging(entity, spec.getTemplate())) {
kubernetes.extensions().deployments().inNamespace(namespace).withName(name).replace(resource);
}
selector = getPodLabelSelector(entity);
}
} else if (entity instanceof ReplicaSet) {
ReplicaSet resource = (ReplicaSet) entity;
ReplicaSetSpec spec = resource.getSpec();
if (spec != null) {
if (enableDebugging(entity, spec.getTemplate())) {
kubernetes.extensions().replicaSets().inNamespace(namespace).withName(name).replace(resource);
}
selector = getPodLabelSelector(entity);
}
} else if (entity instanceof ReplicationController) {
ReplicationController resource = (ReplicationController) entity;
ReplicationControllerSpec spec = resource.getSpec();
if (spec != null) {
if (enableDebugging(entity, spec.getTemplate())) {
kubernetes.replicationControllers().inNamespace(namespace).withName(name).replace(resource);
}
selector = getPodLabelSelector(entity);
}
} else if (entity instanceof DeploymentConfig) {
DeploymentConfig resource = (DeploymentConfig) entity;
DeploymentConfigSpec spec = resource.getSpec();
if (spec != null) {
if (enableDebugging(entity, spec.getTemplate())) {
OpenShiftClient openshiftClient = new Controller(kubernetes).getOpenShiftClientOrNull();
if (openshiftClient == null) {
log.warn("Ignoring DeploymentConfig %s as not connected to an OpenShift cluster", name);
continue;
}
openshiftClient.deploymentConfigs().inNamespace(namespace).withName(name).replace(resource);
}
selector = getPodLabelSelector(entity);
}
}
if (selector != null) {
firstSelector = selector;
} else {
controller.apply(entity, fileName);
}
}
if (firstSelector != null) {
Map<String, String> envVars = new TreeMap<>();
envVars.put(DebugConstants.ENV_VAR_JAVA_DEBUG, "true");
envVars.put(DebugConstants.ENV_VAR_JAVA_DEBUG_SUSPEND, String.valueOf(this.debugSuspend));
if (this.debugSuspendValue != null) {
envVars.put(DebugConstants.ENV_VAR_JAVA_DEBUG_SESSION, this.debugSuspendValue);
}
String podName = waitForRunningPodWithEnvVar(kubernetes, namespace, firstSelector, envVars);
portForward(controller, podName);
}
}
use of io.fabric8.kubernetes.api.model.HasMetadata in project fabric8-maven-plugin by fabric8io.
the class HelmMojo method findTemplate.
private Template findTemplate() throws MojoExecutionException {
if (kubernetesTemplate != null && kubernetesTemplate.isFile()) {
Object dto = null;
try {
dto = KubernetesHelper.loadYaml(kubernetesTemplate, KubernetesResource.class);
} catch (IOException e) {
throw new MojoExecutionException("Failed to load kubernetes YAML " + kubernetesTemplate + ". " + e, e);
}
if (dto instanceof Template) {
return (Template) dto;
}
if (dto instanceof KubernetesList) {
KubernetesList list = (KubernetesList) dto;
List<HasMetadata> items = list.getItems();
if (items != null) {
for (HasMetadata item : items) {
if (item instanceof Template) {
return (Template) item;
}
}
}
}
}
return null;
}
use of io.fabric8.kubernetes.api.model.HasMetadata in project fabric8-maven-plugin by fabric8io.
the class HelmMojo method copyTemplateResourcesToTemplatesDir.
private void copyTemplateResourcesToTemplatesDir(File templatesDir, Template template) throws MojoExecutionException {
List<HasMetadata> objects = template.getObjects();
if (objects != null) {
for (HasMetadata object : objects) {
String name = getNameWithSuffix(KubernetesHelper.getName(object), KubernetesHelper.getKind(object)) + ".yaml";
File outFile = new File(templatesDir, name);
try {
saveYaml(object, outFile);
} catch (IOException e) {
throw new MojoExecutionException("Failed to save template " + outFile + ": " + e, e);
}
}
}
}
use of io.fabric8.kubernetes.api.model.HasMetadata in project fabric8-maven-plugin by fabric8io.
the class HelmMojo method findIconURL.
private String findIconURL() throws MojoExecutionException {
String answer = null;
if (kubernetesManifest != null && kubernetesManifest.isFile()) {
Object dto = null;
try {
dto = KubernetesHelper.loadYaml(kubernetesManifest, KubernetesResource.class);
} catch (IOException e) {
throw new MojoExecutionException("Failed to load kubernetes YAML " + kubernetesManifest + ". " + e, e);
}
if (dto instanceof HasMetadata) {
answer = KubernetesHelper.getOrCreateAnnotations((HasMetadata) dto).get(Annotations.Builds.ICON_URL);
}
if (Strings.isNullOrBlank(answer) && dto instanceof KubernetesList) {
KubernetesList list = (KubernetesList) dto;
List<HasMetadata> items = list.getItems();
if (items != null) {
for (HasMetadata item : items) {
answer = KubernetesHelper.getOrCreateAnnotations(item).get(Annotations.Builds.ICON_URL);
if (Strings.isNotBlank(answer)) {
break;
}
}
}
}
} else {
getLog().warn("No kubernetes manifest file has been generated yet by the fabric8:resource goal at: " + kubernetesManifest);
}
return answer;
}
Aggregations