@@ -5,37 +5,35 @@ import (
55 "github.com/aws/aws-sdk-go-v2/aws"
66 "github.com/jackc/pgtype"
77 kedav1alpha1 "github.com/kedacore/keda/v2/apis/keda/v1alpha1"
8- "github.com/opengovern/opensecurity/services/tasks/config"
98 "github.com/opengovern/opensecurity/services/tasks/db/models"
10- "github.com/opengovern/opensecurity/services/tasks/worker/consts"
119 "golang.org/x/net/context"
1210 appsv1 "k8s.io/api/apps/v1"
1311 corev1 "k8s.io/api/core/v1"
1412 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1513 "os"
1614 "sigs.k8s.io/controller-runtime/pkg/client"
17- "strconv"
1815)
1916
20- var (
21- ESAddress = os .Getenv ("ELASTICSEARCH_ADDRESS" )
22- ESUsername = os .Getenv ("ELASTICSEARCH_USERNAME" )
23- ESPassword = os .Getenv ("ELASTICSEARCH_PASSWORD" )
24- ESIsOnAks = os .Getenv ("ELASTICSEARCH_ISONAKS" )
25-
26- InventoryBaseURL = os .Getenv ("CORE_BASEURL" )
27- )
28-
29- func CreateWorker (ctx context.Context , cfg config.Config , kubeClient client.Client , taskConfig * models.Task , namespace string ) error {
17+ func CreateWorker (ctx context.Context , kubeClient client.Client , taskConfig * models.Task , namespace string ) error {
3018 soNatsUrl , _ := os .LookupEnv ("SCALED_OBJECT_NATS_URL" )
3119
32- env , err := defaultEnvs (cfg , taskConfig )
33- if err != nil {
34- return err
20+ var envVars map [string ]string
21+ if taskConfig .EnvVars .Status == pgtype .Present {
22+ if err := json .Unmarshal (taskConfig .EnvVars .Bytes , & envVars ); err != nil {
23+ return err
24+ }
25+ }
26+
27+ var env []corev1.EnvVar
28+ for k , v := range envVars {
29+ env = append (env , corev1.EnvVar {
30+ Name : k ,
31+ Value : v ,
32+ })
3533 }
3634
3735 var deployment appsv1.Deployment
38- err = kubeClient .Get (ctx , client.ObjectKey {
36+ err : = kubeClient .Get (ctx , client.ObjectKey {
3937 Namespace : namespace ,
4038 Name : taskConfig .ID ,
4139 }, & deployment )
@@ -77,15 +75,15 @@ func CreateWorker(ctx context.Context, cfg config.Config, kubeClient client.Clie
7775 },
7876 },
7977 }
80- err : = kubeClient .Create (ctx , & deployment )
78+ err = kubeClient .Create (ctx , & deployment )
8179 if err != nil {
8280 return err
8381 }
8482 }
8583
8684 var scaleConfig ScaleConfig
8785 if taskConfig .ScaleConfig .Status == pgtype .Present {
88- if err : = json .Unmarshal (taskConfig .ScaleConfig .Bytes , & scaleConfig ); err != nil {
86+ if err = json .Unmarshal (taskConfig .ScaleConfig .Bytes , & scaleConfig ); err != nil {
8987 return err
9088 }
9189 }
@@ -139,67 +137,3 @@ func CreateWorker(ctx context.Context, cfg config.Config, kubeClient client.Clie
139137
140138 return nil
141139}
142-
143- func defaultEnvs (cfg config.Config , taskConfig * models.Task ) ([]corev1.EnvVar , error ) {
144- var natsConfig NatsConfig
145- if taskConfig .NatsConfig .Status == pgtype .Present {
146- if err := json .Unmarshal (taskConfig .NatsConfig .Bytes , & natsConfig ); err != nil {
147- return nil , err
148- }
149- }
150-
151- return []corev1.EnvVar {
152- {
153- Name : consts .NatsURLEnv ,
154- Value : cfg .NATS .URL ,
155- },
156- {
157- Name : consts .NatsConsumerEnv ,
158- Value : natsConfig .Consumer ,
159- },
160- {
161- Name : consts .NatsStreamNameEnv ,
162- Value : natsConfig .Stream ,
163- },
164- {
165- Name : consts .NatsTopicNameEnv ,
166- Value : natsConfig .Topic ,
167- },
168- {
169- Name : consts .NatsResultTopicNameEnv ,
170- Value : natsConfig .ResultTopic ,
171- },
172- {
173- Name : consts .ElasticSearchAddressEnv ,
174- Value : ESAddress ,
175- },
176- {
177- Name : consts .ElasticSearchUsernameEnv ,
178- Value : ESUsername ,
179- },
180- {
181- Name : consts .ElasticSearchPasswordEnv ,
182- Value : ESPassword ,
183- },
184- {
185- Name : consts .ElasticSearchIsOnAksNameEnv ,
186- Value : ESIsOnAks ,
187- },
188- {
189- Name : consts .ElasticSearchIsOpenSearch ,
190- Value : strconv .FormatBool (cfg .ElasticSearch .IsOpenSearch ),
191- },
192- {
193- Name : consts .ElasticSearchAwsRegionEnv ,
194- Value : "" ,
195- },
196- {
197- Name : consts .ElasticSearchAssumeRoleArnEnv ,
198- Value : "" ,
199- },
200- {
201- Name : consts .InventoryBaseURL ,
202- Value : InventoryBaseURL ,
203- },
204- }, nil
205- }
0 commit comments