2023-08-15 21:47:29 +03:00
|
|
|
package main
|
|
|
|
|
|
|
|
// Copyright (c) Microsoft Corporation.
|
|
|
|
// Licensed under the Apache License 2.0.
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"os"
|
|
|
|
|
|
|
|
corev1 "k8s.io/api/core/v1"
|
|
|
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
2024-07-10 02:57:42 +03:00
|
|
|
"sigs.k8s.io/yaml"
|
2023-08-15 21:47:29 +03:00
|
|
|
|
|
|
|
failure "github.com/Azure/ARO-RP/pkg/hive/failure"
|
|
|
|
utillog "github.com/Azure/ARO-RP/pkg/util/log"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
hiveNamespaceName = "hive"
|
|
|
|
configMapName = "additional-install-log-regexes"
|
|
|
|
regexDataEntryName = "regexes"
|
|
|
|
)
|
|
|
|
|
|
|
|
type installLogRegex struct {
|
|
|
|
Name string `json:"name"`
|
|
|
|
SearchRegexStrings []string `json:"searchRegexStrings"`
|
|
|
|
InstallFailingReason string `json:"installFailingReason"`
|
|
|
|
InstallFailingMessage string `json:"installFailingMessage"`
|
|
|
|
}
|
|
|
|
|
2023-08-23 20:53:12 +03:00
|
|
|
func run(ctx context.Context, path string) error {
|
2023-08-15 21:47:29 +03:00
|
|
|
ilrs := []installLogRegex{}
|
|
|
|
|
|
|
|
for _, reason := range failure.Reasons {
|
|
|
|
ilrs = append(ilrs, failureReasonToInstallLogRegex(reason))
|
|
|
|
}
|
|
|
|
|
|
|
|
ilrsRaw, err := yaml.Marshal(ilrs)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
configmap := &corev1.ConfigMap{
|
|
|
|
TypeMeta: metav1.TypeMeta{
|
|
|
|
APIVersion: corev1.SchemeGroupVersion.String(),
|
|
|
|
Kind: "ConfigMap",
|
|
|
|
},
|
|
|
|
ObjectMeta: metav1.ObjectMeta{
|
|
|
|
Namespace: hiveNamespaceName,
|
|
|
|
Name: configMapName,
|
|
|
|
},
|
|
|
|
Data: map[string]string{
|
|
|
|
regexDataEntryName: string(ilrsRaw),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
configmapRaw, err := yaml.Marshal(configmap)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2023-08-23 20:53:12 +03:00
|
|
|
|
|
|
|
if path != "" {
|
|
|
|
return os.WriteFile(path, configmapRaw, 0666)
|
|
|
|
} else {
|
|
|
|
print(string(configmapRaw))
|
|
|
|
return nil
|
|
|
|
}
|
2023-08-15 21:47:29 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func failureReasonToInstallLogRegex(reason failure.InstallFailingReason) installLogRegex {
|
|
|
|
ilr := installLogRegex{
|
|
|
|
Name: reason.Name,
|
|
|
|
InstallFailingReason: reason.Reason,
|
|
|
|
InstallFailingMessage: reason.Message,
|
|
|
|
SearchRegexStrings: []string{},
|
|
|
|
}
|
|
|
|
for _, regex := range reason.SearchRegexes {
|
|
|
|
ilr.SearchRegexStrings = append(ilr.SearchRegexStrings, regex.String())
|
|
|
|
}
|
|
|
|
return ilr
|
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
log := utillog.GetLogger()
|
|
|
|
|
2023-08-23 20:53:12 +03:00
|
|
|
path := ""
|
|
|
|
if len(os.Args) > 1 {
|
|
|
|
path = os.Args[1]
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := run(context.Background(), path); err != nil {
|
2023-08-15 21:47:29 +03:00
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|