public class KubernetesResourceUtil extends Object
Modifier and Type | Field and Description |
---|---|
static String |
API_EXTENSIONS_VERSION |
static String |
API_VERSION |
static HashSet<Class<?>> |
SIMPLE_FIELD_TYPES |
Constructor and Description |
---|
KubernetesResourceUtil() |
Modifier and Type | Method and Description |
---|---|
static boolean |
addPort(List<io.fabric8.kubernetes.api.model.ContainerPort> ports,
String portNumberText,
String portName,
io.fabric8.maven.docker.util.Logger log) |
static boolean |
checkForKind(io.fabric8.kubernetes.api.model.KubernetesListBuilder builder,
String... kinds) |
static String |
extractContainerName(org.apache.maven.project.MavenProject project,
io.fabric8.maven.docker.config.ImageConfiguration imageConfig) |
static <T> T |
findResourceByName(Iterable<io.fabric8.kubernetes.api.model.HasMetadata> entities,
Class<T> clazz,
String name)
Returns the resource of the given kind and name from the collection or null
|
static String |
getBuildStatusPhase(io.fabric8.openshift.api.model.Build build) |
static String |
getBuildStatusReason(io.fabric8.openshift.api.model.Build build) |
static Date |
getCreationTimestamp(io.fabric8.kubernetes.api.model.HasMetadata hasMetadata) |
static String |
getDockerContainerID(io.fabric8.kubernetes.api.model.Pod pod) |
static String |
getEnvVar(List<io.fabric8.kubernetes.api.model.EnvVar> envVarList,
String name,
String defaultValue) |
static String |
getNameWithSuffix(String name,
String kind) |
static io.fabric8.kubernetes.api.model.Pod |
getNewestPod(Collection<io.fabric8.kubernetes.api.model.Pod> pods) |
static io.fabric8.kubernetes.api.model.HasMetadata |
getResource(String defaultApiVersion,
String apiExtensionsVersion,
File file,
String appName)
Read a Kubernetes resource fragment and add meta information extracted from the filename
to the resource descriptor.
|
static void |
handleKubernetesClientException(io.fabric8.kubernetes.client.KubernetesClientException e,
io.fabric8.maven.docker.util.Logger logger) |
static boolean |
isAppCatalogResource(io.fabric8.kubernetes.api.model.HasMetadata templateOrConfigMap) |
static boolean |
isNewerResource(io.fabric8.kubernetes.api.model.HasMetadata newer,
io.fabric8.kubernetes.api.model.HasMetadata older) |
static File[] |
listResourceFragments(File resourceDir) |
static String |
location(io.fabric8.kubernetes.api.model.HasMetadata item) |
static void |
mergePodSpec(io.fabric8.kubernetes.api.model.PodSpecBuilder builder,
io.fabric8.kubernetes.api.model.PodSpec defaultPodSpec,
String defaultName) |
static void |
mergeSimpleFields(Object targetValues,
Object defaultValues)
Uses reflection to copy over default values from the defaultValues object to the targetValues
object similar to the following:
\ * if( values.get${FIELD}() == null ) {
values.(with|set){FIELD}(defaultValues.get${FIELD});
}
Only fields that which use primitives, boxed primitives, or String object are copied. |
static boolean |
podHasContainerImage(io.fabric8.kubernetes.api.model.Pod pod,
String imageName) |
static void |
printLogsAsync(io.fabric8.kubernetes.client.dsl.LogWatch logWatcher,
String failureMessage,
CountDownLatch terminateLatch,
io.fabric8.maven.docker.util.Logger log) |
static io.fabric8.kubernetes.api.model.KubernetesListBuilder |
readResourceFragmentsFrom(String apiVersion,
String apiExtensionsVersion,
String defaultName,
File[] resourceFiles)
Read all Kubernetes resource fragments from a directory and create a
KubernetesListBuilder which
can be adapted later. |
static Map<String,String> |
removeVersionSelector(Map<String,String> selector) |
static boolean |
setEnvVar(List<io.fabric8.kubernetes.api.model.EnvVar> envVarList,
String name,
String value) |
static void |
setLocation(io.fabric8.kubernetes.api.model.HasMetadata item,
String location) |
static String |
toJson(Object resource) |
static String |
toYaml(Object resource) |
static void |
validateKubernetesMasterUrl(URL masterUrl) |
static File |
writeResource(Object resource,
File target,
ResourceFileType resourceFileType) |
static File |
writeResourceFile(Object resource,
File outputFile,
ResourceFileType resourceFileType) |
public static final String API_VERSION
public static final String API_EXTENSIONS_VERSION
public static io.fabric8.kubernetes.api.model.KubernetesListBuilder readResourceFragmentsFrom(String apiVersion, String apiExtensionsVersion, String defaultName, File[] resourceFiles) throws IOException
KubernetesListBuilder
which
can be adapted later.apiVersion
- the api version to useapiExtensionsVersion
- the extension version to usedefaultName
- the default name to use when none is givenappResourcesOnly
- if only resource with the defaultName should be returned ?resourceFiles
- files to add.IOException
public static io.fabric8.kubernetes.api.model.HasMetadata getResource(String defaultApiVersion, String apiExtensionsVersion, File file, String appName) throws IOException
defaultApiVersion
- the API version to add if not given.apiExtensionsVersion
- the API version for extensionsfile
- file to read, whose name must match FILENAME_PATTERN
. @return map holding the fragmentappName
- resource name specifying resources belonging to this applicationIOException
public static String toYaml(Object resource) throws com.fasterxml.jackson.core.JsonProcessingException
com.fasterxml.jackson.core.JsonProcessingException
public static String toJson(Object resource) throws com.fasterxml.jackson.core.JsonProcessingException
com.fasterxml.jackson.core.JsonProcessingException
public static File writeResource(Object resource, File target, ResourceFileType resourceFileType) throws IOException
IOException
public static File writeResourceFile(Object resource, File outputFile, ResourceFileType resourceFileType) throws IOException
IOException
public static String extractContainerName(org.apache.maven.project.MavenProject project, io.fabric8.maven.docker.config.ImageConfiguration imageConfig)
public static Map<String,String> removeVersionSelector(Map<String,String> selector)
public static boolean checkForKind(io.fabric8.kubernetes.api.model.KubernetesListBuilder builder, String... kinds)
public static boolean addPort(List<io.fabric8.kubernetes.api.model.ContainerPort> ports, String portNumberText, String portName, io.fabric8.maven.docker.util.Logger log)
public static boolean setEnvVar(List<io.fabric8.kubernetes.api.model.EnvVar> envVarList, String name, String value)
public static String getEnvVar(List<io.fabric8.kubernetes.api.model.EnvVar> envVarList, String name, String defaultValue)
public static void validateKubernetesMasterUrl(URL masterUrl) throws org.apache.maven.plugin.MojoExecutionException
org.apache.maven.plugin.MojoExecutionException
public static void handleKubernetesClientException(io.fabric8.kubernetes.client.KubernetesClientException e, io.fabric8.maven.docker.util.Logger logger) throws org.apache.maven.plugin.MojoExecutionException
org.apache.maven.plugin.MojoExecutionException
public static <T> T findResourceByName(Iterable<io.fabric8.kubernetes.api.model.HasMetadata> entities, Class<T> clazz, String name)
public static String getBuildStatusPhase(io.fabric8.openshift.api.model.Build build)
public static String getBuildStatusReason(io.fabric8.openshift.api.model.Build build)
public static void printLogsAsync(io.fabric8.kubernetes.client.dsl.LogWatch logWatcher, String failureMessage, CountDownLatch terminateLatch, io.fabric8.maven.docker.util.Logger log)
public static io.fabric8.kubernetes.api.model.Pod getNewestPod(Collection<io.fabric8.kubernetes.api.model.Pod> pods)
public static Date getCreationTimestamp(io.fabric8.kubernetes.api.model.HasMetadata hasMetadata)
public static boolean podHasContainerImage(io.fabric8.kubernetes.api.model.Pod pod, String imageName)
public static String getDockerContainerID(io.fabric8.kubernetes.api.model.Pod pod)
public static boolean isNewerResource(io.fabric8.kubernetes.api.model.HasMetadata newer, io.fabric8.kubernetes.api.model.HasMetadata older)
public static void mergeSimpleFields(Object targetValues, Object defaultValues)
\ * if( values.get${FIELD}() == null ) {
values.(with|set){FIELD}(defaultValues.get${FIELD});
}
Only fields that which use primitives, boxed primitives, or String object are copied.targetValues
- defaultValues
- public static void mergePodSpec(io.fabric8.kubernetes.api.model.PodSpecBuilder builder, io.fabric8.kubernetes.api.model.PodSpec defaultPodSpec, String defaultName)
public static String location(io.fabric8.kubernetes.api.model.HasMetadata item)
public static void setLocation(io.fabric8.kubernetes.api.model.HasMetadata item, String location)
public static boolean isAppCatalogResource(io.fabric8.kubernetes.api.model.HasMetadata templateOrConfigMap)
Copyright © 2017. All rights reserved.