use of org.eclipse.jkube.kit.common.RegistryConfig in project jkube by eclipse.
the class OpenshiftBuildService method checkOrCreatePullSecret.
private boolean checkOrCreatePullSecret(OpenShiftClient client, KubernetesListBuilder builder, String pullSecretName, ImageConfiguration imageConfig) throws Exception {
BuildConfiguration buildConfig = imageConfig.getBuildConfiguration();
String fromImage;
if (buildConfig.isDockerFileMode()) {
fromImage = extractBaseFromDockerfile(jKubeConfiguration, buildConfig);
} else {
fromImage = extractBaseFromConfiguration(buildConfig);
}
String pullRegistry = EnvUtil.firstRegistryOf(new ImageName(fromImage).getRegistry(), jKubeConfiguration.getRegistryConfig().getRegistry(), jKubeConfiguration.getRegistryConfig().getRegistry());
if (pullRegistry != null) {
RegistryConfig registryConfig = jKubeConfiguration.getRegistryConfig();
final AuthConfig authConfig = new AuthConfigFactory(log).createAuthConfig(false, registryConfig.isSkipExtendedAuth(), registryConfig.getAuthConfig(), registryConfig.getSettings(), null, pullRegistry, registryConfig.getPasswordDecryptionMethod());
final Secret secret = Optional.ofNullable(pullSecretName).map(psn -> client.secrets().inNamespace(applicableOpenShiftNamespace).withName(psn).get()).orElse(null);
if (secret != null) {
log.info("Adding to Secret %s", pullSecretName);
return updateSecret(client, pullSecretName, secret.getData());
}
if (authConfig != null) {
JsonObject auths = new JsonObject();
JsonObject auth = new JsonObject();
JsonObject item = new JsonObject();
String authString = authConfig.getUsername() + ":" + authConfig.getPassword();
item.add("auth", new JsonPrimitive(Base64.encodeBase64String(authString.getBytes(StandardCharsets.UTF_8))));
auth.add(pullRegistry, item);
auths.add("auths", auth);
String credentials = Base64.encodeBase64String(auths.toString().getBytes(StandardCharsets.UTF_8));
Map<String, String> data = new HashMap<>();
data.put(".dockerconfigjson", credentials);
log.info("Creating Secret");
builder.addNewSecretItem().withNewMetadata().withName(pullSecretName).endMetadata().withData(data).withType("kubernetes.io/dockerconfigjson").endSecretItem();
return true;
}
}
return false;
}
use of org.eclipse.jkube.kit.common.RegistryConfig in project jkube by eclipse.
the class OpenShiftBuildServiceTest method push_withValidImage_shouldLogWarning.
@Test
public void push_withValidImage_shouldLogWarning() throws JKubeServiceException {
// Given
when(jKubeServiceHub.getLog()).thenReturn(mockedKitLogger);
// When
new OpenshiftBuildService(jKubeServiceHub).push(Collections.singletonList(imageConfiguration), 0, new RegistryConfig(), false);
// Then
verify(mockedKitLogger, times(1)).warn("Image is pushed to OpenShift's internal registry during oc:build goal. Skipping...");
}
use of org.eclipse.jkube.kit.common.RegistryConfig in project jkube by eclipse.
the class OpenShiftBuildServiceTest method push_withEmptyList_shouldNotLogWarning.
@Test
public void push_withEmptyList_shouldNotLogWarning() throws JKubeServiceException {
// Given
when(jKubeServiceHub.getLog()).thenReturn(mockedKitLogger);
// When
new OpenshiftBuildService(jKubeServiceHub).push(Collections.emptyList(), 0, new RegistryConfig(), false);
// Then
verify(mockedKitLogger, times(0)).warn("Image is pushed to OpenShift's internal registry during oc:build goal. Skipping...");
}
use of org.eclipse.jkube.kit.common.RegistryConfig in project jkube by eclipse.
the class OpenshiftBuildServiceIntegrationTest method init.
@Before
public void init() throws Exception {
final KitLogger logger = new KitLogger.StdoutLogger();
baseDirectory = temporaryFolder.newFolder("openshift-build-service");
target = temporaryFolder.newFolder("openshift-build-service", "target");
final File emptyDockerBuildTar = new File(target, "docker-build.tar");
FileUtils.touch(emptyDockerBuildTar);
baseDir = baseDirectory.getAbsolutePath();
projectName = "myapp";
FileUtils.deleteDirectory(new File(baseDir, projectName));
final File dockerFile = new File(baseDir, "Docker.tar");
FileUtils.touch(dockerFile);
openshiftHelper = mockStatic(OpenshiftHelper.class);
openshiftHelper.when(() -> OpenshiftHelper.isOpenShift(eq(mockServer.getOpenshiftClient()))).thenReturn(true);
jKubeBuildTarArchiver = mockConstruction(JKubeBuildTarArchiver.class, (mock, ctx) -> when(mock.createArchive(any(File.class), any(BuildDirs.class), eq(ArchiveCompression.none))).thenReturn(emptyDockerBuildTar));
mockedResourceConfig = mock(ResourceConfig.class, RETURNS_DEEP_STUBS);
when(mockedResourceConfig.getNamespace()).thenReturn("ns1");
jKubeServiceHub = mock(JKubeServiceHub.class, RETURNS_DEEP_STUBS);
when(jKubeServiceHub.getClusterAccess().createDefaultClient()).thenReturn(mockServer.getOpenshiftClient());
when(jKubeServiceHub.getLog()).thenReturn(logger);
when(jKubeServiceHub.getDockerServiceHub().getArchiveService()).thenReturn(new ArchiveService(AssemblyManager.getInstance(), logger));
when(jKubeServiceHub.getBuildServiceConfig().getBuildDirectory()).thenReturn(target.getAbsolutePath());
when(jKubeServiceHub.getConfiguration()).thenReturn(JKubeConfiguration.builder().outputDirectory(target.getAbsolutePath()).project(JavaProject.builder().baseDirectory(baseDirectory).buildDirectory(target).build()).registryConfig(RegistryConfig.builder().build()).build());
image = ImageConfiguration.builder().name(projectName).build(BuildConfiguration.builder().from(projectName).build()).build();
defaultConfig = BuildServiceConfig.builder().buildDirectory(baseDir).buildRecreateMode(BuildRecreateMode.none).s2iBuildNameSuffix("-s2i-suffix2").resourceConfig(mockedResourceConfig).jKubeBuildStrategy(JKubeBuildStrategy.s2i);
defaultConfigSecret = defaultConfig.build().toBuilder().openshiftPullSecret("pullsecret-fabric8");
dockerImageConfig = defaultConfig.build().toBuilder().buildOutputKind("DockerImage");
dockerImageConfigSecret = defaultConfig.build().toBuilder().openshiftPullSecret("pullsecret-fabric8").openshiftPushSecret("pushsecret-fabric8").buildOutputKind("DockerImage");
Serialization.jsonMapper().disable(SerializationFeature.INDENT_OUTPUT);
}
Aggregations