zhisheng17/flink-learning · error · IllegalArgumentException

Unrecognized service type: {}

Error message

Unrecognized service type: {}

What it means

getServiceName() switch over KubernetesConfigOptions.ServiceType has only REST_SERVICE and INTERNAL_SERVICE cases; any other (or future/unmapped) enum value falls into the default branch and throws this IllegalArgumentException.

Source

Thrown at flink-learning-k8s/flink-k8s/src/main/java/org/apache/flink/kubernetes/kubeclient/Fabric8FlinkKubeClient.java:386

						}),
			kubeClientExecutorService);
	}

	/**
	 * Get the Kubernetes service name.
	 *
	 * @param serviceType The service type
	 * @param clusterId The cluster id
	 * @return Return the Kubernetes service name if the service type is known.
	 */
	private String getServiceName(KubernetesService.ServiceType serviceType, String clusterId) {
		switch (serviceType) {
			case REST_SERVICE:
				return ExternalServiceDecorator.getExternalServiceName(clusterId);
			case INTERNAL_SERVICE:
				return InternalServiceDecorator.getInternalServiceName(clusterId);
			default:
				throw new IllegalArgumentException(
					"Unrecognized service type: " + serviceType.name());
		}
	}


	private void setOwnerReference(Deployment deployment, List<HasMetadata> resources) {
		final OwnerReference deploymentOwnerReference = new OwnerReferenceBuilder()
			.withName(deployment.getMetadata().getName())
			.withApiVersion(deployment.getApiVersion())
			.withUid(deployment.getMetadata().getUid())
			.withKind(deployment.getKind())
			.withController(true)
			.withBlockOwnerDeletion(true)
			.build();
		resources.forEach(resource ->
			resource.getMetadata().setOwnerReferences(Collections.singletonList(deploymentOwnerReference)));
	}

View on GitHub (pinned to d731cee761)

Solutions

  1. Upgrade or align all Flink Kubernetes dependencies so client and server use the same ServiceType enum.
  2. Check the classpath for duplicate/mismatched flink-kubernetes jars (shade conflicts).
  3. If adding a new service type in a fork, extend the switch to handle it.
  4. Log serviceType.name() at the call site to confirm which constant reaches the switch.

Example fix

// before: switch missing new enum constant
switch (serviceType) { case REST_SERVICE: ...; case INTERNAL_SERVICE: ...; default: throw ...; }
// after: handle or normalize unknown types explicitly
if (serviceType != REST_SERVICE && serviceType != INTERNAL_SERVICE) {
    throw new IllegalArgumentException("Unsupported service type: " + serviceType);
}
Defensive patterns

Strategy: type-guard

Validate before calling

// pre-check the enum value at boundaries
if (serviceType == null) throw new IllegalArgumentException("serviceType required");
Set<String> supported = Set.of("REST_SERVICE", "INTERNAL_SERVICE");
if (!supported.contains(serviceType.name())) throw new IllegalArgumentException("Unsupported: " + serviceType);

Type guard

static boolean isKnownServiceType(KubernetesConfigOptions.ServiceType t) {
    return t == KubernetesConfigOptions.ServiceType.REST_SERVICE
        || t == KubernetesConfigOptions.ServiceType.INTERNAL_SERVICE;
}

Try / catch

try {
    String name = client.getServiceName(serviceType);
} catch (IllegalArgumentException e) {
    // unknown enum constant — likely version skew; fail fast with context
    throw new IllegalStateException("Version skew in ServiceType: " + e.getMessage(), e);
}

Prevention

When it happens

Trigger: serviceName(serviceType) or updateServiceTargetPort called with a ServiceType not covered by the switch — practically only a new/renamed enum constant in the flink-kubernetes version not yet handled, or a deserialized enum from a different version.

Common situations: Mixing Flink client and server jars of different versions where the ServiceType enum gained a constant; custom extensions of the decorator flow passing an unexpected service type; binary-incompatible shaded classpath.

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


AI-assisted analysis of zhisheng17/flink-learning@d731cee761 (2026-09-06). Data as JSON: /api/errors/10cd819abe61efc4. Report an issue: GitHub.