@Test public void testConfigureAuthDataStatefulSet() { byte[] testBytes = new byte[]{0, 1, 2, 3, 4}; CoreV1Api coreV1Api = mock(CoreV1Api.class); KubernetesSecretsTokenAuthProvider kubernetesSecretsTokenAuthProvider = new KubernetesSecretsTokenAuthProvider(); kubernetesSecretsTokenAuthProvider.initialize(coreV1Api, testBytes, (fd) -> "default"); V1StatefulSet statefulSet = new V1StatefulSet(); statefulSet.setSpec( new V1StatefulSetSpec().template( new V1PodTemplateSpec().spec( new V1PodSpec().containers( Collections.singletonList(new V1Container()))))); FunctionAuthData functionAuthData = FunctionAuthData.builder().data("foo".getBytes()).build(); kubernetesSecretsTokenAuthProvider.configureAuthDataStatefulSet(statefulSet, Optional.of(functionAuthData)); Assert.assertEquals(statefulSet.getSpec().getTemplate().getSpec().getVolumes().size(), 1); Assert.assertEquals(statefulSet.getSpec().getTemplate().getSpec().getVolumes().get(0).getName(), "function-auth"); Assert.assertEquals(statefulSet.getSpec().getTemplate().getSpec().getVolumes().get(0).getSecret().getSecretName(), "pf-secret-foo"); Assert.assertEquals(statefulSet.getSpec().getTemplate().getSpec().getContainers().size(), 1); Assert.assertEquals(statefulSet.getSpec().getTemplate().getSpec().getContainers().get(0).getVolumeMounts().size(), 1); Assert.assertEquals(statefulSet.getSpec().getTemplate().getSpec().getContainers().get(0).getVolumeMounts().get(0).getName(), "function-auth"); Assert.assertEquals(statefulSet.getSpec().getTemplate().getSpec().getContainers().get(0).getVolumeMounts().get(0).getMountPath(), "/etc/auth"); }
@Override public void configureAuthDataStatefulSet(V1StatefulSet statefulSet, Optional<FunctionAuthData> functionAuthData) { if (!functionAuthData.isPresent()) { return; } V1PodSpec podSpec = statefulSet.getSpec().getTemplate().getSpec(); podSpec.setVolumes(Collections.singletonList( new V1Volume() .name(SECRET_NAME) .secret( new V1SecretVolumeSource() .secretName(getSecretName(new String(functionAuthData.get().getData()))) .defaultMode(256)))); podSpec.getContainers().forEach(container -> container.setVolumeMounts(Collections.singletonList( new V1VolumeMount() .name(SECRET_NAME) .mountPath(DEFAULT_SECRET_MOUNT_DIR) .readOnly(true)))); }
KubernetesSecretsTokenAuthProvider implements KubernetesFunctionAuthProvider { @Override public void configureAuthDataStatefulSet(V1StatefulSet statefulSet, Optional<FunctionAuthData> functionAuthData) { if (!functionAuthData.isPresent()) { return; } V1PodSpec podSpec = statefulSet.getSpec().getTemplate().getSpec(); podSpec.setVolumes(Collections.singletonList( new V1Volume() .name(SECRET_NAME) .secret( new V1SecretVolumeSource() .secretName(getSecretName(new String(functionAuthData.get().getData()))) .defaultMode(256)))); podSpec.getContainers().forEach(container -> container.setVolumeMounts(Collections.singletonList( new V1VolumeMount() .name(SECRET_NAME) .mountPath(DEFAULT_SECRET_MOUNT_DIR) .readOnly(true)))); } }
KubernetesSecretsTokenAuthProvider implements KubernetesFunctionAuthProvider { @Override public void configureAuthDataStatefulSet(V1StatefulSet statefulSet, Optional<FunctionAuthData> functionAuthData) { if (!functionAuthData.isPresent()) { return; } V1PodSpec podSpec = statefulSet.getSpec().getTemplate().getSpec(); podSpec.setVolumes(Collections.singletonList( new V1Volume() .name(SECRET_NAME) .secret( new V1SecretVolumeSource() .secretName(getSecretName(new String(functionAuthData.get().getData()))) .defaultMode(256)))); podSpec.getContainers().forEach(container -> container.setVolumeMounts(Collections.singletonList( new V1VolumeMount() .name(SECRET_NAME) .mountPath(DEFAULT_SECRET_MOUNT_DIR) .readOnly(true)))); }  }
KubernetesSecretsTokenAuthProvider implements KubernetesFunctionAuthProvider { @Override public void configureAuthDataStatefulSet(V1StatefulSet statefulSet, Optional<FunctionAuthData> functionAuthData) { if (!functionAuthData.isPresent()) { return; } V1PodSpec podSpec = statefulSet.getSpec().getTemplate().getSpec(); podSpec.setVolumes(Collections.singletonList( new V1Volume() .name(SECRET_NAME) .secret( new V1SecretVolumeSource() .secretName(getSecretName(new String(functionAuthData.get().getData()))) .defaultMode(256)))); podSpec.getContainers().forEach(container -> container.setVolumeMounts(Collections.singletonList( new V1VolumeMount() .name(SECRET_NAME) .mountPath(DEFAULT_SECRET_MOUNT_DIR) .readOnly(true)))); }  @Override void initialize(CoreV1Api coreClient); @Override void setCaBytes(byte[] caBytes); @Override void setNamespaceProviderFunc(java.util.function.Function<Function.FunctionDetails, String> getNamespaceFromDetails); @Override void configureAuthDataStatefulSet(V1StatefulSet statefulSet, Optional<FunctionAuthData> functionAuthData); @Override void configureAuthenticationConfig(AuthenticationConfig authConfig, Optional<FunctionAuthData> functionAuthData); @Override Optional<FunctionAuthData> cacheAuthData(Function.FunctionDetails funcDetails,
                                                    AuthenticationDataSource authenticationDataSource); @Override void cleanUpAuthData(Function.FunctionDetails funcDetails, Optional<FunctionAuthData> functionAuthData); @Override Optional<FunctionAuthData> updateAuthData(Function.FunctionDetails funcDetails,
                                                     Optional<FunctionAuthData> existingFunctionAuthData,
                                                     AuthenticationDataSource authenticationDataSource); }
KubernetesSecretsTokenAuthProvider implements KubernetesFunctionAuthProvider { @Override public void configureAuthDataStatefulSet(V1StatefulSet statefulSet, Optional<FunctionAuthData> functionAuthData) { if (!functionAuthData.isPresent()) { return; } V1PodSpec podSpec = statefulSet.getSpec().getTemplate().getSpec(); podSpec.setVolumes(Collections.singletonList( new V1Volume() .name(SECRET_NAME) .secret( new V1SecretVolumeSource() .secretName(getSecretName(new String(functionAuthData.get().getData()))) .defaultMode(256)))); podSpec.getContainers().forEach(container -> container.setVolumeMounts(Collections.singletonList( new V1VolumeMount() .name(SECRET_NAME) .mountPath(DEFAULT_SECRET_MOUNT_DIR) .readOnly(true)))); }  @Override void initialize(CoreV1Api coreClient); @Override void setCaBytes(byte[] caBytes); @Override void setNamespaceProviderFunc(java.util.function.Function<Function.FunctionDetails, String> getNamespaceFromDetails); @Override void configureAuthDataStatefulSet(V1StatefulSet statefulSet, Optional<FunctionAuthData> functionAuthData); @Override void configureAuthenticationConfig(AuthenticationConfig authConfig, Optional<FunctionAuthData> functionAuthData); @Override Optional<FunctionAuthData> cacheAuthData(Function.FunctionDetails funcDetails,
                                                    AuthenticationDataSource authenticationDataSource); @Override void cleanUpAuthData(Function.FunctionDetails funcDetails, Optional<FunctionAuthData> functionAuthData); @Override Optional<FunctionAuthData> updateAuthData(Function.FunctionDetails funcDetails,
                                                     Optional<FunctionAuthData> existingFunctionAuthData,
                                                     AuthenticationDataSource authenticationDataSource);  }