use of io.fabric8.openshift.api.model.Project in project fabric8-maven-plugin by fabric8io.
the class DeploymentHandlerTest method deploymentTemplateHandlerWithInvalidNameTest.
@Test(expected = IllegalArgumentException.class)
public void deploymentTemplateHandlerWithInvalidNameTest() {
// invalid controller name
ContainerHandler containerHandler = new ContainerHandler(project, envVarHandler, probeHandler);
PodTemplateHandler podTemplateHandler = new PodTemplateHandler(containerHandler);
DeploymentHandler deploymentHandler = new DeploymentHandler(podTemplateHandler);
// with invalid controller name
ResourceConfig config = new ResourceConfig.Builder().imagePullPolicy("IfNotPresent").controllerName("TesTing").withServiceAccount("test-account").withReplicas(5).volumes(volumes1).build();
deploymentHandler.getDeployment(config, images);
}
use of io.fabric8.openshift.api.model.Project in project fabric8-maven-plugin by fabric8io.
the class AutoTLSEnricherTest method testSecretName.
@Test
public void testSecretName() throws Exception {
final SecretNameTestConfig[] data = new SecretNameTestConfig[] { new SecretNameTestConfig(PlatformMode.kubernetes, null, null), new SecretNameTestConfig(PlatformMode.openshift, null, "projectA-tls"), new SecretNameTestConfig(PlatformMode.openshift, "custom-secret", "custom-secret") };
for (final SecretNameTestConfig tc : data) {
final ProcessorConfig config = new ProcessorConfig(null, null, Collections.singletonMap(AutoTLSEnricher.ENRICHER_NAME, new TreeMap(Collections.singletonMap(AutoTLSEnricher.Config.tlsSecretName.name(), tc.tlsSecretNameConfig))));
final Properties projectProps = new Properties();
projectProps.put(PlatformMode.FABRIC8_EFFECTIVE_PLATFORM_MODE, tc.mode.name());
// Setup mock behaviour
new Expectations() {
{
project.getProperties();
result = projectProps;
project.getArtifactId();
result = "projectA";
minTimes = 0;
context.getProject();
result = project;
context.getConfig();
result = config;
}
};
AutoTLSEnricher enricher = new AutoTLSEnricher(context);
Map<String, String> annotations = enricher.getAnnotations(Kind.SERVICE);
if (tc.mode == PlatformMode.kubernetes) {
assertNull(annotations);
continue;
}
assertEquals(1, annotations.size());
assertEquals(tc.tlsSecretName, annotations.get(AutoTLSEnricher.AUTOTLS_ANNOTATION_KEY));
}
}
use of io.fabric8.openshift.api.model.Project in project fabric8-maven-plugin by fabric8io.
the class AutoTLSEnricherTest method testAdapt.
@Test
public void testAdapt() throws Exception {
final AdaptTestConfig[] data = new AdaptTestConfig[] { new AdaptTestConfig(PlatformMode.kubernetes, null, null, null, null, null, null, null, null), new AdaptTestConfig(PlatformMode.openshift, null, "tls-jks-converter", null, "jimmidyson/pemtokeystore:v0.1.0", null, "tls-pem", null, "tls-jks"), new AdaptTestConfig(PlatformMode.openshift, null, "tls-jks-converter", null, "jimmidyson/pemtokeystore:v0.1.0", "tls-a", "tls-a", null, "tls-jks"), new AdaptTestConfig(PlatformMode.openshift, null, "tls-jks-converter", null, "jimmidyson/pemtokeystore:v0.1.0", null, "tls-pem", "jks-b", "jks-b"), new AdaptTestConfig(PlatformMode.openshift, "test-container-name", "test-container-name", "image/123", "image/123", "tls-a", "tls-a", "jks-b", "jks-b") };
for (final AdaptTestConfig tc : data) {
TreeMap configMap = new TreeMap() {
{
put(AutoTLSEnricher.Config.pemToJKSInitContainerName.name(), tc.initContainerNameConfig);
put(AutoTLSEnricher.Config.pemToJKSInitContainerImage.name(), tc.initContainerImageConfig);
put(AutoTLSEnricher.Config.tlsSecretVolumeName.name(), tc.tlsSecretVolumeNameConfig);
put(AutoTLSEnricher.Config.jksVolumeName.name(), tc.jksVolumeNameConfig);
}
};
final ProcessorConfig config = new ProcessorConfig(null, null, Collections.singletonMap(AutoTLSEnricher.ENRICHER_NAME, configMap));
final Properties projectProps = new Properties();
projectProps.put(PlatformMode.FABRIC8_EFFECTIVE_PLATFORM_MODE, tc.mode.name());
// Setup mock behaviour
new Expectations() {
{
project.getProperties();
result = projectProps;
project.getArtifactId();
result = "projectA";
minTimes = 0;
context.getProject();
result = project;
context.getConfig();
result = config;
}
};
AutoTLSEnricher enricher = new AutoTLSEnricher(context);
KubernetesListBuilder klb = new KubernetesListBuilder().addNewPodTemplateItem().withNewMetadata().and().withNewTemplate().withNewMetadata().and().withNewSpec().and().and().and();
enricher.adapt(klb);
PodTemplate pt = (PodTemplate) klb.getItems().get(0);
String initContainers = pt.getTemplate().getMetadata().getAnnotations().get(InitContainerHandler.INIT_CONTAINER_ANNOTATION);
assertEquals(tc.mode == PlatformMode.openshift, initContainers != null);
if (tc.mode == PlatformMode.kubernetes) {
continue;
}
JSONArray ja = new JSONArray(initContainers);
assertEquals(1, ja.length());
JSONObject jo = ja.getJSONObject(0);
assertEquals(tc.initContainerName, jo.get("name"));
assertEquals(tc.initContainerImage, jo.get("image"));
JSONArray mounts = jo.getJSONArray("volumeMounts");
assertEquals(2, mounts.length());
JSONObject mount = mounts.getJSONObject(0);
assertEquals(tc.tlsSecretVolumeName, mount.get("name"));
mount = mounts.getJSONObject(1);
assertEquals(tc.jksVolumeName, mount.get("name"));
}
}
use of io.fabric8.openshift.api.model.Project in project fabric8-maven-plugin by fabric8io.
the class AbstractSpringBootHealthCheckEnricherSupport method init.
@Before
public void init() {
String version = getSpringBootVersion();
this.propertyHelper = new SpringBootConfigurationHelper(version);
final MavenProject project = new MavenProject();
Set<Artifact> artifacts = new HashSet<>();
Artifact a = new DefaultArtifact("org.springframework.boot", "spring-boot", version, "compile", "jar", "", null);
a.setResolved(true);
artifacts.add(a);
project.setArtifacts(artifacts);
new Expectations() {
{
context.getProject();
result = project;
}
};
}
use of io.fabric8.openshift.api.model.Project in project fabric8-maven-plugin by fabric8io.
the class ImportMojo method createGithubProjectAndUserDetails.
protected UserDetails createGithubProjectAndUserDetails(KubernetesClient kubernetes, String namespace) throws MojoExecutionException {
log.info("Creating Project on GitHub");
String url = "https://api.github.com";
UserDetails userDetails = null;
String secretNamespace = getSecretNamespace();
ensureNamespaceExists(kubernetes, secretNamespace);
ConfigMap configMap = getSecretGitConfigMap(kubernetes, namespace, secretNamespace);
String host = convertToValidDnsLabel(currentUserName() + "-github.com");
String currentSecretName = configMap.getData().get(host);
if (currentSecretName == null) {
currentSecretName = createGitSecretName(namespace, host);
}
Secret secret = findOrCreateGitSecret(kubernetes, currentSecretName, host);
// FIXME: Rename the methods to be generic
// if empty or retrying lets re-enter the user/pwd
gitUserName = getGogsSecretField(kubernetes, secret, host, "username");
gitPassword = getGogsSecretField(kubernetes, secret, host, "password");
if (Strings.isNullOrBlank(gitEmail)) {
gitEmail = findEmailFromDotGitConfig();
}
createOrUpdateSecret(kubernetes, secret);
updateSecretGitConfigMap(kubernetes, secretNamespace, configMap, host, currentSecretName);
return new UserDetails("https://api.github.com", "https://api.github.com", gitUserName, gitPassword, gitEmail);
}
Aggregations