Skip to content

Support init containers - #12019

Merged
knative-prow-robot merged 6 commits into
knative:mainfrom
skonto:support_init_containers
Oct 6, 2021
Merged

knative-prow-robot merged 6 commits into
knative:mainfrom
skonto:support_init_containers

Conversation

@skonto

@skonto skonto commented Sep 20, 2021 •

Copy link
Copy Markdown
Contributor
  • Supports init containers behind a flag
  • Re-uses most of the existing validation logic
  • As with the other containers full validation can be done via dry-run per service eg. containers having the same name

Tracking Issue: #12024

Sample run:

apiVersion: serving.knative.dev/v1
kind: Service
metadata:
  name: helloworld-go
  namespace: default
spec:
  template:
    spec:
      containers:
        - image: docker.io/skonto/helloworld-go
      initContainers:
        -
          command:
            - sh
            - "-c"
            - "ls /"
          image: busybox

$ oc get pods
NAME                                              READY   STATUS     RESTARTS   AGE
helloworld-go-00001-deployment-6f6cf695fd-n6k2g   0/2     Init:0/1   0          11s
$ oc logs helloworld-go-00001-deployment-6f6cf695fd-n6k2g -c init-test
bin
dev
etc
home
proc
root
sys
tmp
usr
var
$ oc get pods
NAME                                              READY   STATUS    RESTARTS   AGE
helloworld-go-00001-deployment-6f6cf695fd-n6k2g   2/2     Running   0          74s

/cc @julz @dprotaso @markusthoemmes

@google-cla google-cla Bot added the cla: yes Indicates the PR's author has signed the CLA. label Sep 20, 2021
@knative-prow-robot knative-prow-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. area/API API objects and controllers area/networking labels Sep 20, 2021
@codecov

codecov Bot commented Sep 20, 2021 •

Copy link
Copy Markdown

Codecov Report

Merging #12019 (edeb47b) into main (365f68b) will decrease coverage by 0.13%.
The diff coverage is 63.79%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main   #12019      +/-   ##
==========================================
- Coverage   87.44%   87.30%   -0.14%     
==========================================
  Files         196      196              
  Lines        9534     9582      +48     
==========================================
+ Hits         8337     8366      +29     
- Misses        923      940      +17     
- Partials      274      276       +2     
Impacted Files Coverage Δ
pkg/apis/serving/fieldmask.go 94.32% <0.00%> (-0.70%) ⬇️
pkg/apis/serving/k8s_validation.go 91.89% <64.81%> (-4.25%) ⬇️
pkg/apis/config/features.go 95.45% <100.00%> (+0.21%) ⬆️
pkg/autoscaler/statforwarder/forwarder.go 88.88% <0.00%> (-7.41%) ⬇️
pkg/autoscaler/statforwarder/leases.go 76.97% <0.00%> (+1.43%) ⬆️
pkg/autoscaler/scaling/multiscaler.go 89.09% <0.00%> (+1.81%) ⬆️
pkg/reconciler/revision/background.go 93.20% <0.00%> (+1.94%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 365f68b...edeb47b. Read the comment docs.

@skonto

skonto commented Sep 20, 2021

Copy link
Copy Markdown
Contributor Author

Test fail unrelated:

   --- FAIL: TestSvcToSvcViaActivator/b-disabled (11.49s)
    ...
  service_to_service_test.go:140: Failed to start endpoint of httpproxy: response: status: 502, body: dial tcp: lookup svc-to-sv

@markusthoemmes

Copy link
Copy Markdown
Contributor

haven't actually looked through things yet, but since tomorrow's the release cut, let's delay this after that out of an abundance of caution.

/hold

@knative-prow-robot knative-prow-robot added do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. labels Sep 20, 2021
@skonto
skonto force-pushed the support_init_containers branch from 185901f to 349c6de Compare September 21, 2021 10:33
@knative-prow-robot knative-prow-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Sep 21, 2021
@skonto skonto changed the title Support init containers [wip]Support init containers Sep 21, 2021
@knative-prow-robot knative-prow-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Sep 21, 2021
@skonto

skonto commented Sep 21, 2021

Copy link
Copy Markdown
Contributor Author
    --- FAIL: TestSvcToSvcViaActivator/both-enabled (12.26s)
        service_to_service_test.go:224: Creating helloworld Service
        service.go:113: Creating a new Service service svc-to-svc-via-activator-both-enabled-gioyrjhq

@skonto skonto changed the title [wip]Support init containers Support init containers Sep 21, 2021
@knative-prow-robot knative-prow-robot added needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. and removed do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. labels Sep 21, 2021
@markusthoemmes

Copy link
Copy Markdown
Contributor

/unhold

Release is done.

@knative-prow-robot knative-prow-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Sep 23, 2021
@markusthoemmes

Copy link
Copy Markdown
Contributor

/assign @dprotaso

@skonto
skonto force-pushed the support_init_containers branch from da04659 to 69fb63f Compare September 24, 2021 12:19
@knative-prow-robot knative-prow-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Sep 24, 2021
@skonto

skonto commented Sep 24, 2021 •

Copy link
Copy Markdown
Contributor Author

Failures are irrelevant:

--- FAIL: TestRouteCreation (14.50s)
    
--- FAIL: TestSvcToSvcViaActivator (0.01s)

@skonto

skonto commented Sep 29, 2021

Copy link
Copy Markdown
Contributor Author

@dprotaso gentle ping.

Comment on lines +634 to +642
var errs *apis.FieldError
if len(ports) == 0 {
return nil
}
for _, p := range ports {
errs = errs.Also(validateContainerPortBasic(p))
}
return errs
}

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.

