io.fabric8.kubernetes.internal.KubernetesDeserializer Java Examples

The following examples show how to use io.fabric8.kubernetes.internal.KubernetesDeserializer. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: KubernetesConnection.java    From vault-crd with Apache License 2.0 6 votes vote down vote up
@Bean
public MixedOperation<Vault, VaultList, DoneableVault, Resource<Vault, DoneableVault>> customResource(
        KubernetesClient client, @Value("${kubernetes.crd.name}") String crdName) {
    Resource<CustomResourceDefinition, DoneableCustomResourceDefinition> crdResource
            = client.customResourceDefinitions().withName(crdName);

    // Hack for bug in Kubernetes-Client for CRDs https://github.com/fabric8io/kubernetes-client/issues/1099
    String kind = StringUtils.substringAfter(crdName, ".") + "/v1#Vault";
    KubernetesDeserializer.registerCustomKind(kind, Vault.class);

    CustomResourceDefinition customResourceDefinition = crdResource.get();
    if (customResourceDefinition == null) {
        log.error("Please first apply custom resource definition and then restart vault-crd");
        System.exit(1);
    }

    return client.customResources(customResourceDefinition, Vault.class, VaultList.class, DoneableVault.class);
}
 
Example #2
Source File: CustomResourceOperationsImpl.java    From kubernetes-client with Apache License 2.0 6 votes vote down vote up
public CustomResourceOperationsImpl(CustomResourceOperationContext context) {
  super(context.withApiGroupName(context.getCrdContext().getGroup())
    .withApiGroupVersion(context.getCrdContext().getVersion())
    .withPlural(context.getCrdContext().getPlural()));

  this.type = context.getType();
  this.listType = context.getListType();
  this.doneableType = context.getDoneableType();

  this.resourceNamespaced = resourceNamespaced(context.getCrdContext());
  this.apiVersion = getAPIGroup() + "/" + getAPIVersion();

  KubernetesDeserializer.registerCustomKind(apiVersion, kind(context.getCrdContext()), type);
  if (KubernetesResource.class.isAssignableFrom(listType)) {
    KubernetesDeserializer.registerCustomKind(listType.getSimpleName(), (Class<? extends KubernetesResource>) listType);
  }
}
 
Example #3
Source File: CustomResourceOperationsImplTest.java    From kubernetes-client with Apache License 2.0 6 votes vote down vote up
private void assertForContext(CustomResourceOperationContext context) throws IOException {
  // CustomResourceOperationsImpl constructor invokes KubernetesDeserializer::registerCustomKind
  new CustomResourceOperationsImpl<>(context);

  JsonFactory factory = new MappingJsonFactory();
  JsonParser parser = factory.createParser("{\n" +
    "    \"apiVersion\": \"custom.group/v1alpha1\",\n" +
    "    \"kind\": \"MyCustomResource\"\n" +
    "}");

  KubernetesDeserializer deserializer = new KubernetesDeserializer();
  KubernetesResource resource = deserializer.deserialize(parser, null);

  assertThat(resource, instanceOf(MyCustomResource.class));
  assertEquals("custom.group/v1alpha1", ((MyCustomResource) resource).getApiVersion());
}
 
Example #4
Source File: Operator.java    From java-operator-sdk with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("rawtypes")
private <R extends CustomResource> void registerController(ResourceController<R> controller,
                                                           boolean watchAllNamespaces, Retry retry, String... targetNamespaces) throws OperatorException {
    Class<R> resClass = getCustomResourceClass(controller);
    CustomResourceDefinition crd = getCustomResourceDefinitionForController(controller);
    KubernetesDeserializer.registerCustomKind(getApiVersion(crd), getKind(crd), resClass);

    MixedOperation client = k8sClient.customResources(crd, resClass, CustomResourceList.class, getCustomResourceDoneableClass(controller));
    EventDispatcher eventDispatcher = new EventDispatcher(controller,
            getDefaultFinalizer(controller), new EventDispatcher.CustomResourceReplaceFacade(client));
    EventScheduler eventScheduler = new EventScheduler(eventDispatcher, retry, ControllerUtils.getGenerationEventProcessing(controller));
    registerWatches(controller, client, resClass, watchAllNamespaces, targetNamespaces, eventScheduler);
}
 
