func()

in internal/deployers/eksapi/janitor.go [93:121]


func (j *janitor) sweepWorker(wg *sync.WaitGroup, stackQueue <-chan cloudformationtypes.Stack, errChan chan<- error) {
	defer wg.Done()
	for stack := range stackQueue {
		resourceID := *stack.StackName
		if !strings.HasPrefix(resourceID, ResourcePrefix) {
			continue
		}
		if stack.StackStatus == "DELETE_COMPLETE" {
			continue
		}
		if j.stackStatus != "" && j.stackStatus != string(stack.StackStatus) {
			klog.Infof("skipping resources (status: %v): %s", stack.StackStatus, resourceID)
			continue
		}
		resourceAge := time.Since(*stack.CreationTime)
		if resourceAge < j.maxResourceAge {
			klog.Infof("skipping resources (%v old): %s", resourceAge, resourceID)
			continue
		}
		clients := j.awsClientsForStack(stack)
		infraManager := NewInfrastructureManager(clients, resourceID, j.metrics)
		clusterManager := NewClusterManager(clients, resourceID)
		nodeManager := NewNodeManager(clients, resourceID)
		klog.Infof("deleting resources (%v old): %s", resourceAge, resourceID)
		if err := deleteResources(infraManager, clusterManager, nodeManager, nil /* k8sClient */, nil /* deployerOptions */); err != nil {
			errChan <- fmt.Errorf("failed to delete resources: %s: %v", resourceID, err)
		}
	}
}