mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 11:50:44 +00:00
Merge pull request #63586 from serathius/clean-sd-sinks-limit
Automatic merge from submit-queue (batch tested with PRs 63658, 63509, 63800, 63586, 63840). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. Clean stackdriver sinks when reached limit Workaround for stackdriver sinks leaking during test. This will automate cleaning when sinks when we reach limit. It can cause other tests running in parallel to fail, but because it's happens once per month impact is negligible. Fixes #7295 ```release-note NONE ``` /cc @krzyzacy @x13n @cezarygerard
This commit is contained in:
commit
40b8247e3a
@ -49,6 +49,9 @@ const (
|
||||
|
||||
// The parallelism level of polling logs process.
|
||||
sdLoggingPollParallelism = 10
|
||||
|
||||
// The limit on the number of stackdriver sinks that can be created within one project.
|
||||
stackdriverSinkCountLimit = 90
|
||||
)
|
||||
|
||||
type logProviderScope int
|
||||
@ -86,6 +89,10 @@ func newSdLogProvider(f *framework.Framework, scope logProviderScope) (*sdLogPro
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = ensureProjectHasSinkCapacity(sdService.Projects.Sinks, framework.TestContext.CloudConfig.ProjectID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
pubsubService, err := pubsub.New(hc)
|
||||
if err != nil {
|
||||
@ -104,6 +111,36 @@ func newSdLogProvider(f *framework.Framework, scope logProviderScope) (*sdLogPro
|
||||
return provider, nil
|
||||
}
|
||||
|
||||
func ensureProjectHasSinkCapacity(sinksService *sd.ProjectsSinksService, projectID string) error {
|
||||
listResponse, err := listSinks(sinksService, projectID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(listResponse.Sinks) >= stackdriverSinkCountLimit {
|
||||
framework.Logf("Reached Stackdriver sink limit. Deleting all sinks")
|
||||
deleteSinks(sinksService, projectID, listResponse.Sinks)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func listSinks(sinksService *sd.ProjectsSinksService, projectID string) (*sd.ListSinksResponse, error) {
|
||||
projectDst := fmt.Sprintf("projects/%s", projectID)
|
||||
listResponse, err := sinksService.List(projectDst).PageSize(stackdriverSinkCountLimit).Do()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to list Stackdriver Logging sinks: %v", err)
|
||||
}
|
||||
return listResponse, nil
|
||||
}
|
||||
|
||||
func deleteSinks(sinksService *sd.ProjectsSinksService, projectID string, sinks []*sd.LogSink) {
|
||||
for _, sink := range sinks {
|
||||
sinkNameID := fmt.Sprintf("projects/%s/sinks/%s", projectID, sink.Name)
|
||||
if _, err := sinksService.Delete(sinkNameID).Do(); err != nil {
|
||||
framework.Logf("Failed to delete LogSink: %v", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (p *sdLogProvider) Init() error {
|
||||
projectID := framework.TestContext.CloudConfig.ProjectID
|
||||
nsName := p.framework.Namespace.Name
|
||||
|
Loading…
Reference in New Issue
Block a user