1
1
package manifests
2
2
3
3
import (
4
+ "fmt"
4
5
"os"
5
6
"path/filepath"
6
7
7
8
"github.com/ghodss/yaml"
8
9
"github.com/pkg/errors"
9
10
11
+ configv1 "github.com/openshift/api/config/v1"
10
12
"github.com/openshift/installer/pkg/asset"
11
13
"github.com/openshift/installer/pkg/asset/installconfig"
14
+ "github.com/openshift/installer/pkg/asset/templates/content/openshift"
12
15
13
- netopv1 "github.com/openshift/cluster-network-operator/pkg/apis/networkoperator/v1"
14
16
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
15
17
clusterv1a1 "sigs.k8s.io/cluster-api/pkg/apis/cluster/v1alpha1"
16
18
)
@@ -20,35 +22,18 @@ var (
20
22
noCfgFilename = filepath .Join (manifestDir , "cluster-network-02-config.yml" )
21
23
)
22
24
23
- const (
24
-
25
- // We need to manually create our CRD first, so we can create the
26
- // configuration instance of it.
27
- // Other operators have their CRD created by the CVO, but we manually
28
- // create our operator's configuration in the installer.
29
- netConfigCRD = `
30
- apiVersion: apiextensions.k8s.io/v1beta1
31
- kind: CustomResourceDefinition
32
- metadata:
33
- name: networkconfigs.networkoperator.openshift.io
34
- spec:
35
- group: networkoperator.openshift.io
36
- names:
37
- kind: NetworkConfig
38
- listKind: NetworkConfigList
39
- plural: networkconfigs
40
- singular: networkconfig
41
- scope: Cluster
42
- versions:
43
- - name: v1
44
- served: true
45
- storage: true
46
- `
47
- )
25
+ // We need to manually create our CRDs first, so we can create the
26
+ // configuration instance of it in the installer. Other operators have
27
+ // their CRD created by the CVO, but we need to create the corresponding
28
+ // CRs in the installer, so we need the CRD to be there.
29
+ // The first CRD is the high-level Network.config.openshift.io object,
30
+ // which is stable ahd minimal. Administrators can override configure the
31
+ // network in a more detailed manner with the operator-specific CR, which
32
+ // also needs to be done before the installer is run, so we provide both.
48
33
49
34
// Networking generates the cluster-network-*.yml files.
50
35
type Networking struct {
51
- config * netopv1. NetworkConfig
36
+ config * configv1. Network
52
37
FileList []* asset.File
53
38
}
54
39
@@ -64,60 +49,44 @@ func (no *Networking) Name() string {
64
49
func (no * Networking ) Dependencies () []asset.Asset {
65
50
return []asset.Asset {
66
51
& installconfig.InstallConfig {},
52
+ & openshift.NetworkCRDs {},
67
53
}
68
54
}
69
55
70
56
// Generate generates the network operator config and its CRD.
71
57
func (no * Networking ) Generate (dependencies asset.Parents ) error {
72
58
installConfig := & installconfig.InstallConfig {}
73
- dependencies .Get (installConfig )
59
+ crds := & openshift.NetworkCRDs {}
60
+ dependencies .Get (installConfig , crds )
74
61
75
62
netConfig := installConfig .Config .Networking
76
63
77
- // determine pod address space.
78
- // This can go away when we get rid of PodCIDR
79
- // entirely in favor of ClusterNetworks
80
- var clusterNets []netopv1.ClusterNetwork
64
+ clusterNet := []configv1.ClusterNetworkEntry {}
81
65
if len (netConfig .ClusterNetworks ) > 0 {
82
- clusterNets = netConfig .ClusterNetworks
83
- } else if ! netConfig .PodCIDR .IPNet .IP .IsUnspecified () {
84
- clusterNets = []netopv1.ClusterNetwork {
85
- {
86
- CIDR : netConfig .PodCIDR .String (),
87
- HostSubnetLength : 9 ,
88
- },
66
+ for _ , net := range netConfig .ClusterNetworks {
67
+ _ , size := net .CIDR .Mask .Size ()
68
+ clusterNet = append (clusterNet , configv1.ClusterNetworkEntry {
69
+ CIDR : net .CIDR .String (),
70
+ HostPrefix : uint32 (size ) - uint32 (net .HostSubnetLength ),
71
+ })
89
72
}
90
73
} else {
91
- return errors .Errorf ("Either PodCIDR or ClusterNetworks must be specified" )
92
- }
93
-
94
- defaultNet := netopv1.DefaultNetworkDefinition {
95
- Type : netConfig .Type ,
74
+ return errors .Errorf ("ClusterNetworks must be specified" )
96
75
}
97
76
98
- // Add any network-specific configuration defaults here.
99
- switch netConfig .Type {
100
- case netopv1 .NetworkTypeOpenshiftSDN :
101
- defaultNet .OpenshiftSDNConfig = & netopv1.OpenshiftSDNConfig {
102
- // Default to network policy, operator provides all other defaults.
103
- Mode : netopv1 .SDNModePolicy ,
104
- }
105
- }
106
-
107
- no .config = & netopv1.NetworkConfig {
77
+ no .config = & configv1.Network {
108
78
TypeMeta : metav1.TypeMeta {
109
- APIVersion : netopv1 .SchemeGroupVersion .String (),
110
- Kind : "NetworkConfig " ,
79
+ APIVersion : configv1 .SchemeGroupVersion .String (),
80
+ Kind : "Network " ,
111
81
},
112
82
ObjectMeta : metav1.ObjectMeta {
113
- Name : "default " ,
83
+ Name : "cluster " ,
114
84
// not namespaced
115
85
},
116
-
117
- Spec : netopv1.NetworkConfigSpec {
118
- ServiceNetwork : netConfig .ServiceCIDR .String (),
119
- ClusterNetworks : clusterNets ,
120
- DefaultNetwork : defaultNet ,
86
+ Spec : configv1.NetworkSpec {
87
+ ClusterNetwork : clusterNet ,
88
+ ServiceNetwork : []string {netConfig .ServiceCIDR .String ()},
89
+ NetworkType : netConfig .Type ,
121
90
},
122
91
}
123
92
@@ -126,10 +95,15 @@ func (no *Networking) Generate(dependencies asset.Parents) error {
126
95
return errors .Wrapf (err , "failed to create %s manifests from InstallConfig" , no .Name ())
127
96
}
128
97
98
+ crdContents := ""
99
+ for _ , crdFile := range crds .Files () {
100
+ crdContents = fmt .Sprintf ("%s\n ---\n %s" , crdContents , crdFile .Data )
101
+ }
102
+
129
103
no .FileList = []* asset.File {
130
104
{
131
105
Filename : noCrdFilename ,
132
- Data : []byte (netConfigCRD ),
106
+ Data : []byte (crdContents ),
133
107
},
134
108
{
135
109
Filename : noCfgFilename ,
@@ -155,13 +129,13 @@ func (no *Networking) ClusterNetwork() (*clusterv1a1.ClusterNetworkingConfig, er
155
129
}
156
130
157
131
pods := []string {}
158
- for _ , cn := range no .config .Spec .ClusterNetworks {
132
+ for _ , cn := range no .config .Spec .ClusterNetwork {
159
133
pods = append (pods , cn .CIDR )
160
134
}
161
135
162
136
cn := & clusterv1a1.ClusterNetworkingConfig {
163
137
Services : clusterv1a1.NetworkRanges {
164
- CIDRBlocks : [] string { no .config .Spec .ServiceNetwork } ,
138
+ CIDRBlocks : no .config .Spec .ServiceNetwork ,
165
139
},
166
140
Pods : clusterv1a1.NetworkRanges {
167
141
CIDRBlocks : pods ,
@@ -189,7 +163,7 @@ func (no *Networking) Load(f asset.FileFetcher) (bool, error) {
189
163
return false , err
190
164
}
191
165
192
- netConfig := & netopv1. NetworkConfig {}
166
+ netConfig := & configv1. Network {}
193
167
if err := yaml .Unmarshal (cfgFile .Data , netConfig ); err != nil {
194
168
return false , errors .Wrapf (err , "failed to unmarshal %s" , noCfgFilename )
195
169
}
0 commit comments