-
Notifications
You must be signed in to change notification settings - Fork 599
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
JobSink: Delete secrets associated with jobs when jobs are deleted (#…
…8331) * JobSink: Delete secrets associated with jobs when jobs are deleted As reported in #8323 old JobSink secrets lead to processing old events again while new events are lost. Using OwnerReference and k8s garbage collection, now a secret created for a given event is bound to a given Job lifecycle, so that when a job is deleted, the associated secret will be deleted. Signed-off-by: Pierangelo Di Pilato <[email protected]> * Fix jobsink name generator + add unit and fuzz tests Signed-off-by: Pierangelo Di Pilato <[email protected]> * Fix e2e test Signed-off-by: Pierangelo Di Pilato <[email protected]> * Lint Signed-off-by: Pierangelo Di Pilato <[email protected]> --------- Signed-off-by: Pierangelo Di Pilato <[email protected]>
- Loading branch information
Showing
5 changed files
with
250 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
/* | ||
Copyright 2024 The Knative Authors | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package main | ||
|
||
import ( | ||
"testing" | ||
|
||
"k8s.io/apimachinery/pkg/api/validation" | ||
|
||
"knative.dev/eventing/pkg/utils" | ||
) | ||
|
||
type testCase struct { | ||
JobSinkName string | ||
Source string | ||
Id string | ||
} | ||
|
||
func TestToJobName(t *testing.T) { | ||
testcases := []testCase{ | ||
{ | ||
JobSinkName: "job-sink-success", | ||
Source: "mysource3/myservice", | ||
Id: "2234-5678", | ||
}, | ||
{ | ||
JobSinkName: "a", | ||
Source: "0", | ||
Id: "0", | ||
}, | ||
} | ||
|
||
for _, tc := range testcases { | ||
t.Run(tc.JobSinkName+"_"+tc.Source+"_"+tc.Id, func(t *testing.T) { | ||
if errs := validation.NameIsDNS1035Label(tc.JobSinkName, false); len(errs) != 0 { | ||
t.Errorf("Invalid JobSinkName: %v", errs) | ||
} | ||
|
||
name := toJobName(tc.JobSinkName, tc.Source, tc.Id) | ||
doubleName := toJobName(tc.JobSinkName, tc.Source, tc.Id) | ||
if name != doubleName { | ||
t.Errorf("Before: %q, after: %q", name, doubleName) | ||
} | ||
|
||
if got := utils.ToDNS1123Subdomain(name); got != name { | ||
t.Errorf("ToDNS1123Subdomain(Want) returns a different result, Want: %q, Got: %q", name, got) | ||
} | ||
|
||
if errs := validation.NameIsDNS1035Label(name, false); len(errs) != 0 { | ||
t.Errorf("toJobName produced invalid name %q given %q, %q, %q: errors: %#v", name, tc.JobSinkName, tc.Source, tc.Id, errs) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func FuzzToJobName(f *testing.F) { | ||
testcases := []testCase{ | ||
{ | ||
JobSinkName: "job-sink-success", | ||
Source: "mysource3/myservice", | ||
Id: "2234-5678", | ||
}, | ||
{ | ||
JobSinkName: "a", | ||
Source: "0", | ||
Id: "0", | ||
}, | ||
} | ||
|
||
for _, tc := range testcases { | ||
f.Add(tc.JobSinkName, tc.Source, tc.Id) // Use f.Add to provide a seed corpus | ||
} | ||
f.Fuzz(func(t *testing.T, js, source, id string) { | ||
if errs := validation.NameIsDNSLabel(js, false); len(errs) != 0 { | ||
t.Skip("Prerequisite: invalid jobsink name") | ||
} | ||
|
||
name := toJobName(js, source, id) | ||
doubleName := toJobName(js, source, id) | ||
if name != doubleName { | ||
t.Errorf("Before: %q, after: %q", name, doubleName) | ||
} | ||
|
||
if got := utils.ToDNS1123Subdomain(name); got != name { | ||
t.Errorf("ToDNS1123Subdomain(Want) returns a different result, Want: %q, Got: %q", name, got) | ||
} | ||
|
||
if errs := validation.NameIsDNSLabel(name, false); len(errs) != 0 { | ||
t.Errorf("toJobName produced invalid name %q given %q, %q, %q: errors: %#v", name, js, source, id, errs) | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.