Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When deploying CRDs to kubernetes properties aren't replaced in deployment yaml files #515

Closed
marespane opened this issue Dec 8, 2020 · 2 comments · Fixed by #534
Closed
Assignees
Labels
bug Something isn't working
Milestone

Comments

@marespane
Copy link
Contributor

marespane commented Dec 8, 2020

Info

  • Eclipse JKube version : 1.0.2
  • Maven version (mvn -v) :
Apache Maven 3.6.3
Maven home: /usr/share/maven
Java version: 11.0.9, vendor: Oracle Corporation, runtime: /usr/lib/jvm/java-11-oracle
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "5.4.0-56-generic", arch: "amd64", family: "unix"

  • Kubernetes / Red Hat OpenShift setup and version : minikube latest version ( kubernetes version 1.19.4 ) and EKS cluster kubernetes v1.17.4

  • If it's a bug, how to reproduce : Use my sampleKerberosProject, first apply test_resource.yaml custom resource definition, then mvn k8s:resource && mvn k8s:apply
    You will get error, which will be solved if you in src/main/jkube/test-cr.yml replace ${app_namespace} with any namespace.

I was looking into your code, and quick fix is to replace resourceDir with OutputDirectory. But probably better solution is to replace properties in getCustomResourcesFileToNameMap function.

@rohanKanojia
Copy link
Member

Hmm, I can reproduce this. Right now, Custom Resource fragments are not part of the enrichment phase and are applied as it is during k8s:apply goal. It's being done here:

https://github.com/eclipse/jkube/blob/bf88230a5c110d686ea02ffb45dba8a294f5e2e9/jkube-kit/config/service/src/main/java/org/eclipse/jkube/kit/config/service/ApplyService.java#L455-L463

We would probably need to read file as string and replace properties with their respective values. We're doing something similar for Dockerfiles here:
https://github.com/eclipse/jkube/blob/bf88230a5c110d686ea02ffb45dba8a294f5e2e9/jkube-kit/build/api/src/main/java/org/eclipse/jkube/kit/build/api/helper/DockerFileUtil.java#L129-L135

@rohanKanojia rohanKanojia added the bug Something isn't working label Dec 8, 2020
@manusa manusa added this to the 1.1.0 milestone Dec 10, 2020
@rohanKanojia rohanKanojia self-assigned this Jan 5, 2021
rohanKanojia added a commit to rohanKanojia/jkube that referenced this issue Jan 5, 2021
… fragments

Refactor ApplyService.applyCustomResource to process CustomResource
fragment and interpolate it with project properties before applying
to Kubernetes.
rohanKanojia added a commit to rohanKanojia/jkube that referenced this issue Jan 11, 2021
… fragments

CustomResource fragments are now processed during resource phase and
copied to target/classes/META-INF/jkube/custom-resource directory. They
will be picked and applied during apply phase.
rohanKanojia added a commit to rohanKanojia/jkube that referenced this issue Jan 12, 2021
… fragments

CustomResource fragments are now processed during resource phase and
copied to target/classes/META-INF/jkube/custom-resource directory. They
will be picked and applied during apply phase.
rohanKanojia added a commit to rohanKanojia/jkube that referenced this issue Jan 12, 2021
… fragments

CustomResource fragments are now processed during resource phase and
copied to target/classes/META-INF/jkube/custom-resource directory. They
will be picked and applied during apply phase.
rohanKanojia added a commit to rohanKanojia/jkube that referenced this issue Jan 12, 2021
… fragments

CustomResource fragments are now processed during resource phase and
copied to target/classes/META-INF/jkube/custom-resource directory. They
will be picked and applied during apply phase.
rohanKanojia added a commit to rohanKanojia/jkube that referenced this issue Jan 12, 2021
… fragments

CustomResource fragments are now processed during resource phase and
copied to target/classes/META-INF/jkube/custom-resource directory. They
will be picked and applied during apply phase.
rohanKanojia added a commit to rohanKanojia/jkube that referenced this issue Jan 12, 2021
… fragments

