@@ -15,7 +15,6 @@ import (
1515 akov2 "github.com/mongodb/mongodb-atlas-kubernetes/v2/pkg/api/v1"
1616 "github.com/mongodb/mongodb-atlas-kubernetes/v2/pkg/api/v1/common"
1717 "github.com/mongodb/mongodb-atlas-kubernetes/v2/pkg/api/v1/status"
18- "github.com/mongodb/mongodb-atlas-kubernetes/v2/pkg/controller/watch"
1918 "github.com/mongodb/mongodb-atlas-kubernetes/v2/pkg/controller/workflow"
2019)
2120
@@ -51,62 +50,50 @@ func (r *AtlasProjectReconciler) ensureAlertConfigurations(service *workflow.Con
5150
5251// This method reads secrets refs and fills the secret data for the related Notification
5352func (r * AtlasProjectReconciler ) readAlertConfigurationsSecretsData (project * akov2.AtlasProject , service * workflow.Context , alertConfigs []akov2.AlertConfiguration ) error {
54- resourcesToWatch := make ([]watch.WatchedObject , 0 )
5553 projectNs := project .Namespace
56- defer func () {
57- service .AddResourcesToWatch (resourcesToWatch ... )
58- r .Log .Debugf ("watching alert configuration secrets: %v\r \n " , r .DeprecatedResourceWatcher .WatchedResourcesSnapshot ())
59- }()
6054
6155 for i := 0 ; i < len (alertConfigs ); i ++ {
6256 ac := & alertConfigs [i ]
6357 for j := 0 ; j < len (ac .Notifications ); j ++ {
6458 nf := & ac .Notifications [j ]
6559 switch {
6660 case nf .APITokenRef .Name != "" :
67- token , res , err := readNotificationSecret (service .Context , r .Client , nf .APITokenRef , projectNs , "APIToken" )
68- resourcesToWatch = append (resourcesToWatch , * res )
61+ token , err := readNotificationSecret (service .Context , r .Client , nf .APITokenRef , projectNs , "APIToken" )
6962 if err != nil {
7063 return err
7164 }
7265 nf .SetAPIToken (token )
7366 case nf .DatadogAPIKeyRef .Name != "" :
74- token , res , err := readNotificationSecret (service .Context , r .Client , nf .DatadogAPIKeyRef , projectNs , "DatadogAPIKey" )
75- resourcesToWatch = append (resourcesToWatch , * res )
67+ token , err := readNotificationSecret (service .Context , r .Client , nf .DatadogAPIKeyRef , projectNs , "DatadogAPIKey" )
7668 if err != nil {
7769 return err
7870 }
7971 nf .SetDatadogAPIKey (token )
8072 case nf .FlowdockAPITokenRef .Name != "" :
81- token , res , err := readNotificationSecret (service .Context , r .Client , nf .FlowdockAPITokenRef , projectNs , "FlowdockAPIToken" )
82- resourcesToWatch = append (resourcesToWatch , * res )
73+ token , err := readNotificationSecret (service .Context , r .Client , nf .FlowdockAPITokenRef , projectNs , "FlowdockAPIToken" )
8374 if err != nil {
8475 return err
8576 }
8677 nf .SetFlowdockAPIToken (token )
8778 case nf .OpsGenieAPIKeyRef .Name != "" :
88- token , res , err := readNotificationSecret (service .Context , r .Client , nf .OpsGenieAPIKeyRef , projectNs , "OpsGenieAPIKey" )
89- resourcesToWatch = append (resourcesToWatch , * res )
79+ token , err := readNotificationSecret (service .Context , r .Client , nf .OpsGenieAPIKeyRef , projectNs , "OpsGenieAPIKey" )
9080 if err != nil {
9181 return err
9282 }
9383 nf .SetOpsGenieAPIKey (token )
9484 case nf .ServiceKeyRef .Name != "" :
95- token , res , err := readNotificationSecret (service .Context , r .Client , nf .ServiceKeyRef , projectNs , "ServiceKey" )
96- resourcesToWatch = append (resourcesToWatch , * res )
85+ token , err := readNotificationSecret (service .Context , r .Client , nf .ServiceKeyRef , projectNs , "ServiceKey" )
9786 if err != nil {
9887 return err
9988 }
10089 nf .SetServiceKey (token )
10190 case nf .VictorOpsSecretRef .Name != "" :
102- token , res , err := readNotificationSecret (service .Context , r .Client , nf .VictorOpsSecretRef , projectNs , "VictorOpsAPIKey" )
103- resourcesToWatch = append (resourcesToWatch , * res )
91+ token , err := readNotificationSecret (service .Context , r .Client , nf .VictorOpsSecretRef , projectNs , "VictorOpsAPIKey" )
10492 if err != nil {
10593 return err
10694 }
10795 nf .SetVictorOpsAPIKey (token )
108- token , res , err = readNotificationSecret (service .Context , r .Client , nf .VictorOpsSecretRef , projectNs , "VictorOpsRoutingKey" )
109- resourcesToWatch = append (resourcesToWatch , * res )
96+ token , err = readNotificationSecret (service .Context , r .Client , nf .VictorOpsSecretRef , projectNs , "VictorOpsRoutingKey" )
11097 if err != nil {
11198 return err
11299 }
@@ -117,7 +104,7 @@ func (r *AtlasProjectReconciler) readAlertConfigurationsSecretsData(project *ako
117104 return nil
118105}
119106
120- func readNotificationSecret (ctx context.Context , kubeClient client.Client , res common.ResourceRefNamespaced , parentNamespace string , fieldName string ) (string , * watch. WatchedObject , error ) {
107+ func readNotificationSecret (ctx context.Context , kubeClient client.Client , res common.ResourceRefNamespaced , parentNamespace string , fieldName string ) (string , error ) {
121108 secret := & v1.Secret {}
122109 var ns string
123110 if res .Namespace == "" {
@@ -127,19 +114,18 @@ func readNotificationSecret(ctx context.Context, kubeClient client.Client, res c
127114 }
128115
129116 secretObj := client.ObjectKey {Name : res .Name , Namespace : ns }
130- obj := & watch.WatchedObject {ResourceKind : "Secret" , Resource : secretObj }
131117
132118 if err := kubeClient .Get (ctx , secretObj , secret ); err != nil {
133- return "" , obj , err
119+ return "" , err
134120 }
135121 val , exists := secret .Data [fieldName ]
136122 switch {
137123 case ! exists :
138- return "" , obj , fmt .Errorf ("secret '%s/%s' doesn't contain '%s' parameter" , ns , res .Name , fieldName )
124+ return "" , fmt .Errorf ("secret '%s/%s' doesn't contain '%s' parameter" , ns , res .Name , fieldName )
139125 case len (val ) == 0 :
140- return "" , obj , fmt .Errorf ("secret '%s/%s' contains an empty value for '%s' parameter" , ns , res .Name , fieldName )
126+ return "" , fmt .Errorf ("secret '%s/%s' contains an empty value for '%s' parameter" , ns , res .Name , fieldName )
141127 }
142- return string (val ), obj , nil
128+ return string (val ), nil
143129}
144130
145131func syncAlertConfigurations (service * workflow.Context , groupID string , alertSpec []akov2.AlertConfiguration ) workflow.Result {
0 commit comments