@@ -36,6 +36,7 @@ import (
3636 corev1 "k8s.io/api/core/v1"
3737 apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
3838 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
39+ "k8s.io/apimachinery/pkg/util/sets"
3940)
4041
4142// VMAlertmanagerConfigSpec defines configuration for VMAlertmanagerConfig
@@ -121,12 +122,12 @@ func (r *VMAlertmanagerConfig) Validate() error {
121122 if MustSkipCRValidation (r ) {
122123 return nil
123124 }
124- receivers := make ( map [string ]struct {} )
125+ receivers := sets . New [string ]( )
125126 for idx , recv := range r .Spec .Receivers {
126- if _ , ok := receivers [ recv .Name ]; ok {
127+ if receivers . Has ( recv .Name ) {
127128 return fmt .Errorf ("notification config name %q is not unique" , recv .Name )
128129 }
129- receivers [ recv .Name ] = struct {}{}
130+ receivers . Insert ( recv .Name )
130131 if err := validateReceiver (recv ); err != nil {
131132 return fmt .Errorf ("receiver at idx=%d is invalid: %w" , idx , err )
132133 }
@@ -1506,17 +1507,17 @@ func parseTime(in string) (mins int, err error) {
15061507 return mins , nil
15071508}
15081509
1509- func validateTimeIntervals (timeIntervals []TimeIntervals ) (map [string ]struct {} , error ) {
1510- timeIntervalNames := make ( map [string ]struct {}, len ( timeIntervals ) )
1510+ func validateTimeIntervals (timeIntervals []TimeIntervals ) (sets. Set [string ], error ) {
1511+ timeIntervalNames := sets . New [string ]( )
15111512
15121513 for idx , ti := range timeIntervals {
15131514 if err := validateTimeIntervalsEntry (& ti ); err != nil {
15141515 return nil , fmt .Errorf ("time interval at idx=%d is invalid: %w" , idx , err )
15151516 }
1516- if _ , ok := timeIntervalNames [ ti .Name ]; ok {
1517+ if timeIntervalNames . Has ( ti .Name ) {
15171518 return nil , fmt .Errorf ("time interval at idx=%d is not unique with name=%q" , idx , ti .Name )
15181519 }
1519- timeIntervalNames [ ti .Name ] = struct {}{}
1520+ timeIntervalNames . Insert ( ti .Name )
15201521 }
15211522 return timeIntervalNames , nil
15221523}
@@ -1527,21 +1528,21 @@ var opsgenieTypeMatcher = regexp.MustCompile(opsgenieValidTypesRe)
15271528
15281529// checkRouteReceiver returns an error if a node in the routing tree
15291530// references a receiver not in the given map.
1530- func checkRouteReceiver (r * SubRoute , receivers map [string ]struct {} , tiNames map [string ]struct {} ) error {
1531+ func checkRouteReceiver (r * SubRoute , receivers sets. Set [string ], tiNames sets. Set [string ]) error {
15311532 for _ , ti := range r .ActiveTimeIntervals {
1532- if _ , ok := tiNames [ ti ]; ! ok {
1533+ if ! tiNames . Has ( ti ) {
15331534 return fmt .Errorf ("undefined time interval %q used in route" , ti )
15341535 }
15351536 }
15361537 for _ , ti := range r .MuteTimeIntervals {
1537- if _ , ok := tiNames [ ti ]; ! ok {
1538+ if ! tiNames . Has ( ti ) {
15381539 return fmt .Errorf ("undefined time interval %q used in route" , ti )
15391540 }
15401541 }
15411542 if r .Receiver == "" {
15421543 return nil
15431544 }
1544- if _ , ok := receivers [ r .Receiver ]; ! ok {
1545+ if ! receivers . Has ( r .Receiver ) {
15451546 return fmt .Errorf ("undefined receiver %q used in route" , r .Receiver )
15461547 }
15471548 for idx , sr := range r .Routes {
0 commit comments