Example #5
Source File: AptReader.java    From dekorate with Apache License 2.0 5 votes vote down vote up
private void hack() {
  // InternalResourceMappingProvider not loaded in FMP probably due to Kubernetes-Client collisions
  StreamSupport.stream(ServiceLoader.load(KubernetesResourceMappingProvider.class, AptReader.class.getClassLoader()).spliterator(), false)
    .map(KubernetesResourceMappingProvider::getMappings)
    .map(Map::entrySet).flatMap(Set::stream)
    .forEach(e -> {
      if (e.getKey().contains("#")){
        final String[] apiKind = e.getKey().split("#");
        KubernetesDeserializer.registerCustomKind(apiKind[0], apiKind[1], e.getValue());
      } else {
        KubernetesDeserializer.registerCustomKind(e.getKey(), e.getValue());
      }
    });
}
 
Example #6
Source File: Crds.java    From strimzi-kafka-operator with Apache License 2.0 5 votes vote down vote up
/**
 * Register custom resource kinds with {@link KubernetesDeserializer} so Fabric8 knows how to deserialize them.
 */
public static void registerCustomKinds() {
    for (Class<? extends CustomResource> crdClass : CRDS) {
        for (String version : apiVersions(crdClass)) {
            KubernetesDeserializer.registerCustomKind(version, kind(crdClass), crdClass);
        }
    }
}
 
Example #7
Source File: CoreCrd.java    From enmasse with Apache License 2.0 5 votes vote down vote up
public static void registerCustomCrds() {
    KubernetesDeserializer.registerCustomKind(API_VERSION, Address.KIND, Address.class);
    KubernetesDeserializer.registerCustomKind(API_VERSION, AddressList.KIND, AddressList.class);

    KubernetesDeserializer.registerCustomKind(API_VERSION, AddressSpace.KIND, AddressSpace.class);
    KubernetesDeserializer.registerCustomKind(API_VERSION, AddressSpaceList.KIND, AddressSpaceList.class);

    KubernetesDeserializer.registerCustomKind(API_VERSION, AddressSpaceSchema.KIND, AddressSpaceSchema.class);
    KubernetesDeserializer.registerCustomKind(API_VERSION, AddressSpaceSchemaList.KIND, AddressSpaceSchemaList.class);

    KubernetesDeserializer.registerCustomKind(API_VERSION_BETA2, "MessagingInfrastructure", MessagingInfrastructure.class);
    KubernetesDeserializer.registerCustomKind(API_VERSION_BETA2, "MessagingInfrastructureList", MessagingInfrastructureList.class);

    KubernetesDeserializer.registerCustomKind(API_VERSION_BETA2, "MessagingTenant", MessagingTenant.class);
    KubernetesDeserializer.registerCustomKind(API_VERSION_BETA2, "MessagingTenantList", MessagingTenantList.class);

    KubernetesDeserializer.registerCustomKind(API_VERSION_BETA2, "MessagingAddress", MessagingAddress.class);
    KubernetesDeserializer.registerCustomKind(API_VERSION_BETA2, "MessagingAddressList", MessagingAddressList.class);

    KubernetesDeserializer.registerCustomKind(API_VERSION_BETA2, "MessagingEndpoint", MessagingEndpoint.class);
    KubernetesDeserializer.registerCustomKind(API_VERSION_BETA2, "MessagingEndpointList", MessagingEndpointList.class);

    KubernetesDeserializer.registerCustomKind(API_VERSION_BETA2, "MessagingPlan", MessagingPlan.class);
    KubernetesDeserializer.registerCustomKind(API_VERSION_BETA2, "MessagingPlanList", MessagingPlanList.class);

    KubernetesDeserializer.registerCustomKind(API_VERSION_BETA2, "MessagingAddressPlan", MessagingAddressPlan.class);
    KubernetesDeserializer.registerCustomKind(API_VERSION_BETA2, "MessagingAddressPlanList", MessagingAddressPlanList.class);
}
 
Example #8
Source File: CustomResourceCrudTest.java    From kubernetes-client with Apache License 2.0 5 votes vote down vote up
@BeforeEach
void setUp() {
  KubernetesDeserializer.registerCustomKind("stable.example.com/v1", "CronTab", CronTab.class);
  cronTabCrd = kubernetesServer.getClient()
    .customResourceDefinitions()
    .load(getClass().getResourceAsStream("/crontab-crd.yml"))
    .get();
  kubernetesServer.getClient().customResourceDefinitions().create(cronTabCrd);
  crdContext = CustomResourceDefinitionContext.fromCrd(cronTabCrd);
}
 
Example #9
Source File: RabbitMQOperator.java    From rabbitmq-operator with Apache License 2.0 4 votes vote down vote up
private void registerCrdDeserializationTypes() {
    KubernetesDeserializer.registerCustomKind("indeed.com/v1alpha1", "RabbitMQCustomResource", RabbitMQCustomResource.class);
    KubernetesDeserializer.registerCustomKind("indeed.com/v1alpha1", "RabbitMQNetworkPartitionCustomResource", RabbitMQNetworkPartitionCustomResource.class);
}
 
Example #10
Source File: K8SCoreRuntime.java    From jhipster-operator with Apache License 2.0 4 votes vote down vote up
public void registerCustomKind(String apiVersion, String kind, Class<? extends KubernetesResource> clazz) {
    KubernetesDeserializer.registerCustomKind(apiVersion, kind, clazz);
}
 
Example #11
Source File: AdmissionReviewTest.java    From vault-crd with Apache License 2.0 4 votes vote down vote up
@Before
public void setup() {
    String kind = StringUtils.substringAfter("vault.koudingspawn.de", ".") + "/v1#Vault";
    KubernetesDeserializer.registerCustomKind(kind, Vault.class);
}
 
Example #12
Source File: AdminCrd.java    From enmasse with Apache License 2.0 4 votes vote down vote up
public static void registerCustomCrds() {

        KubernetesDeserializer.registerCustomKind(API_VERSION_V1BETA2, AddressPlan.KIND, AddressPlan.class);
        KubernetesDeserializer.registerCustomKind(API_VERSION_V1BETA2, AddressPlanList.KIND, AddressPlanList.class);

        KubernetesDeserializer.registerCustomKind(API_VERSION_V1BETA2, AddressSpacePlan.KIND, AddressSpacePlan.class);
        KubernetesDeserializer.registerCustomKind(API_VERSION_V1BETA2, AddressSpacePlanList.KIND, AddressSpacePlanList.class);

        KubernetesDeserializer.registerCustomKind(API_VERSION_V1BETA1, BrokeredInfraConfig.KIND, BrokeredInfraConfig.class);
        KubernetesDeserializer.registerCustomKind(API_VERSION_V1BETA1, BrokeredInfraConfigList.KIND, BrokeredInfraConfigList.class);

        KubernetesDeserializer.registerCustomKind(API_VERSION_V1BETA1, StandardInfraConfig.KIND, StandardInfraConfig.class);
        KubernetesDeserializer.registerCustomKind(API_VERSION_V1BETA1, StandardInfraConfigList.KIND, StandardInfraConfigList.class);

        KubernetesDeserializer.registerCustomKind(API_VERSION_V1BETA1, AuthenticationService.KIND, AuthenticationService.class);
        KubernetesDeserializer.registerCustomKind(API_VERSION_V1BETA1, AuthenticationServiceList.KIND, AuthenticationServiceList.class);

        KubernetesDeserializer.registerCustomKind(API_VERSION_V1BETA1, ConsoleService.KIND, ConsoleService.class);
        KubernetesDeserializer.registerCustomKind(API_VERSION_V1BETA1, ConsoleServiceList.KIND, ConsoleServiceList.class);

    }
 
Example #13
Source File: UserCrd.java    From enmasse with Apache License 2.0 4 votes vote down vote up
public static void registerCustomCrds() {
    KubernetesDeserializer.registerCustomKind(API_VERSION, User.KIND, User.class);
    KubernetesDeserializer.registerCustomKind(API_VERSION, UserList.KIND, UserList.class);
}
 
Example #14
Source File: IoTCrd.java    From enmasse with Apache License 2.0 4 votes vote down vote up
public static void registerCustomCrds() {
    KubernetesDeserializer.registerCustomKind(API_VERSION, IoTProject.KIND, IoTProject.class);
    KubernetesDeserializer.registerCustomKind(API_VERSION, IoTProjectList.KIND, IoTProjectList.class);
    KubernetesDeserializer.registerCustomKind(API_VERSION, IoTConfig.KIND, IoTConfig.class);
}