@@ -68,6 +68,7 @@ func RegisterSteps(sc *godog.ScenarioContext) {
6868 sc .Step (`^(?i)resource "([^"]+)" is installed$` , ResourceAvailable )
6969 sc .Step (`^(?i)resource "([^"]+)" is available$` , ResourceAvailable )
7070 sc .Step (`^(?i)resource "([^"]+)" is removed$` , ResourceRemoved )
71+ sc .Step (`^(?i)resource "([^"]+)" is eventually not found$` , ResourceEventuallyNotFound )
7172 sc .Step (`^(?i)resource "([^"]+)" exists$` , ResourceAvailable )
7273 sc .Step (`^(?i)resource is applied$` , ResourceIsApplied )
7374 sc .Step (`^(?i)resource "deployment/test-operator" reports as (not ready|ready)$` , MarkTestOperatorNotReady )
@@ -398,24 +399,25 @@ func ClusterExtensionRevisionIsArchived(ctx context.Context, revisionName string
398399func ResourceAvailable (ctx context.Context , resource string ) error {
399400 sc := scenarioCtx (ctx )
400401 resource = substituteScenarioVars (resource , sc )
401- rtype , name , found := strings .Cut (resource , "/" )
402+ kind , name , found := strings .Cut (resource , "/" )
402403 if ! found {
403- return fmt .Errorf ("resource %s is not in the format <type >/<name>" , resource )
404+ return fmt .Errorf ("resource %s is not in the format <kind >/<name>" , resource )
404405 }
405406 waitFor (ctx , func () bool {
406- _ , err := k8sClient ("get" , rtype , name , "-n" , sc .namespace )
407+ _ , err := k8sClient ("get" , kind , name , "-n" , sc .namespace )
407408 return err == nil
408409 })
409410 return nil
410411}
411412
412413func ResourceRemoved (ctx context.Context , resource string ) error {
413414 sc := scenarioCtx (ctx )
414- rtype , name , found := strings .Cut (resource , "/" )
415+ resource = substituteScenarioVars (resource , sc )
416+ kind , name , found := strings .Cut (resource , "/" )
415417 if ! found {
416- return fmt .Errorf ("resource %s is not in the format <type >/<name>" , resource )
418+ return fmt .Errorf ("resource %s is not in the format <kind >/<name>" , resource )
417419 }
418- yaml , err := k8sClient ("get" , rtype , name , "-n" , sc .namespace , "-o" , "yaml" )
420+ yaml , err := k8sClient ("get" , kind , name , "-n" , sc .namespace , "-o" , "yaml" )
419421 if err != nil {
420422 return err
421423 }
@@ -424,23 +426,38 @@ func ResourceRemoved(ctx context.Context, resource string) error {
424426 return err
425427 }
426428 sc .removedResources = append (sc .removedResources , * obj )
427- _ , err = k8sClient ("delete" , rtype , name , "-n" , sc .namespace )
429+ _ , err = k8sClient ("delete" , kind , name , "-n" , sc .namespace )
428430 return err
429431}
430432
433+ func ResourceEventuallyNotFound (ctx context.Context , resource string ) error {
434+ sc := scenarioCtx (ctx )
435+ resource = substituteScenarioVars (resource , sc )
436+ kind , name , found := strings .Cut (resource , "/" )
437+ if ! found {
438+ return fmt .Errorf ("resource %s is not in the format <kind>/<name>" , resource )
439+ }
440+
441+ require .Eventually (godog .T (ctx ), func () bool {
442+ obj , err := k8sClient ("get" , kind , name , "-n" , sc .namespace , "--ignore-not-found" , "-o" , "yaml" )
443+ return err == nil && obj == ""
444+ }, timeout , tick )
445+ return nil
446+ }
447+
431448func ResourceMatches (ctx context.Context , resource string , requiredContentTemplate * godog.DocString ) error {
432449 sc := scenarioCtx (ctx )
433450 resource = substituteScenarioVars (resource , sc )
434- rtype , name , found := strings .Cut (resource , "/" )
451+ kind , name , found := strings .Cut (resource , "/" )
435452 if ! found {
436- return fmt .Errorf ("resource %s is not in the format <type >/<name>" , resource )
453+ return fmt .Errorf ("resource %s is not in the format <kind >/<name>" , resource )
437454 }
438455 requiredContent , err := toUnstructured (substituteScenarioVars (requiredContentTemplate .Content , sc ))
439456 if err != nil {
440457 return fmt .Errorf ("failed to parse required resource yaml: %v" , err )
441458 }
442459 waitFor (ctx , func () bool {
443- objJson , err := k8sClient ("get" , rtype , name , "-n" , sc .namespace , "-o" , "json" )
460+ objJson , err := k8sClient ("get" , kind , name , "-n" , sc .namespace , "-o" , "json" )
444461 if err != nil {
445462 return false
446463 }
@@ -468,12 +485,13 @@ func ResourceMatches(ctx context.Context, resource string, requiredContentTempla
468485
469486func ResourceRestored (ctx context.Context , resource string ) error {
470487 sc := scenarioCtx (ctx )
471- rtype , name , found := strings .Cut (resource , "/" )
488+ resource = substituteScenarioVars (resource , sc )
489+ kind , name , found := strings .Cut (resource , "/" )
472490 if ! found {
473- return fmt .Errorf ("resource %s is not in the format <type >/<name>" , resource )
491+ return fmt .Errorf ("resource %s is not in the format <kind >/<name>" , resource )
474492 }
475493 waitFor (ctx , func () bool {
476- yaml , err := k8sClient ("get" , rtype , name , "-n" , sc .namespace , "-o" , "yaml" )
494+ yaml , err := k8sClient ("get" , kind , name , "-n" , sc .namespace , "-o" , "yaml" )
477495 if err != nil {
478496 return false
479497 }
@@ -486,7 +504,7 @@ func ResourceRestored(ctx context.Context, resource string) error {
486504 for i , removed := range sc .removedResources {
487505 rct := removed .GetCreationTimestamp ()
488506 if removed .GetName () == obj .GetName () && removed .GetKind () == obj .GetKind () && rct .Before (& ct ) {
489- switch rtype {
507+ switch kind {
490508 case "configmap" :
491509 if ! reflect .DeepEqual (removed .Object ["data" ], obj .Object ["data" ]) {
492510 return false
0 commit comments