Skip to content

Commit

Permalink
Fix export e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dsimansk committed Jun 27, 2023
1 parent 009b2e7 commit 0fcf800
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
2 changes: 2 additions & 0 deletions lib/test/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ func BuildServiceWithOptions(name string, so ...servingtest.ServiceOption) *serv
APIVersion: "serving.knative.dev/v1",
}
svc.Spec.Template.Spec.Containers[0].Resources = corev1.ResourceRequirements{}
svc.Spec.Template.Spec.Containers[0].SecurityContext = &corev1.SecurityContext{}
return svc
}

Expand Down Expand Up @@ -301,6 +302,7 @@ func BuildRevision(name string, options ...servingtest.RevisionOption) *servingv
rev.ObjectMeta.UID = ""
rev.ObjectMeta.Generation = int64(0)
rev.Spec.PodSpec.Containers[0].Resources = corev1.ResourceRequirements{}
rev.Spec.PodSpec.Containers[0].SecurityContext = &corev1.SecurityContext{}
return rev
}

Expand Down
3 changes: 1 addition & 2 deletions pkg/kn/flags/podspec.go
Original file line number Diff line number Diff line change
Expand Up @@ -411,12 +411,11 @@ func (p *PodSpecFlags) ResolvePodSpec(podSpec *corev1.PodSpec, flags *pflag.Flag
}
}

if flags.Changed("security-context") && p.SecurityContext != "" {
if flags.Changed("security-context") {
if err := UpdateSecurityContext(podSpec, p.SecurityContext); err != nil {
return err
}
} else {
// Set default Security Context
if err := UpdateSecurityContext(podSpec, ""); err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/kn/flags/podspec_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -385,8 +385,8 @@ func UpdateSecurityContext(spec *corev1.PodSpec, securityContext string) error {
container := containerOfPodSpec(spec)
switch strings.ToLower(securityContext) {
case "none":
// Remove any Security Context defined
container.SecurityContext = nil
// Blank any Security Context defined
container.SecurityContext = &corev1.SecurityContext{}
case "strict":
// Add or update Security Context to default strict
container.SecurityContext = DefaultStrictSecCon()
Expand Down

0 comments on commit 0fcf800

Please sign in to comment.