This repository has been archived by the owner on Sep 2, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
/
sdn_transform.go
159 lines (130 loc) · 4.22 KB
/
sdn_transform.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
package transform
import (
"fmt"
"github.com/konveyor/cpma/pkg/decode"
"github.com/konveyor/cpma/pkg/env"
"github.com/konveyor/cpma/pkg/io"
"github.com/konveyor/cpma/pkg/transform/reportoutput"
"github.com/konveyor/cpma/pkg/transform/sdn"
legacyconfigv1 "github.com/openshift/api/legacyconfig/v1"
"github.com/sirupsen/logrus"
)
// SDNComponentName is the SDN component string
const SDNComponentName = "SDN"
// SDNExtraction is an SDN specific extraction
type SDNExtraction struct {
legacyconfigv1.MasterConfig
}
// SDNTransform is an SDN specific transform
type SDNTransform struct {
}
const clusterNetworkComment = `Networks must be configured during installation,
hostSubnetLength was replaced with hostPrefix in OCP4, default value was set to 23`
// Transform converts data collected from an OCP3 into a useful output
func (e SDNExtraction) Transform() ([]Output, error) {
outputs := []Output{}
if env.Config().GetBool("Manifests") {
logrus.Info("SDNTransform::Transform:Manifests")
manifests, err := e.buildManifestOutput()
if err != nil {
return nil, err
}
outputs = append(outputs, manifests)
}
if env.Config().GetBool("Reporting") {
logrus.Info("SDNTransform::Transform:Reports")
e.buildReportOutput()
}
return outputs, nil
}
func (e SDNExtraction) buildManifestOutput() (Output, error) {
var manifests []Manifest
networkCR, err := sdn.Translate(e.MasterConfig)
if err != nil {
return nil, err
}
networkCRYAML, err := GenYAML(networkCR)
if err != nil {
return nil, err
}
manifest := Manifest{Name: "100_CPMA-cluster-config-sdn.yaml", CRD: networkCRYAML}
manifests = append(manifests, manifest)
return ManifestOutput{
Manifests: manifests,
}, nil
}
func (e SDNExtraction) buildReportOutput() {
componentReport := reportoutput.ComponentReport{
Component: SDNComponentName,
}
for _, n := range e.MasterConfig.NetworkConfig.ClusterNetworks {
cidrComment := fmt.Sprintf("Networks must be configured during installation, it's possible to use %s", n.CIDR)
componentReport.Reports = append(componentReport.Reports,
reportoutput.Report{
Name: "CIDR",
Kind: "ClusterNetwork",
Supported: true,
Confidence: ModerateConfidence,
Comment: cidrComment,
})
componentReport.Reports = append(componentReport.Reports,
reportoutput.Report{
Name: "HostSubnetLength",
Kind: "ClusterNetwork",
Supported: false,
Confidence: NoConfidence,
Comment: clusterNetworkComment,
})
}
componentReport.Reports = append(componentReport.Reports,
reportoutput.Report{
Name: e.MasterConfig.NetworkConfig.ServiceNetworkCIDR,
Kind: "ServiceNetwork",
Supported: true,
Confidence: ModerateConfidence,
Comment: "Networks must be configured during installation",
})
componentReport.Reports = append(componentReport.Reports,
reportoutput.Report{
Name: "",
Kind: "ExternalIPNetworkCIDRs",
Supported: false,
Confidence: NoConfidence,
Comment: "Configuration of ExternalIPNetworkCIDRs is not supported in OCP4",
})
componentReport.Reports = append(componentReport.Reports,
reportoutput.Report{
Name: "",
Kind: "IngressIPNetworkCIDR",
Supported: false,
Confidence: NoConfidence,
Comment: "Translation of this configuration is not supported, refer to ingress operator configuration for more information",
})
FinalReportOutput.Report.ComponentReports = append(FinalReportOutput.Report.ComponentReports, componentReport)
}
// Extract collects SDN configuration information from an OCP3 cluster
func (e SDNTransform) Extract() (Extraction, error) {
logrus.Info("SDNTransform::Extract")
content, err := io.FetchFile(env.Config().GetString("MasterConfigFile"))
if err != nil {
return nil, err
}
masterConfig, err := decode.MasterConfig(content)
if err != nil {
return nil, err
}
var extraction SDNExtraction
extraction.MasterConfig = *masterConfig
return extraction, nil
}
// Validate the data extracted from the OCP3 cluster
func (e SDNExtraction) Validate() error {
if err := sdn.Validate(e.MasterConfig); err != nil {
return err
}
return nil
}
// Name returns a human readable name for the transform
func (e SDNTransform) Name() string {
return SDNComponentName
}