diff --git a/CHANGELOG.md b/CHANGELOG.md index a1227c57840..53bf3724f21 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,7 +15,7 @@ * Remove `setIntVal`, `setStrVal`, `setKind` setters from `IntOrString` class to avoid invalid combinations * Fix #3889 : remove piped stream for file download * Fix #1285: removed references to manually calling registerCustomKind -* Fix #3334: adding basic support for server side apply +* Fix #3334: adding basic support for server side apply. Use patch(PatchContext.of(PatchType.SERVER_SIDE_APPLY), service), or new PatchContext.Builder().withPatchType(PatchType.SERVER_SIDE_APPLY).withForce(true).build() to override conflicts. #### Dependency Upgrade * Fix #3788: Point CamelK Extension model to latest released version v1.8.0 diff --git a/kubernetes-client-api/src/test/java/io/fabric8/kubernetes/client/ConfigTest.java b/kubernetes-client-api/src/test/java/io/fabric8/kubernetes/client/ConfigTest.java index d1e3bad5938..aea85da034b 100644 --- a/kubernetes-client-api/src/test/java/io/fabric8/kubernetes/client/ConfigTest.java +++ b/kubernetes-client-api/src/test/java/io/fabric8/kubernetes/client/ConfigTest.java @@ -54,9 +54,11 @@ public class ConfigTest { private static final String TEST_KUBECONFIG_EXEC_FILE = Utils.filePath(ConfigTest.class.getResource("/test-kubeconfig-exec")); private static final String TEST_TOKEN_GENERATOR_FILE = Utils.filePath(ConfigTest.class.getResource("/token-generator")); - private static final String TEST_KUBECONFIG_EXEC_WIN_FILE = Utils.filePath(ConfigTest.class.getResource("/test-kubeconfig-exec-win")); + private static final String TEST_KUBECONFIG_EXEC_WIN_FILE = Utils + .filePath(ConfigTest.class.getResource("/test-kubeconfig-exec-win")); - private static final String TEST_KUBECONFIG_NO_CURRENT_CONTEXT_FILE = Utils.filePath(ConfigTest.class.getResource("/test-kubeconfig-nocurrentctxt.yml")); + private static final String TEST_KUBECONFIG_NO_CURRENT_CONTEXT_FILE = Utils + .filePath(ConfigTest.class.getResource("/test-kubeconfig-nocurrentctxt.yml")); @BeforeEach public void setUp() { @@ -146,41 +148,40 @@ void testWithSystemProperties() { @Test void testWithBuilder() { Config config = new ConfigBuilder() - .withMasterUrl("http://somehost:80") - .withApiVersion("v1") - .withNamespace("testns") - .withOauthToken("token") - .withUsername("user") - .withPassword("pass") - .withTrustCerts(true) - .withDisableHostnameVerification(true) - .withCaCertFile("/path/to/cert") - .withCaCertData("cacertdata") - .withClientCertFile("/path/to/clientcert") - .withClientCertData("clientcertdata") - .withClientKeyFile("/path/to/clientkey") - .withClientKeyData("clientkeydata") - .withClientKeyAlgo("algo") - .withClientKeyPassphrase("passphrase") - .withMaxConcurrentRequests(120) - .withMaxConcurrentRequestsPerHost(20) - .withWatchReconnectInterval(5000) - .withWatchReconnectLimit(5) - .withRequestTimeout(5000) - .withUploadConnectionTimeout(60000) - .withUploadRequestTimeout(600000) - .withHttpProxy("httpProxy") - .withTlsVersions(TlsVersion.TLS_1_2, TlsVersion.TLS_1_1) - .withTrustStoreFile("/path/to/truststore") - .withTrustStorePassphrase("truststorePassphrase") - .withKeyStoreFile("/path/to/keystore") - .withKeyStorePassphrase("keystorePassphrase") - .build(); + .withMasterUrl("http://somehost:80") + .withApiVersion("v1") + .withNamespace("testns") + .withOauthToken("token") + .withUsername("user") + .withPassword("pass") + .withTrustCerts(true) + .withDisableHostnameVerification(true) + .withCaCertFile("/path/to/cert") + .withCaCertData("cacertdata") + .withClientCertFile("/path/to/clientcert") + .withClientCertData("clientcertdata") + .withClientKeyFile("/path/to/clientkey") + .withClientKeyData("clientkeydata") + .withClientKeyAlgo("algo") + .withClientKeyPassphrase("passphrase") + .withMaxConcurrentRequests(120) + .withMaxConcurrentRequestsPerHost(20) + .withWatchReconnectInterval(5000) + .withWatchReconnectLimit(5) + .withRequestTimeout(5000) + .withUploadConnectionTimeout(60000) + .withUploadRequestTimeout(600000) + .withHttpProxy("httpProxy") + .withTlsVersions(TlsVersion.TLS_1_2, TlsVersion.TLS_1_1) + .withTrustStoreFile("/path/to/truststore") + .withTrustStorePassphrase("truststorePassphrase") + .withKeyStoreFile("/path/to/keystore") + .withKeyStorePassphrase("keystorePassphrase") + .build(); assertConfig(config); } - @Test void testWithBuilderAndSystemProperties() { System.setProperty(Config.KUBERNETES_MASTER_SYSTEM_PROPERTY, "http://tobeoverriden:80"); @@ -218,9 +219,9 @@ void testWithBuilderAndSystemProperties() { System.setProperty(Config.KUBERNETES_UPLOAD_REQUEST_TIMEOUT_SYSTEM_PROPERTY, "600000"); Config config = new ConfigBuilder() - .withMasterUrl("http://somehost:80") - .withNamespace("testns") - .build(); + .withMasterUrl("http://somehost:80") + .withNamespace("testns") + .build(); assertConfig(config); } @@ -307,8 +308,8 @@ void testWithKubeConfigAndSytemPropertiesAndBuilder() { System.setProperty(Config.KUBERNETES_MASTER_SYSTEM_PROPERTY, "http://somehost:80"); Config config = new ConfigBuilder() - .withNamespace("testns2") - .build(); + .withNamespace("testns2") + .build(); assertNotNull(config); assertEquals("http://somehost:80/", config.getMasterUrl()); @@ -387,8 +388,8 @@ void testWithNamespacePathAndSytemPropertiesAndBuilder() { System.setProperty(Config.KUBERNETES_NAMESPACE_SYSTEM_PROPERTY, "tobeoverriden"); Config config = new ConfigBuilder() - .withNamespace("testns2") - .build(); + .withNamespace("testns2") + .build(); assertNotNull(config); assertEquals("http://somehost:80/", config.getMasterUrl()); @@ -397,16 +398,16 @@ void testWithNamespacePathAndSytemPropertiesAndBuilder() { @Test void testWithCustomHeader() { - Map customHeaders = new HashMap<>(); - customHeaders.put("user-id","test-user"); - customHeaders.put("cluster-id","test-cluster"); + Map customHeaders = new HashMap<>(); + customHeaders.put("user-id", "test-user"); + customHeaders.put("cluster-id", "test-cluster"); Config config = new ConfigBuilder() - .withCustomHeaders(customHeaders) - .build(); + .withCustomHeaders(customHeaders) + .build(); assertNotNull(config); assertNotNull(config.getCustomHeaders()); - assertEquals(2,config.getCustomHeaders().size()); + assertEquals(2, config.getCustomHeaders().size()); } @Test @@ -419,12 +420,12 @@ void shouldSetImpersonateUsernameAndGroupFromSystemProperty() { extras.put("c", Collections.singletonList("d")); final Config config = new ConfigBuilder() - .withImpersonateUsername("a") - .withImpersonateExtras(extras) - .build(); + .withImpersonateUsername("a") + .withImpersonateExtras(extras) + .build(); assertEquals("a", config.getImpersonateUsername()); - assertArrayEquals(new String[]{"group"}, config.getImpersonateGroups()); + assertArrayEquals(new String[] { "group" }, config.getImpersonateGroups()); assertEquals(Collections.singletonList("d"), config.getImpersonateExtras().get("c")); } @@ -449,8 +450,8 @@ void honorClientAuthenticatorCommands() throws Exception { void shouldBeUsedTokenSuppliedByProvider() { Config config = new ConfigBuilder().withOauthToken("oauthToken") - .withOauthTokenProvider(() -> "PROVIDER_TOKEN") - .build(); + .withOauthTokenProvider(() -> "PROVIDER_TOKEN") + .build(); assertEquals("PROVIDER_TOKEN", config.getOauthToken()); } @@ -463,13 +464,14 @@ void shouldHonorDefaultWebsocketPingInterval() { } @Test - void testKubeConfigWithAuthConfigProvider() throws URISyntaxException { + void testKubeConfigWithAuthConfigProvider() throws URISyntaxException { System.setProperty("kubeconfig", new File(getClass().getResource("/test-kubeconfig").toURI()).getAbsolutePath()); Config config = Config.autoConfigure("production/172-28-128-4:8443/mmosley"); assertEquals("https://172.28.128.4:8443/", config.getMasterUrl()); - assertEquals("eyJraWQiOiJDTj1vaWRjaWRwLnRyZW1vbG8ubGFuLCBPVT1EZW1vLCBPPVRybWVvbG8gU2VjdXJpdHksIEw9QXJsaW5ndG9uLCBTVD1WaXJnaW5pYSwgQz1VUy1DTj1rdWJlLWNhLTEyMDIxNDc5MjEwMzYwNzMyMTUyIiwiYWxnIjoiUlMyNTYifQ.eyJpc3MiOiJodHRwczovL29pZGNpZHAudHJlbW9sby5sYW46ODQ0My9hdXRoL2lkcC9PaWRjSWRQIiwiYXVkIjoia3ViZXJuZXRlcyIsImV4cCI6MTQ4MzU0OTUxMSwianRpIjoiMm96US15TXdFcHV4WDlHZUhQdy1hZyIsImlhdCI6MTQ4MzU0OTQ1MSwibmJmIjoxNDgzNTQ5MzMxLCJzdWIiOiI0YWViMzdiYS1iNjQ1LT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xIwePzEkT4DfcQthoZdy9ucNvvLoi1DIC-UocFD8HLs8LYKEqSxQvOcvnThbObJ9af71EwmuE21fO5KzMW20KtAeget1gnldOosPtz1G5EwvaQ401-RPQzPGMVBld0_zMCAwZttJ4knw", + config.getOauthToken()); } @Test @@ -537,7 +539,7 @@ private void assertConfig(Config config) { assertEquals(60000, config.getRequestConfig().getUploadConnectionTimeout()); assertEquals(600000, config.getRequestConfig().getUploadRequestTimeout()); - assertArrayEquals(new TlsVersion[]{TlsVersion.TLS_1_2, TlsVersion.TLS_1_1}, config.getTlsVersions()); + assertArrayEquals(new TlsVersion[] { TlsVersion.TLS_1_2, TlsVersion.TLS_1_1 }, config.getTlsVersions()); assertEquals("/path/to/truststore", config.getTrustStoreFile()); assertEquals("truststorePassphrase", config.getTrustStorePassphrase()); @@ -556,13 +558,14 @@ void testGetAuthenticatorCommandFromExecConfig() throws IOException { boolean isNewFileCreated = commandFile.createNewFile(); String systemPathValue = getTestPathValue(commandFolder); ExecConfig execConfig = new ExecConfigBuilder() - .withApiVersion("client.authentication.k8s.io/v1alpha1") - .addToArgs("--region", "us-west2", "eks", "get-token", "--cluster-name", "api-eks.example.com") - .withCommand("aws") - .build(); + .withApiVersion("client.authentication.k8s.io/v1alpha1") + .addToArgs("--region", "us-west2", "eks", "get-token", "--cluster-name", "api-eks.example.com") + .withCommand("aws") + .build(); // When - List processBuilderArgs = Config.getAuthenticatorCommandFromExecConfig(execConfig, new File("~/.kube/config"), systemPathValue); + List processBuilderArgs = Config.getAuthenticatorCommandFromExecConfig(execConfig, new File("~/.kube/config"), + systemPathValue); // Then assertTrue(isNewFileCreated); @@ -588,12 +591,12 @@ private void assertPlatformPrefixes(List processBuilderArgs) { private String getTestPathValue(File commandFolder) { if (Utils.isWindowsOperatingSystem()) { return "C:\\Program Files\\Java\\jdk14.0_23\\bin" + File.pathSeparator + - commandFolder.getAbsolutePath() + File.pathSeparator + - "C:\\Program Files\\Apache Software Foundation\\apache-maven-3.3.1"; + commandFolder.getAbsolutePath() + File.pathSeparator + + "C:\\Program Files\\Apache Software Foundation\\apache-maven-3.3.1"; } else { return "/usr/java/jdk-14.0.1/bin" + File.pathSeparator + - commandFolder.getAbsolutePath() + File.pathSeparator + - "/opt/apache-maven/bin"; + commandFolder.getAbsolutePath() + File.pathSeparator + + "/opt/apache-maven/bin"; } } }