Skip to content

Commit e4898af

Browse files
committed
fix: reorder nic jobs
1 parent 87379b4 commit e4898af

File tree

1 file changed

+88
-88
lines changed

1 file changed

+88
-88
lines changed

pkg/jobs/nic_job_list.go

Lines changed: 88 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -75,94 +75,6 @@ func getNginxIngressPod(dc *data_collector.DataCollector, ctx context.Context) (
7575

7676
func NICJobList() []Job {
7777
jobList := []Job{
78-
{
79-
Name: "parse-entitlement",
80-
Timeout: time.Second * 10,
81-
Execute: func(dc *data_collector.DataCollector, ctx context.Context, ch chan JobResult) {
82-
jobResult := JobResult{Files: make(map[string][]byte), Error: nil}
83-
84-
ingressPod, err := getNginxIngressPod(dc, ctx)
85-
if err != nil {
86-
dc.Logger.Printf("\tCould not find nginx-ingress pod: %v\n", err)
87-
jobResult.Error = err
88-
ch <- jobResult
89-
return
90-
}
91-
92-
for _, container := range ingressPod.Spec.Containers {
93-
if container.Name == "nginx-ingress" {
94-
for _, arg := range container.Args {
95-
if strings.Contains(arg, "mgmt-configmap") {
96-
configMapString := strings.SplitN(arg, "=", 2)
97-
if len(configMapString) != 2 {
98-
dc.Logger.Printf("\tCould not parse mgmt-configmap argument: %s\n", arg)
99-
jobResult.Error = fmt.Errorf("could not parse mgmt-configmap argument: %s", arg)
100-
ch <- jobResult
101-
return
102-
}
103-
configMapName := strings.Split(configMapString[1], "/")[1]
104-
configMapNamespace := strings.Replace(strings.Split(configMapString[1], "/")[0], "$(POD_NAMESPACE)", ingressPod.Namespace, 1)
105-
106-
configMap, err := dc.K8sCoreClientSet.CoreV1().ConfigMaps(configMapNamespace).Get(ctx, configMapName, metav1.GetOptions{})
107-
if err != nil {
108-
dc.Logger.Printf("\tCould not retrieve ConfigMap %s in namespace %s: %v\n", configMapName, configMapNamespace, err)
109-
jobResult.Error = err
110-
ch <- jobResult
111-
return
112-
}
113-
114-
licenseTokenSecretName, exists := configMap.Data["license-token-secret-name"]
115-
if !exists {
116-
dc.Logger.Printf("\tConfigMap %s in namespace %s does not contain 'license-token-secret-name' key\n", configMapName, configMapNamespace)
117-
jobResult.Error = fmt.Errorf("configmap %s in namespace %s does not contain 'license-token-secret-name' key", configMapName, configMapNamespace)
118-
ch <- jobResult
119-
return
120-
}
121-
122-
licenseTokenSecret, err := dc.K8sCoreClientSet.CoreV1().Secrets(configMapNamespace).Get(ctx, licenseTokenSecretName, metav1.GetOptions{})
123-
if err != nil {
124-
dc.Logger.Printf("\tCould not retrieve Secret %s in namespace %s: %v\n", licenseTokenSecretName, configMapNamespace, err)
125-
jobResult.Error = err
126-
ch <- jobResult
127-
return
128-
}
129-
130-
licenseToken, exists := licenseTokenSecret.Data["license.jwt"]
131-
if !exists {
132-
dc.Logger.Printf("\tSecret %s in namespace %s does not contain 'license.jwt' key\n", licenseTokenSecretName, configMapNamespace)
133-
jobResult.Error = fmt.Errorf("secret %s in namespace %s does not contain 'license.jwt' key", licenseTokenSecretName, configMapNamespace)
134-
ch <- jobResult
135-
return
136-
}
137-
138-
claim := strings.Split(string(licenseToken), ".")[1]
139-
decodedClaim, err := base64.RawStdEncoding.DecodeString(claim)
140-
if err != nil {
141-
dc.Logger.Printf("\tCould not decode license token claim from Secret %s in namespace %s: %v\n", licenseTokenSecretName, configMapNamespace, err)
142-
jobResult.Error = err
143-
ch <- jobResult
144-
return
145-
}
146-
147-
var prettyJSON bytes.Buffer
148-
err = json.Indent(&prettyJSON, decodedClaim, "", " ")
149-
if err != nil {
150-
dc.Logger.Printf("\tCould not format license token claim JSON from Secret %s in namespace %s: %v\n", licenseTokenSecretName, configMapNamespace, err)
151-
jobResult.Error = err
152-
ch <- jobResult
153-
return
154-
}
155-
156-
fileName := fmt.Sprintf("%s_payload.json", licenseTokenSecretName)
157-
jobResult.Files[filepath.Join(dc.BaseDir, "entitlement", ingressPod.Namespace, fileName)] = prettyJSON.Bytes()
158-
break
159-
}
160-
}
161-
}
162-
}
163-
ch <- jobResult
164-
},
165-
},
16678
{
16779
Name: "exec-nginx-ingress-version",
16880
Timeout: time.Second * 10,
@@ -349,6 +261,94 @@ func NICJobList() []Job {
349261
ch <- jobResult
350262
},
351263
},
264+
{
265+
Name: "parse-entitlement",
266+
Timeout: time.Second * 10,
267+
Execute: func(dc *data_collector.DataCollector, ctx context.Context, ch chan JobResult) {
268+
jobResult := JobResult{Files: make(map[string][]byte), Error: nil}
269+
270+
ingressPod, err := getNginxIngressPod(dc, ctx)
271+
if err != nil {
272+
dc.Logger.Printf("\tCould not find nginx-ingress pod: %v\n", err)
273+
jobResult.Error = err
274+
ch <- jobResult
275+
return
276+
}
277+
278+
for _, container := range ingressPod.Spec.Containers {
279+
if container.Name == "nginx-ingress" {
280+
for _, arg := range container.Args {
281+
if strings.Contains(arg, "mgmt-configmap") {
282+
configMapString := strings.SplitN(arg, "=", 2)
283+
if len(configMapString) != 2 {
284+
dc.Logger.Printf("\tCould not parse mgmt-configmap argument: %s\n", arg)
285+
jobResult.Error = fmt.Errorf("could not parse mgmt-configmap argument: %s", arg)
286+
ch <- jobResult
287+
return
288+
}
289+
configMapName := strings.Split(configMapString[1], "/")[1]
290+
configMapNamespace := strings.Replace(strings.Split(configMapString[1], "/")[0], "$(POD_NAMESPACE)", ingressPod.Namespace, 1)
291+
292+
configMap, err := dc.K8sCoreClientSet.CoreV1().ConfigMaps(configMapNamespace).Get(ctx, configMapName, metav1.GetOptions{})
293+
if err != nil {
294+
dc.Logger.Printf("\tCould not retrieve ConfigMap %s in namespace %s: %v\n", configMapName, configMapNamespace, err)
295+
jobResult.Error = err
296+
ch <- jobResult
297+
return
298+
}
299+
300+
licenseTokenSecretName, exists := configMap.Data["license-token-secret-name"]
301+
if !exists {
302+
dc.Logger.Printf("\tConfigMap %s in namespace %s does not contain 'license-token-secret-name' key\n", configMapName, configMapNamespace)
303+
jobResult.Error = fmt.Errorf("configmap %s in namespace %s does not contain 'license-token-secret-name' key", configMapName, configMapNamespace)
304+
ch <- jobResult
305+
return
306+
}
307+
308+
licenseTokenSecret, err := dc.K8sCoreClientSet.CoreV1().Secrets(configMapNamespace).Get(ctx, licenseTokenSecretName, metav1.GetOptions{})
309+
if err != nil {
310+
dc.Logger.Printf("\tCould not retrieve Secret %s in namespace %s: %v\n", licenseTokenSecretName, configMapNamespace, err)
311+
jobResult.Error = err
312+
ch <- jobResult
313+
return
314+
}
315+
316+
licenseToken, exists := licenseTokenSecret.Data["license.jwt"]
317+
if !exists {
318+
dc.Logger.Printf("\tSecret %s in namespace %s does not contain 'license.jwt' key\n", licenseTokenSecretName, configMapNamespace)
319+
jobResult.Error = fmt.Errorf("secret %s in namespace %s does not contain 'license.jwt' key", licenseTokenSecretName, configMapNamespace)
320+
ch <- jobResult
321+
return
322+
}
323+
324+
claim := strings.Split(string(licenseToken), ".")[1]
325+
decodedClaim, err := base64.RawStdEncoding.DecodeString(claim)
326+
if err != nil {
327+
dc.Logger.Printf("\tCould not decode license token claim from Secret %s in namespace %s: %v\n", licenseTokenSecretName, configMapNamespace, err)
328+
jobResult.Error = err
329+
ch <- jobResult
330+
return
331+
}
332+
333+
var prettyJSON bytes.Buffer
334+
err = json.Indent(&prettyJSON, decodedClaim, "", " ")
335+
if err != nil {
336+
dc.Logger.Printf("\tCould not format license token claim JSON from Secret %s in namespace %s: %v\n", licenseTokenSecretName, configMapNamespace, err)
337+
jobResult.Error = err
338+
ch <- jobResult
339+
return
340+
}
341+
342+
fileName := fmt.Sprintf("%s_payload.json", licenseTokenSecretName)
343+
jobResult.Files[filepath.Join(dc.BaseDir, "entitlement", ingressPod.Namespace, fileName)] = prettyJSON.Bytes()
344+
break
345+
}
346+
}
347+
}
348+
}
349+
ch <- jobResult
350+
},
351+
},
352352
}
353353
return jobList
354354
}

0 commit comments

Comments
 (0)