Package io.fabric8.jenkins.openshiftsync
Class OpenShiftUtils
java.lang.Object
io.fabric8.jenkins.openshiftsync.OpenShiftUtils
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic void
addAnnotation
(io.fabric8.kubernetes.api.model.HasMetadata resource, String name, String value) static NamespaceName
buildConfigNameFromJenkinsJobName
(String jobName, String namespace) Maps a Jenkins Job name to an ObjectShift BuildConfig namestatic String
dumpWithoutRuntimeStateAsYaml
(io.fabric8.kubernetes.api.model.HasMetadata obj) static String
formatTimestamp
(long timestamp) static String
getAnnotation
(io.fabric8.kubernetes.api.model.HasMetadata resource, String name) static io.fabric8.openshift.client.OpenShiftClient
static String
getExternalServiceUrl
(io.fabric8.openshift.client.OpenShiftClient openShiftClient, String defaultProtocolText, String namespace, String serviceName) Returns the public URL of the given servicestatic ItemGroup
getFullNameParent
(Jenkins activeJenkins, String fullName, String namespace) Returns the parent for the given item full name or default to the active jenkins if it does not existstatic io.fabric8.kubernetes.client.informers.SharedInformerFactory
static String
getJenkinsURL
(io.fabric8.openshift.client.OpenShiftClient openShiftClient, String namespace) Calculates the external URL to access Jenkinsstatic String
static String
getName
(io.fabric8.kubernetes.api.model.HasMetadata resource) static String
getNamespace
(io.fabric8.kubernetes.api.model.HasMetadata resource) static String
static String[]
getNamespaceOrUseDefault
(String[] configuredNamespaces, io.fabric8.openshift.client.OpenShiftClient client) Gets the current namespace running Jenkins inside or returns a reasonable defaultprotected static io.fabric8.openshift.client.OpenShiftClient
static io.fabric8.openshift.client.OpenShiftClient
static void
initializeOpenShiftClient
(String serverUrl, int maxConnections) Initializes anOpenShiftClient
static boolean
isCancellable
(io.fabric8.openshift.api.model.BuildStatus buildStatus) static boolean
isCancelled
(io.fabric8.openshift.api.model.BuildStatus status) static boolean
isNew
(io.fabric8.openshift.api.model.BuildStatus buildStatus) static boolean
isPipelineStrategyBuild
(io.fabric8.openshift.api.model.Build b) static boolean
isPipelineStrategyBuildConfig
(io.fabric8.openshift.api.model.BuildConfig bc) Checks if aBuildConfig
relates to a Jenkins buildstatic boolean
isResourceWithoutStateEqual
(io.fabric8.kubernetes.api.model.HasMetadata oldObj, io.fabric8.kubernetes.api.model.HasMetadata newObj) static String
jenkinsJobDisplayName
(io.fabric8.openshift.api.model.BuildConfig bc) Finds the Jenkins job display name for the givenBuildConfig
.static String
jenkinsJobDisplayName
(String namespace, String buildConfigName) Creates the Jenkins Job display name for the given buildConfigNamestatic String
jenkinsJobFullName
(io.fabric8.openshift.api.model.BuildConfig bc) Finds the full jenkins job path including folders for the givenBuildConfig
.static String
jenkinsJobName
(io.fabric8.openshift.api.model.BuildConfig bc) Finds the Jenkins job name for the givenBuildConfig
.static String
jenkinsJobName
(String namespace, String buildConfigName) Creates the Jenkins Job name for the given buildConfigNamestatic long
parseResourceVersion
(io.fabric8.kubernetes.api.model.HasMetadata obj) static long
parseResourceVersion
(String resourceVersion) static long
parseTimestamp
(String timestamp) static void
static void
updateGitSourceUrl
(io.fabric8.openshift.api.model.BuildConfig buildConfig, String gitUrl, String ref) Lazily creates the GitSource if need be then updates the git URLstatic void
updateOpenShiftBuildPhase
(io.fabric8.openshift.api.model.Build build, String phase)
-
Constructor Details
-
OpenShiftUtils
public OpenShiftUtils()
-
-
Method Details
-
initializeOpenShiftClient
Initializes anOpenShiftClient
- Parameters:
serverUrl
- the optional URL of where the OpenShift cluster API server is runningmaxConnections
- the maximum number of connections
-
getOpenShiftClient
public static io.fabric8.openshift.client.OpenShiftClient getOpenShiftClient() -
getAuthenticatedOpenShiftClient
public static io.fabric8.openshift.client.OpenShiftClient getAuthenticatedOpenShiftClient() -
getInformerFactory
public static io.fabric8.kubernetes.client.informers.SharedInformerFactory getInformerFactory() -
shutdownOpenShiftClient
public static void shutdownOpenShiftClient() -
isPipelineStrategyBuildConfig
public static boolean isPipelineStrategyBuildConfig(io.fabric8.openshift.api.model.BuildConfig bc) Checks if aBuildConfig
relates to a Jenkins build- Parameters:
bc
- the BuildConfig- Returns:
- true if this is an OpenShift BuildConfig which should be mirrored to a Jenkins Job
-
isPipelineStrategyBuild
public static boolean isPipelineStrategyBuild(io.fabric8.openshift.api.model.Build b) -
jenkinsJobName
Finds the Jenkins job name for the givenBuildConfig
.- Parameters:
bc
- the BuildConfig- Returns:
- the jenkins job name for the given BuildConfig
-
jenkinsJobName
Creates the Jenkins Job name for the given buildConfigName- Parameters:
namespace
- the namespace of the buildbuildConfigName
- the name of theBuildConfig
in in the namespace- Returns:
- the jenkins job name for the given namespace and name
-
jenkinsJobFullName
Finds the full jenkins job path including folders for the givenBuildConfig
.- Parameters:
bc
- the BuildConfig- Returns:
- the jenkins job name for the given BuildConfig
-
getFullNameParent
Returns the parent for the given item full name or default to the active jenkins if it does not exist- Parameters:
activeJenkins
- the active Jenkins instancefullName
- the full name of the instancenamespace
- the namespace where the instance runs- Returns:
- and ItemGroup representing the full parent
-
jenkinsJobDisplayName
Finds the Jenkins job display name for the givenBuildConfig
.- Parameters:
bc
- the BuildConfig- Returns:
- the jenkins job display name for the given BuildConfig
-
jenkinsJobDisplayName
Creates the Jenkins Job display name for the given buildConfigName- Parameters:
namespace
- the namespace of the buildbuildConfigName
- the name of theBuildConfig
in in the namespace- Returns:
- the jenkins job display name for the given namespace and name
-
getNamespaceOrUseDefault
public static String[] getNamespaceOrUseDefault(String[] configuredNamespaces, io.fabric8.openshift.client.OpenShiftClient client) Gets the current namespace running Jenkins inside or returns a reasonable default- Parameters:
configuredNamespaces
- the optional configured namespace(s)client
- the OpenShift client- Returns:
- the default namespace using either the configuration value, the default namespace on the client or "default"
-
getExternalServiceUrl
public static String getExternalServiceUrl(io.fabric8.openshift.client.OpenShiftClient openShiftClient, String defaultProtocolText, String namespace, String serviceName) Returns the public URL of the given service- Parameters:
openShiftClient
- the OpenShiftClient to usedefaultProtocolText
- the protocol text part of a URL such ashttp://
namespace
- the Kubernetes namespaceserviceName
- the service name- Returns:
- the external URL of the service
-
getJenkinsURL
public static String getJenkinsURL(io.fabric8.openshift.client.OpenShiftClient openShiftClient, String namespace) Calculates the external URL to access Jenkins- Parameters:
namespace
- the namespace Jenkins is runing insideopenShiftClient
- the OpenShift client- Returns:
- the external URL to access Jenkins
-
getNamespacefromPodInputs
-
updateGitSourceUrl
public static void updateGitSourceUrl(io.fabric8.openshift.api.model.BuildConfig buildConfig, String gitUrl, String ref) Lazily creates the GitSource if need be then updates the git URL- Parameters:
buildConfig
- the BuildConfig to updategitUrl
- the URL to the git reporef
- the git ref (commit/branch/etc) for the build
-
updateOpenShiftBuildPhase
public static void updateOpenShiftBuildPhase(io.fabric8.openshift.api.model.Build build, String phase) -
buildConfigNameFromJenkinsJobName
Maps a Jenkins Job name to an ObjectShift BuildConfig name- Parameters:
jobName
- the job to associate to a BuildConfig namenamespace
- the default namespace that Jenkins is running inside- Returns:
- the namespaced name for the BuildConfig
-
parseResourceVersion
public static long parseResourceVersion(io.fabric8.kubernetes.api.model.HasMetadata obj) -
parseResourceVersion
-
formatTimestamp
-
parseTimestamp
-
isResourceWithoutStateEqual
public static boolean isResourceWithoutStateEqual(io.fabric8.kubernetes.api.model.HasMetadata oldObj, io.fabric8.kubernetes.api.model.HasMetadata newObj) -
dumpWithoutRuntimeStateAsYaml
public static String dumpWithoutRuntimeStateAsYaml(io.fabric8.kubernetes.api.model.HasMetadata obj) throws com.fasterxml.jackson.core.JsonProcessingException - Throws:
com.fasterxml.jackson.core.JsonProcessingException
-
isCancellable
public static boolean isCancellable(io.fabric8.openshift.api.model.BuildStatus buildStatus) -
isNew
public static boolean isNew(io.fabric8.openshift.api.model.BuildStatus buildStatus) -
isCancelled
public static boolean isCancelled(io.fabric8.openshift.api.model.BuildStatus status) -
getLabel
-
getAnnotation
-
addAnnotation
-
getNamespace
-
getName
-
getOpenshiftClient
protected static io.fabric8.openshift.client.OpenShiftClient getOpenshiftClient()
-