Skip to content

feat: Add custom DNS and pod annotations support #548

Open
labibfrag wants to merge 5 commits intohyperledger-labs:mainfrom
labibfrag:name-servers-and-custom-annotations
Open

feat: Add custom DNS and pod annotations support #548
labibfrag wants to merge 5 commits intohyperledger-labs:mainfrom
labibfrag:name-servers-and-custom-annotations

Conversation

@labibfrag
Copy link
Copy Markdown

feat: Add custom DNS and pod annotations support

Add support for custom DNS nameservers and pod annotations via environment variables to enable advanced Kubernetes configurations like service mesh integration.

Features:

  • Custom DNS nameserver configuration via FABRIC_K8S_BUILDER_NAME_SERVERS
  • Custom pod annotations via FABRIC_K8S_BUILDER_CUSTOM_ANNOTATIONS
  • Both features are optional and backward compatible

Changes:

  • internal/util/env.go: Add NameServersVariable and CustomAnnotationsVariable constants, implement ParseAnnotations() helper
  • internal/util/k8s.go: Update getChaincodeJobSpec() and CreateChaincodeJob() to accept and apply custom DNS and annotations
  • internal/cmd/run.go: Add getNameServers() and getCustomAnnotations() functions
  • internal/builder/run.go: Add NameServers and CustomAnnotations fields to Run struct
  • internal/util/k8s_test.go: Add comprehensive tests for ParseAnnotations() function
  • docs/configuring/overview.md: Document new environment variables and usage

Usage:

  • FABRIC_K8S_BUILDER_NAME_SERVERS: Set to custom DNS server IP (e.g., "10.96.0.10")
  • FABRIC_K8S_BUILDER_CUSTOM_ANNOTATIONS: Comma-separated key=value pairs (e.g., "sidecar.istio.io/inject=true,app=myapp")

When FABRIC_K8S_BUILDER_NAME_SERVERS is set, pods use dnsPolicy: None with the specified nameserver. When empty, default Kubernetes DNS is used.

Custom annotations are merged with existing chaincode pod annotations, enabling integration with service meshes like Istio and monitoring tools like Prometheus.

Signed-off-by: Labib Farag <labib.farag@ibm.com>
@jt-nti
Copy link
Copy Markdown
Member

jt-nti commented Apr 2, 2026

Hi @labibfrag, thanks for the pull request! At first glance it looks great- I'll check it out properly and hopefully get it merged when I'm back at work after Easter. Thanks again!

Copy link
Copy Markdown
Member

@jt-nti jt-nti left a comment

Choose a reason for hiding this comment

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

Hi @labibfrag, thanks again for the PR.

The main thing I've spotted looking through the code is that there's no validation for the two new variables, which would then need testing in cmd/run/main_test.go

It would also be nice to add an integration test or two in test/integration/testdata

Before doing that though, I'd also like to discuss a bit more about the background to the PR since there is no related open issue.

The example settings you included were a great clue, thank you, and I think they point to a potential problem. From what I can tell istio will be looking for labels, not annotations, in which case this PR might not do what you need it to.

The builder also uses Jobs which could potentially cause some complexity, although reading https://istio.io/latest/blog/2023/native-sidecars/ does sound promising. Also, there was an example in there that makes me think that custom labels may not be necessary. For example if FABRIC_K8S_BUILDER_NAMESPACE is set to hlf-chaincode, then this might work without any additional changes...

kubectl label namespace hlf-chaincode istio-injection=enabled

Or maybe even...

kubectl label namespace hlf-chaincode istio.io/dataplane-mode=ambient

I was less sure about why the nameserver changes were required. Is that also istio related, or something related to accessing chaincode images? Reading https://kubernetes.io/docs/tasks/administer-cluster/dns-custom-nameservers/ I was wondering whether this kind of thing would be useful but that's just wild speculation!

chaincode.local:53 {
    errors
    cache 30
    forward . 10.150.0.1
}

Anyway, if there are ways to make use of the builder in a service mesh without any changes, that would be ideal. While I'm keen to minimise k8s config in the builder, if there are things you can't achieve without changes, e.g. custom labels rather than annotations, this PR is a great start!

Comment thread internal/cmd/run.go

func getNameServers(logger *log.CmdLogger) string {
nameServers := util.GetOptionalEnv(util.NameServersVariable, "")
logger.Debugf("%s=%s", util.NameServersVariable, nameServers)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

There should be some validation for the nameserver variable. I think it's something like up to 3 IP addresses but I don't know for sure/the details.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

yes it can be 3 servers
nameservers: a list of IP addresses that will be used as DNS servers for the Pod. There can be at most 3 IP addresses specified.
but it's admin responsibility to identify the servers , we can add validation / Warning about length
do you agree ?

Comment thread internal/cmd/run.go Outdated
annotationsStr := util.GetOptionalEnv(util.CustomAnnotationsVariable, "")
logger.Debugf("%s=%s", util.CustomAnnotationsVariable, annotationsStr)

annotations := util.ParseAnnotations(annotationsStr)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

There should be some validation for the annotations somewhere. The builder does label validation for example.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

what type of validation we can add for this annotation ?

@labibfrag labibfrag requested a review from jt-nti April 15, 2026 13:54
@jt-nti
Copy link
Copy Markdown
Member

jt-nti commented Apr 24, 2026

Can this PR be closed now that #553 is open?

@labibfrag
Copy link
Copy Markdown
Author

labibfrag commented Apr 24, 2026

Can this PR be closed now that #553 is open?

actually I included changes in PR #553 in my PR
propose to close #553 not #548

@jt-nti
Copy link
Copy Markdown
Member

jt-nti commented Apr 24, 2026

Aha, thanks, glad I checked! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants