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

added environment variable CF_INSTANCE_PORTS #3230

Merged
merged 1 commit into from
May 7, 2024

Conversation

marsteg
Copy link
Contributor

@marsteg marsteg commented Apr 23, 2024

Is there a related GitHub Issue?

#3229

What is this change about?

Adding environment variable CF_INSTANCE_PORTS to workloads

Does this PR introduce a breaking change?

not, that i expect it

Acceptance Steps

  • deploy an app, that prints the environment variable CF_INSTANCE_PORTS
  • check that the app actually has the environment variable

Tag your pair, your PM, and/or team

@danail-branekov @georgethebeatle

Additional info

I've seen strange errors when executing go test -v: 12:04:37.313765 45784 reflector.go:462] pkg/mod/k8s.io/[email protected]/tools/cache/reflector.go:229: watch of *v1.Secret ended with: an error on the server ("unable to decode an event from the watch stream: context canceled") has prevented the request from succeeding - i hope that this is some local issue...

@@ -138,9 +138,11 @@ func (b *ProcessEnvBuilder) buildPortEnv(ctx context.Context, cfApp *korifiv1alp
processPorts := ports.FromRoutes(cfRoutesForProcess.Items, cfApp.Name, cfProcess.Spec.ProcessType)
if len(processPorts) > 0 {
portString := strconv.FormatInt(int64(processPorts[0]), 10)
cfInstancePorts := fmt.Sprintf("[{\"internal\":%s},{\"internal\":%s}]", portString, portString)
Copy link
Member

Choose a reason for hiding this comment

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

Why do we need internal twice? I guess we need external as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

very good question! So i basically copied what i saw that a productive CF instance gave me by default. I got there:

CF_INSTANCE_PORTS env is: [{"internal":8080,"external_tls_proxy":61157,"internal_tls_proxy":61001},{"internal":8080,"internal_tls_proxy":61443}]

so my assumption is, that the first {} holds ALL ports and the second {} holds all "internal" ports. since I didn't know what the tls_proxy ports are in the korifi environment, I left them out for now.

Copy link
Member

Choose a reason for hiding this comment

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

Could it be that in the example above you have had two routes for the same app? Docs for that env var do not seem to mention anything about the number of json entries.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

no, there is just one route when I do "cf routes". Could the route be hidden somehow? i didn't specifically create one...

Copy link
Member

@danail-branekov danail-branekov Apr 25, 2024

Choose a reason for hiding this comment

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

I have spun a traditional cf deployment, pushed dora from CATS and got

vcap@a0213476-fa1a-43c1-5ec8-99af:~$ echo $CF_INSTANCE_PORTS  | jq .
[
  {
    "external": 61000,
    "internal": 8080,
    "external_tls_proxy": 61002,
    "internal_tls_proxy": 61001
  },
  {
    "external": 61000,
    "internal": 8080,
    "internal_tls_proxy": 61443
  },
  {
    "external": 61001,
    "internal": 2222,
    "external_tls_proxy": 61003,
    "internal_tls_proxy": 61002
  }
]

weird...

The app has a single route:

❯ cf app dora
Showing health and status for app dora in org org1 / space space2 as admin...

name:              dora
requested state:   started
routes:            dora.mel-c.korifi.cf-app.com
last uploaded:     Thu 25 Apr 10:48:43 UTC 2024
stack:             cflinuxfs4
buildpacks:
        name             version   detect output   buildpack name
        ruby_buildpack   1.10.13   ruby            ruby

type:           web
sidecars:
instances:      1/1
memory usage:   256M
     state     since                  cpu    memory          disk           logging             details
#0   running   2024-04-25T10:48:55Z   0.7%   76.5M of 256M   130.2M of 1G   0B/s of unlimited

type:           worker
sidecars:
instances:      0/0
memory usage:   256M
There are no running instances of this process.


❯ cf route mel-c.korifi.cf-app.com -n dora
 Showing route dora.mel-c.korifi.cf-app.com in org org1 / space space2 as admin...

domain:     mel-c.korifi.cf-app.com
host:       dora
port:
path:
protocol:   http

Destinations:
        app    process   port   app-protocol
        dora   web       8080   http1

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Talked to a CF developer:
proposal: once external_tls_proxy and internal_tls_proxy gets added, we could simply add the internal only (external ones not exposed if envoy is active). For now, internal should be enough but there seem to be apps, that rely on the existance of all fields

@marsteg
Copy link
Contributor Author

marsteg commented Apr 29, 2024

@danail-branekov, @georgethebeatle: as discussed, i removed the 2nd port for now

@@ -350,6 +350,10 @@ var _ = Describe("EnvBuilder", func() {
"Name": Equal("PORT"),
"Value": Equal("1234"),
}),
MatchFields(IgnoreExtras, Fields{
"Name": Equal("CF_INSTANCE_PORTS"),
"Value": ContainSubstring("\"internal\":1234"),
Copy link
Member

Choose a reason for hiding this comment

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

How about we use MatchJSON instead of ContainSubstring? thus we could ensure that the content of the value is a valid json

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done! I suppose we could also create a struct and json.Marshall it... but i'm note sure if that's better as json shouldn't change?

@marsteg marsteg force-pushed the cf_instance_ports branch 2 times, most recently from 4b33d9a to 2869d9f Compare May 6, 2024 12:26
@marsteg marsteg force-pushed the cf_instance_ports branch from 2869d9f to d513048 Compare May 6, 2024 12:31
@danail-branekov danail-branekov merged commit fe9c795 into cloudfoundry:main May 7, 2024
11 checks passed
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.

2 participants