class AbstractKubernetesProfileEnvironmentPostProcessor implements EnvironmentPostProcessor, Ordered {

	private static final DeferredLog LOG = new DeferredLog();

	private static final String NAMESPACE_PATH_PROPERTY = "spring.cloud.kubernetes.client.serviceAccountNamespacePath";

	protected static final String NAMESPACE_PROPERTY = "spring.cloud.kubernetes.client.namespace";

	private static final String PROPERTY_SOURCE_NAME = "KUBERNETES_NAMESPACE_PROPERTY_SOURCE";

	// Before ConfigFileApplicationListener so values there can use these ones
	private static final int ORDER = ConfigDataEnvironmentPostProcessor.ORDER - 1;

	/**
	 * Profile name.
	 */
	public static final String KUBERNETES_PROFILE = "kubernetes";

	@Override
	public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) {

		application.addInitializers(ctx -> LOG.replayTo(AbstractKubernetesProfileEnvironmentPostProcessor.class));

		if (CloudPlatform.KUBERNETES.isActive(environment)) {
			addNamespaceFromServiceAccountFile(environment);
			addKubernetesProfileIfMissing(environment);
		}
	}

	protected abstract boolean isInsideKubernetes(Environment environment);

	private boolean hasKubernetesProfile(Environment environment) {
		return Arrays.stream(environment.getActiveProfiles()).anyMatch(KUBERNETES_PROFILE::equalsIgnoreCase);
	}

	@Override
	public int getOrder() {
		return ORDER;
	}

	private void addKubernetesProfileIfMissing(ConfigurableEnvironment environment) {
		if (isInsideKubernetes(environment)) {
			if (hasKubernetesProfile(environment)) {
				LOG.debug("'kubernetes' already in list of active profiles");
			}
			else {
				LOG.debug("Adding 'kubernetes' to list of active profiles");
				environment.addActiveProfile(KUBERNETES_PROFILE);
			}
		}
		else {
			LOG.warn("Not running inside kubernetes. Skipping 'kubernetes' profile activation.");
		}
	}

	private void addNamespaceFromServiceAccountFile(ConfigurableEnvironment environment) {<FILL_FUNCTION_BODY>}

}

		String serviceAccountNamespacePathString = environment.getProperty(NAMESPACE_PATH_PROPERTY,
				SERVICE_ACCOUNT_NAMESPACE_PATH);
		String namespace = KubernetesNamespaceProvider
				.getNamespaceFromServiceAccountFile(serviceAccountNamespacePathString);
		if (StringUtils.hasText(namespace)) {
			environment.getPropertySources().addLast(new MapPropertySource(PROPERTY_SOURCE_NAME,
					Collections.singletonMap(NAMESPACE_PROPERTY, namespace)));
		}

	
<no_super_class>