github.com/redhat-appstudio/release-service@v0.0.0-20240507045911-a8558ef3422a/tekton/predicates.go (about)

     1  /*
     2  Copyright 2022.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package tekton
    18  
    19  import (
    20  	"sigs.k8s.io/controller-runtime/pkg/event"
    21  	"sigs.k8s.io/controller-runtime/pkg/predicate"
    22  )
    23  
    24  // ReleasePipelineRunSucceededPredicate returns a predicate which filters out all objects except
    25  // managed Release PipelineRuns which have just succeeded.
    26  func ReleasePipelineRunSucceededPredicate() predicate.Predicate {
    27  	return predicate.Funcs{
    28  		CreateFunc: func(createEvent event.CreateEvent) bool {
    29  			return false
    30  		},
    31  		DeleteFunc: func(deleteEvent event.DeleteEvent) bool {
    32  			return false
    33  		},
    34  		GenericFunc: func(genericEvent event.GenericEvent) bool {
    35  			return false
    36  		},
    37  		UpdateFunc: func(e event.UpdateEvent) bool {
    38  			return isReleasePipelineRun(e.ObjectNew) && hasPipelineSucceeded(e.ObjectNew)
    39  		},
    40  	}
    41  }