It looks like init containers ports are being treated differently than sidecar ports

we're skipping the checks

  • only TCP is allowed
  • only allow port names http h2c and `` (blank)

Thus I'm wondering what motivated the relaxed requirement and whether we should consider revisiting what we do for sidecars

@skonto skonto Sep 29, 2021 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

My pov is that init containers are not part of normal app operation. So I thought users should be more flexible (be closer to K8s initi container's allowed spec) and so to use more stuff than normal Service operation allows. For example port names should be arbitrary at this point and communication protocol can be any because people may want to setup their app in some arbitrary way.

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.

I agree - but let's pull this thread into an issue and see if anyone else has any opinions & thoughts.

Comment thread pkg/apis/serving/k8s_validation_test.go Outdated
Comment on lines +1741 to +1769
if !test.skipContainerTest {
got := ValidateContainer(ctx, test.c, test.volumes)
if diff := cmp.Diff(test.want.Error(), got.Error()); diff != "" {
t.Errorf("ValidateContainer (-want, +got): \n%s", diff)
}
}

if test.testAsInitContainer {
got := validateInitContainer(ctx, test.c, test.volumes)
if diff := cmp.Diff(test.wantForInitContainer.Error(), got.Error()); diff != "" {
t.Errorf("ValidateInitContainer (-want, +got): \n%s", diff)
}

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.

I think for the sake of clarity and readability we pull the init container validation tests into a separate Test function with it's own cases

@skonto skonto Sep 29, 2021 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I thought about it but this seems the most compact representation (trade-off with clarity) to avoid repeating stuff as most scenarios apply both to user containers and init containers. Afterall these are just containers to validated in the same pod.
Otherwise I will have to copy all common cases to a func that returns them and then add only the specific ones for user containers, as the init containers ones are a subset. Anyway I can try it and see.

@knative-prow-robot knative-prow-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Oct 5, 2021
Stavros Kontopoulos added 2 commits October 6, 2021 12:16
@skonto
skonto force-pushed the support_init_containers branch from 69fb63f to 520174e Compare October 6, 2021 09:31
@knative-prow-robot knative-prow-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Oct 6, 2021
@knative-prow-robot knative-prow-robot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Oct 6, 2021
@skonto

skonto commented Oct 6, 2021 •

Copy link
Copy Markdown
Contributor Author

@dprotaso I refactored the test cases, ready for review. Let's discuss sidecar containers although init containers are not like that because they are not running along with the app but they run to completion before the app is run. So I consider them to have different semantics.

@skonto

skonto commented Oct 6, 2021 •

Copy link
Copy Markdown
Contributor Author
--- FAIL: TestSvcToSvcViaActivator (0.02s)
    stream.go:254: D 11:38:31.182 autoscaler-5584db6444-f775f [knative.dev.serving.pkg.reconciler.autoscaling.kpa.Reconciler] [serving-tests/svc-to-svc-via-activator-both-enabled-nipteqmf-00001] Adding to queue serving-tests/svc-to-svc-via-activator-both-enabled-nipteqmf-00001 (depth: 1)
--- FAIL: TestRouteCreation (13.06s)
    route_test.go:156: Creating a new Route and Configuration

Fails look irrelevant.

@dprotaso

dprotaso commented Oct 6, 2021 •

Copy link
Copy Markdown
Member

/lgtm
/approve

Posting my comment re: sidecar vs. container differences again

I agree - but let's pull this thread into an issue and see if anyone else has any opinions & thoughts.

@skonto can you update the docs/websites highlighting the new feature flag & create a new issue for the topic above

@knative-prow-robot knative-prow-robot added the lgtm Indicates that a PR is ready to be merged. label Oct 6, 2021
@knative-prow-robot

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: dprotaso, skonto

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@knative-prow-robot knative-prow-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Oct 6, 2021
@knative-prow-robot
knative-prow-robot merged commit e979b9f into knative:main Oct 6, 2021
@dprotaso

dprotaso commented Oct 6, 2021

Copy link
Copy Markdown
Member

@skonto can you update the docs/websites highlighting the new feature flag & create a new issue for the topic above

I just made the docs issue & comment - so I can close this tab :)

@skonto

skonto commented Oct 7, 2021

Copy link
Copy Markdown
Contributor Author

@dprotaso issue for discussion.

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

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. area/API API objects and controllers area/networking cla: yes Indicates the PR's author has signed the CLA. lgtm Indicates that a PR is ready to be merged. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants