diff --git a/api/v1/clustercatalog_types.go b/api/v1/clustercatalog_types.go index f083c1128..ee1391b79 100644 --- a/api/v1/clustercatalog_types.go +++ b/api/v1/clustercatalog_types.go @@ -34,6 +34,14 @@ const ( AvailabilityModeAvailable AvailabilityMode = "Available" AvailabilityModeUnavailable AvailabilityMode = "Unavailable" + + // Condition types + TypeServing = "Serving" + + // Serving Reasons + ReasonAvailable = "Available" + ReasonUnavailable = "Unavailable" + ReasonUserSpecifiedUnavailable = "UserSpecifiedUnavailable" ) //+kubebuilder:object:root=true diff --git a/api/v1/clusterextension_types_test.go b/api/v1/clusterextension_types_test.go index f05427348..7bc9a3393 100644 --- a/api/v1/clusterextension_types_test.go +++ b/api/v1/clusterextension_types_test.go @@ -5,7 +5,6 @@ import ( "go/ast" "go/parser" "go/token" - "io/fs" "strconv" "strings" "testing" @@ -52,49 +51,47 @@ func TestClusterExtensionReasonRegistration(t *testing.T) { } } -// parseConstants parses the values of the top-level constants in the current -// directory whose names start with the given prefix. When running as part of a -// test, the current directory is the directory of the file that contains the -// test in which this function is called. +// parseConstants parses the values of the top-level constants that start with the given prefix, +// in the files clusterextension_types.go and common_types.go. func parseConstants(prefix string) ([]string, error) { fset := token.NewFileSet() - // ParseDir returns a map of package name to package ASTs. An AST is a representation of the source code - // that can be traversed to extract information. The map is keyed by the package name. - pkgs, err := parser.ParseDir(fset, ".", func(info fs.FileInfo) bool { - return !strings.HasSuffix(info.Name(), "_test.go") - }, 0) - if err != nil { - return nil, err + // An AST is a representation of the source code that can be traversed to extract information. + // Converting files to AST representation to extract information. + parseFiles, astFiles := []string{"clusterextension_types.go", "common_types.go"}, []*ast.File{} + for _, file := range parseFiles { + p, err := parser.ParseFile(fset, file, nil, 0) + if err != nil { + return nil, err + } + astFiles = append(astFiles, p) } var constValues []string - // Iterate all of the top-level declarations in each package's files, - // looking for constants that start with the prefix. When we find one, - // add its value to the constValues list. - for _, pkg := range pkgs { - for _, f := range pkg.Files { - for _, d := range f.Decls { - genDecl, ok := d.(*ast.GenDecl) - if !ok { + // Iterate all of the top-level declarations in each file, looking + // for constants that start with the prefix. When we find one, add + // its value to the constValues list. + for _, f := range astFiles { + for _, d := range f.Decls { + genDecl, ok := d.(*ast.GenDecl) + if !ok { + continue + } + for _, s := range genDecl.Specs { + valueSpec, ok := s.(*ast.ValueSpec) + if !ok || len(valueSpec.Names) != 1 || valueSpec.Names[0].Obj.Kind != ast.Con || !strings.HasPrefix(valueSpec.Names[0].String(), prefix) { continue } - for _, s := range genDecl.Specs { - valueSpec, ok := s.(*ast.ValueSpec) - if !ok || len(valueSpec.Names) != 1 || valueSpec.Names[0].Obj.Kind != ast.Con || !strings.HasPrefix(valueSpec.Names[0].String(), prefix) { + for _, val := range valueSpec.Values { + lit, ok := val.(*ast.BasicLit) + if !ok || lit.Kind != token.STRING { continue } - for _, val := range valueSpec.Values { - lit, ok := val.(*ast.BasicLit) - if !ok || lit.Kind != token.STRING { - continue - } - v, err := strconv.Unquote(lit.Value) - if err != nil { - return nil, fmt.Errorf("unquote literal string %s: %v", lit.Value, err) - } - constValues = append(constValues, v) + v, err := strconv.Unquote(lit.Value) + if err != nil { + return nil, fmt.Errorf("unquote literal string %s: %v", lit.Value, err) } + constValues = append(constValues, v) } } } diff --git a/api/v1/common_types.go b/api/v1/common_types.go index 6008d7557..5478039c9 100644 --- a/api/v1/common_types.go +++ b/api/v1/common_types.go @@ -19,7 +19,6 @@ package v1 const ( TypeInstalled = "Installed" TypeProgressing = "Progressing" - TypeServing = "Serving" // Progressing reasons ReasonSucceeded = "Succeeded" @@ -29,9 +28,4 @@ const ( // Terminal reasons ReasonDeprecated = "Deprecated" ReasonFailed = "Failed" - - // Serving reasons - ReasonAvailable = "Available" - ReasonUnavailable = "Unavailable" - ReasonUserSpecifiedUnavailable = "UserSpecifiedUnavailable" ) diff --git a/internal/operator-controller/conditionsets/conditionsets.go b/internal/operator-controller/conditionsets/conditionsets.go index 1b57a0cd8..c69aff421 100644 --- a/internal/operator-controller/conditionsets/conditionsets.go +++ b/internal/operator-controller/conditionsets/conditionsets.go @@ -31,7 +31,6 @@ var ConditionTypes = []string{ ocv1.TypeChannelDeprecated, ocv1.TypeBundleDeprecated, ocv1.TypeProgressing, - ocv1.TypeServing, } var ConditionReasons = []string{ @@ -40,7 +39,4 @@ var ConditionReasons = []string{ ocv1.ReasonFailed, ocv1.ReasonBlocked, ocv1.ReasonRetrying, - ocv1.ReasonAvailable, - ocv1.ReasonUnavailable, - ocv1.ReasonUserSpecifiedUnavailable, }