Skip to content
This repository has been archived by the owner on Jun 19, 2024. It is now read-only.

Improve support for sidecar containers #1202

Merged
merged 7 commits into from
Mar 13, 2019

Conversation

nicolaferraro
Copy link
Member

This fixes #968, and its implementation is based on a discussion with @kameshsampath a long time ago.

This changes how the fragments are merged with generated resources. If a container in a fragment has a name (different from the f-m-p generated one) it's considered a sidecar and not merged, creating 2 containers. Fragments that don't declare a name (or with a matching one) are considered an addition to the default container.

I've changed the health-check enrichment process to enrich only generated containers and not sidecars. In order to do this I needed to add a env variable to generated containers (there are no annotation/labels at container level) to recognize it during enrichment.

@nicolaferraro
Copy link
Member Author

retest this please

@nicolaferraro nicolaferraro force-pushed the sidecars branch 3 times, most recently from f33dd5a to 4cf8190 Compare February 20, 2018 17:04

/**
* Enriches containers with health check probes.
*/
public abstract class AbstractHealthCheckEnricher extends BaseEnricher {

private enum Config implements Configs.Key {
enrichAllContainers {{ d = "false"; }},
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CRITICAL Rename this constant name to match the regular expression '^[A-Z][A-Z0-9](_[A-Z0-9]+)$'. rule
MAJOR Move the contents of this initializer to a standard constructor or to field initializers. rule
MINOR Use another way to initialize this instance. rule


/**
* Enriches containers with health check probes.
*/
public abstract class AbstractHealthCheckEnricher extends BaseEnricher {

private enum Config implements Configs.Key {
enrichAllContainers {{ d = "false"; }},
enrichContainers {{ d = null; }};
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CRITICAL Rename this constant name to match the regular expression '^[A-Z][A-Z0-9](_[A-Z0-9]+)$'. rule
MAJOR Move the contents of this initializer to a standard constructor or to field initializers. rule
MINOR Use another way to initialize this instance. rule

@@ -80,6 +87,46 @@ private String describe(Probe probe) {
return desc.toString();
}

protected List<ContainerBuilder> getContainersToEnrich(KubernetesListBuilder builder) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CRITICAL Refactor this method to reduce its Cognitive Complexity from 16 to the 15 allowed. rule

@ghost
Copy link

ghost commented Feb 20, 2018

SonarQube analysis reported 7 issues

  • CRITICAL 3 critical
  • MAJOR 2 major
  • MINOR 2 minor

Watch the comments in this conversation to review them.

@nicolaferraro
Copy link
Member Author

Finally.. JMockit was not working well..

@hrishin
Copy link
Member

hrishin commented Mar 1, 2018

@nicolaferraro Thanks for the PR. Will review it soon :)

@nicolaferraro
Copy link
Member Author

@hrishin did you have time to have a look?

@hrishin
Copy link
Member

hrishin commented Apr 3, 2018

@nicolaferraro sorry to say I got sidetracked from FMP these days. I can give initial look but @rohanKanojia @piyush1594 can help here to review it.

@piyush1594 @rohanKanojia lets priorities this PR review ASAP

@geoand
Copy link
Contributor

geoand commented May 28, 2018

Hi,

Is there any news on this? I ran into this issue as well

@piyush-garg
Copy link
Collaborator

@nicolaferraro Would you like to rebase and push again.

@hrishin
Copy link
Member

hrishin commented Jun 18, 2018

@nicolaferraro we have rebased it. Could you please verify it?

@nicolaferraro
Copy link
Member Author

Rebased...

@piyush-garg
Copy link
Collaborator

piyush-garg commented Jun 22, 2018

hey, @nicolaferraro 3.5.40 got released two days, you need to put it in 3.5.41. Thanks

Copy link
Contributor

@rhuss rhuss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really like and support the intention of the PR. Although I haven't much time to dig into the details, the only thing I dislike a bit is the introduction of a kind of 'processing instruction' in form of a container env which doesn't get remove afterwards.

Actually, it would be nice if the Kubernetes Model would allow for such kind of transient meta data, so it might be worth to open an issue over there. In the meantime, I would add a postprocess step to remove the "FABRIC8_GENERATED" env vzr.

@@ -53,6 +53,12 @@
.endValueFrom()
.build());

ret.add(
new EnvVarBuilder()
.withName("FABRIC8_GENERATED")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder whether we could use some other kind of meta-data for a container to indicate that it's auto generated? As this env var is visible within the container it might have side effects (although unlikely) but at least it pollutes the env namespace and increases the descriptors size. I understand that a container within a pod cannot carry any annotations/labels.

However, we need this information only during the (internal) build up of the model, so it sounds a bit over the top to make this information persistent. I suspect that the Kubernetes model objects don't carry any 'transient' meta information (which would be useful here), but maybe we could, in a postrpocess step, remove our markers before writing out the resource files ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it was my concern too. I think having a enricher that removes the env variable at the end of the build is ok. However, I think that I can also use a annotation at pod level to specify the name of the container that is generated by fabric8. Let's keep this on hold and I'll try to provide a different implementation. I don't like the added env variable either.

@codecov
Copy link

codecov bot commented Nov 2, 2018

Codecov Report

Merging #1202 into master will increase coverage by 0.3%.
The diff coverage is 56.6%.

@@             Coverage Diff             @@
##             master    #1202     +/-   ##
===========================================
+ Coverage     35.76%   36.06%   +0.3%     
- Complexity     1110     1131     +21     
===========================================
  Files           180      180             
  Lines          9969    10041     +72     
  Branches       1617     1632     +15     
===========================================
+ Hits           3565     3621     +56     
- Misses         5976     5987     +11     
- Partials        428      433      +5

Copy link
Member Author

@nicolaferraro nicolaferraro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rohanKanojia I think removing the env variable at the end is the easiest way to implement the functionality without affecting the end user. This way, the variable is just a marker within the enrichment process.

LGTM

@rohanKanojia rohanKanojia added pr/waiting-on-feedback Waiting on feedback and removed pr/change-requested Reviewer requested a change pr/wip Work in Progress, do not merge labels Jan 17, 2019

public DeploymentOpenShiftConverter(PlatformMode mode, Long openshiftDeployTimeoutSeconds) {
public DeploymentOpenShiftConverter(PlatformMode mode, Long openshiftDeployTimeoutSeconds, MavenProject project) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of passing the MavenProject, can we only pass the artifactId?

@devang-gaur
Copy link
Contributor

fixes #1037

@@ -38,7 +38,7 @@

private final EnricherConfig config;
private final String name;
private EnricherContext enricherContext;
public EnricherContext enricherContext;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't like to have a public field, maybe protected? Or create a getter?

deploymentConfigBuilder.editSpec().addNewTrigger().withType("ConfigChange").endTrigger().endSpec();
}
}
});
}
}

private void setProcessingInstruction(List<String> containerNames) {
Map<String, String> pi = new HashMap<>();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you rename to a meaningful var name?

nicolaferraro and others added 7 commits March 13, 2019 17:27
We can have a varible called Processing Instructions(pi) in EnricherContext which
would be propagated through the chain of enrichers rather than polluting application's
container environment.
Don't add ImageChange triggers to containers other than main
application containers. In Openshift mode, ImageStream is used
by default. This is just a workaround for fabric8io#1037
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
pr/waiting-on-feedback Waiting on feedback target/4.0 PR for targeted to 4.0.x
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support for Multi containers with Resource Fragments
8 participants