CustomResource fragments are now processed during resource phase and
copied to target/classes/META-INF/jkube/custom-resource directory. They
will be picked and applied during apply phase.
rohanKanojia added a commit to rohanKanojia/jkube that referenced this issue Jan 12, 2021
… fragments

CustomResource fragments are now processed during resource phase and
copied to target/classes/META-INF/jkube/custom-resource directory. They
will be picked and applied during apply phase.
rohanKanojia added a commit to rohanKanojia/jkube that referenced this issue Jan 13, 2021
… fragments

CustomResource fragments are now processed during resource phase and
copied to target/classes/META-INF/jkube/custom-resource directory. They
will be picked and applied during apply phase.
@manusa manusa linked a pull request Jan 18, 2021 that will close this issue
12 tasks
rohanKanojia added a commit to rohanKanojia/jkube that referenced this issue Jan 21, 2021
… fragments

CustomResource fragments are now processed during resource phase and
copied to target/classes/META-INF/jkube/custom-resource directory. They
will be picked and applied during apply phase.
@manusa
Copy link
Member

manusa commented Jan 25, 2021

#534 review meeting notes

This are some of the bullet points and actions after reviewing the approach followed in #534

  1. Enricher should not be used to accomplish this functionality.

  2. Custom Resources should be treated as any other resources processed by JKube (namely resource fragments)

  3. The implementation of a Generic Resource was initially tried but the use of Serialization.yamlMapper().readValue() threw some exceptions.


I managed to implement a GenericResource that can be used to deserialize any yaml resource into a HasMetadata instance. You can check the implementation in this demo project: https://github.com/marcnuri-demo/fabric8-generic-custom-resource

What we're basically doing here is creating a very simple/basic implementation of HasMetadata that deserializes any extra fields and properties into the additionalProperties field.

In order to allow the use of this GenericResource in a KubernetesListBuilder and to allow the use of ObjectMetaBuilder visitors (e.g. ProjectLabelEnricher) a basic GenericResourceBuilder class has been implemented too. I've manually implemented this class so that we don't need to add the sundr.io dependency to generate builders. Unless I missed something else, this should be enough to provide the required functionality in JKube.


In order to implement the current functionality following steps should be performed:

I'm not sure if we can add a list in the src/main/jkube directory, IIRC we can't. But if we can, then some additional tasks should be performed for deserialization of the CRs.

rohanKanojia added a commit to rohanKanojia/jkube that referenced this issue Jan 27, 2021
… fragments

CustomResource fragments are now deserialized/serialized into GenericCustomResource so
that they are processed with standard kubernetes types
rohanKanojia added a commit to rohanKanojia/jkube that referenced this issue Jan 27, 2021
… fragments

CustomResource fragments are now deserialized/serialized into GenericCustomResource so
that they are processed with standard kubernetes types
rohanKanojia added a commit to rohanKanojia/jkube that referenced this issue Jan 27, 2021
… fragments

CustomResource fragments are now deserialized/serialized into GenericCustomResource so
that they are processed with standard kubernetes types
@manusa manusa modified the milestones: 1.1.0, 1.2.0 Jan 28, 2021
rohanKanojia added a commit to rohanKanojia/jkube that referenced this issue Jan 28, 2021
… fragments

CustomResource fragments are now deserialized/serialized into GenericCustomResource so
that they are processed with standard kubernetes types
rohanKanojia added a commit to rohanKanojia/jkube that referenced this issue Jan 29, 2021
… fragments

CustomResource fragments are now deserialized/serialized into GenericCustomResource so
that they are processed with standard kubernetes types
manusa pushed a commit to rohanKanojia/jkube that referenced this issue Feb 3, 2021
… fragments

CustomResource fragments are now deserialized/serialized into GenericCustomResource so
that they are processed with standard kubernetes types
manusa pushed a commit that referenced this issue Feb 3, 2021
CustomResource fragments are now deserialized/serialized into GenericCustomResource so
that they are processed with standard kubernetes types
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants