@@ -374,16 +374,12 @@ func (p Parser) parseRule(node *yaml.Node, offsetLine, offsetColumn int, content
374374 }
375375 }
376376
377- for _ , entry := range []struct {
378- part * yaml.Node
379- key string
380- }{
381- {key : labelsKey , part : labelsNode },
382- {key : annotationsKey , part : annotationsNode },
383- } {
384- if entry .part != nil && ! isTag (entry .part .ShortTag (), mapTag ) {
385- return invalidValueError (lines , entry .part .Line + offsetLine , entry .key , describeTag (mapTag ), describeTag (entry .part .ShortTag ()))
386- }
377+ if (recordPart != nil || alertPart != nil ) && exprPart != nil && labelsNode != nil && ! isTag (labelsNode .ShortTag (), mapTag ) {
378+ return invalidValueError (lines , labelsNode .Line + offsetLine , labelsKey , describeTag (mapTag ), describeTag (labelsNode .ShortTag ()))
379+ }
380+
381+ if alertPart != nil && exprPart != nil && annotationsNode != nil && ! isTag (annotationsNode .ShortTag (), mapTag ) {
382+ return invalidValueError (lines , annotationsNode .Line + offsetLine , annotationsKey , describeTag (mapTag ), describeTag (annotationsNode .ShortTag ()))
387383 }
388384
389385 if ok , perr , plines := validateStringMap (labelsKey , labelsNodes , offsetLine , lines ); ! ok {
@@ -631,6 +627,9 @@ type yamlMap struct {
631627}
632628
633629func mappingNodes (node * yaml.Node ) []yamlMap {
630+ if node .Kind != yaml .MappingNode {
631+ return nil
632+ }
634633 m := make ([]yamlMap , 0 , len (node .Content )/ 2 )
635634 for i := 0 ; i < len (node .Content ); i += 2 {
636635 m = append (m , yamlMap {key : node .Content [i ], val : node .Content [i + 1 ]})
0 commit comments