Skip to content

Commit dafc79f

Browse files
committed
Generate Network.cluster config instead of NetworkConfig.networkoperator
* Add the Network.config.openshift.io CRD * Generate the network config from the install config * Remove networkoperator types from install config (but use the same schema) * Move network CRDs to templates to match #943 This doesn't change the json/yaml serialization of the install config, but it changes it internally.
1 parent 749d9e5 commit dafc79f

File tree

13 files changed

+214
-197
lines changed

13 files changed

+214
-197
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
apiVersion: apiextensions.k8s.io/v1beta1
2+
kind: CustomResourceDefinition
3+
metadata:
4+
name: networks.config.openshift.io
5+
spec:
6+
group: config.openshift.io
7+
names:
8+
kind: Network
9+
listKind: NetworkList
10+
plural: networks
11+
singular: network
12+
scope: Cluster
13+
versions:
14+
- name: v1
15+
served: true
16+
storage: true
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# This is the advanced network configuration CRD
2+
# Only necessary if you need to tweak certain settings.
3+
# See https://github.com/openshift/cluster-network-operator#configuring
4+
apiVersion: apiextensions.k8s.io/v1beta1
5+
kind: CustomResourceDefinition
6+
metadata:
7+
name: networkconfigs.networkoperator.openshift.io
8+
spec:
9+
group: networkoperator.openshift.io
10+
names:
11+
kind: NetworkConfig
12+
listKind: NetworkConfigList
13+
plural: networkconfigs
14+
singular: networkconfig
15+
scope: Cluster
16+
versions:
17+
- name: v1
18+
served: true
19+
storage: true

docs/user/troubleshooting.md

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -224,19 +224,18 @@ From a deployment perspective, the network operator is often the "canary in the
224224
First, determine that the network configuration exists:
225225

226226
```console
227-
$ kubectl get networkconfigs.networkoperator.openshift.io default -oyaml
228-
...
227+
$ kubectl get network.config.openshift.io cluster -oyaml
228+
apiVersion: config.openshift.io/v1
229+
kind: Network
230+
metadata:
231+
name: cluster
229232
spec:
230-
additionalNetworks: null
231-
clusterNetworks:
232-
- cidr: 10.2.0.0/16
233-
hostSubnetLength: 9
234-
defaultNetwork:
235-
openshiftSDNConfig:
236-
mode: Networkpolicy
237-
otherConfig: null
238-
type: OpenshiftSDN
239-
serviceNetwork: 10.3.0.0/16
233+
serviceNetwork:
234+
- 172.30.0.0/16
235+
clusterNetwork:
236+
- cidr: 10.128.0.0/14
237+
hostPrefix: 23
238+
networkType: OpenShiftSDN
240239
```
241240

242241
If it doesn't exist, the installer didn't create it. You'll have to run `openshift-install create manifests` to determine why.

pkg/asset/installconfig/installconfig_test.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"testing"
77

88
"github.com/golang/mock/gomock"
9-
netopv1 "github.com/openshift/cluster-network-operator/pkg/apis/networkoperator/v1"
109
"github.com/stretchr/testify/assert"
1110
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1211

@@ -66,11 +65,11 @@ func TestInstallConfigGenerate_FillsInDefaults(t *testing.T) {
6665
BaseDomain: "test-domain",
6766
Networking: &types.Networking{
6867
MachineCIDR: ipnet.MustParseCIDR("10.0.0.0/16"),
69-
Type: "OpenshiftSDN",
68+
Type: "OpenShiftSDN",
7069
ServiceCIDR: ipnet.MustParseCIDR("172.30.0.0/16"),
71-
ClusterNetworks: []netopv1.ClusterNetwork{
70+
ClusterNetworks: []types.ClusterNetworkEntry{
7271
{
73-
CIDR: "10.128.0.0/14",
72+
CIDR: *ipnet.MustParseCIDR("10.128.0.0/14"),
7473
HostSubnetLength: 9,
7574
},
7675
},
@@ -125,11 +124,11 @@ pullSecret: "{\"auths\":{\"example.com\":{\"auth\":\"authorization value\"}}}"
125124
BaseDomain: "test-domain",
126125
Networking: &types.Networking{
127126
MachineCIDR: ipnet.MustParseCIDR("10.0.0.0/16"),
128-
Type: "OpenshiftSDN",
127+
Type: "OpenShiftSDN",
129128
ServiceCIDR: ipnet.MustParseCIDR("172.30.0.0/16"),
130-
ClusterNetworks: []netopv1.ClusterNetwork{
129+
ClusterNetworks: []types.ClusterNetworkEntry{
131130
{
132-
CIDR: "10.128.0.0/14",
131+
CIDR: *ipnet.MustParseCIDR("10.128.0.0/14"),
133132
HostSubnetLength: 9,
134133
},
135134
},

pkg/asset/manifests/network.go

Lines changed: 40 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
package manifests
22

33
import (
4+
"fmt"
45
"os"
56
"path/filepath"
67

78
"github.com/ghodss/yaml"
89
"github.com/pkg/errors"
910

11+
configv1 "github.com/openshift/api/config/v1"
1012
"github.com/openshift/installer/pkg/asset"
1113
"github.com/openshift/installer/pkg/asset/installconfig"
14+
"github.com/openshift/installer/pkg/asset/templates/content/openshift"
1215

13-
netopv1 "github.com/openshift/cluster-network-operator/pkg/apis/networkoperator/v1"
1416
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1517
clusterv1a1 "sigs.k8s.io/cluster-api/pkg/apis/cluster/v1alpha1"
1618
)
@@ -20,35 +22,18 @@ var (
2022
noCfgFilename = filepath.Join(manifestDir, "cluster-network-02-config.yml")
2123
)
2224

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.
4833

4934
// Networking generates the cluster-network-*.yml files.
5035
type Networking struct {
51-
config *netopv1.NetworkConfig
36+
config *configv1.Network
5237
FileList []*asset.File
5338
}
5439

@@ -64,60 +49,44 @@ func (no *Networking) Name() string {
6449
func (no *Networking) Dependencies() []asset.Asset {
6550
return []asset.Asset{
6651
&installconfig.InstallConfig{},
52+
&openshift.NetworkCRDs{},
6753
}
6854
}
6955

7056
// Generate generates the network operator config and its CRD.
7157
func (no *Networking) Generate(dependencies asset.Parents) error {
7258
installConfig := &installconfig.InstallConfig{}
73-
dependencies.Get(installConfig)
59+
crds := &openshift.NetworkCRDs{}
60+
dependencies.Get(installConfig, crds)
7461

7562
netConfig := installConfig.Config.Networking
7663

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{}
8165
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+
})
8972
}
9073
} 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")
9675
}
9776

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{
10878
TypeMeta: metav1.TypeMeta{
109-
APIVersion: netopv1.SchemeGroupVersion.String(),
110-
Kind: "NetworkConfig",
79+
APIVersion: configv1.SchemeGroupVersion.String(),
80+
Kind: "Network",
11181
},
11282
ObjectMeta: metav1.ObjectMeta{
113-
Name: "default",
83+
Name: "cluster",
11484
// not namespaced
11585
},
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,
12190
},
12291
}
12392

@@ -126,10 +95,15 @@ func (no *Networking) Generate(dependencies asset.Parents) error {
12695
return errors.Wrapf(err, "failed to create %s manifests from InstallConfig", no.Name())
12796
}
12897

98+
crdContents := ""
99+
for _, crdFile := range crds.Files() {
100+
crdContents = fmt.Sprintf("%s\n---\n%s", crdContents, crdFile.Data)
101+
}
102+
129103
no.FileList = []*asset.File{
130104
{
131105
Filename: noCrdFilename,
132-
Data: []byte(netConfigCRD),
106+
Data: []byte(crdContents),
133107
},
134108
{
135109
Filename: noCfgFilename,
@@ -155,13 +129,13 @@ func (no *Networking) ClusterNetwork() (*clusterv1a1.ClusterNetworkingConfig, er
155129
}
156130

157131
pods := []string{}
158-
for _, cn := range no.config.Spec.ClusterNetworks {
132+
for _, cn := range no.config.Spec.ClusterNetwork {
159133
pods = append(pods, cn.CIDR)
160134
}
161135

162136
cn := &clusterv1a1.ClusterNetworkingConfig{
163137
Services: clusterv1a1.NetworkRanges{
164-
CIDRBlocks: []string{no.config.Spec.ServiceNetwork},
138+
CIDRBlocks: no.config.Spec.ServiceNetwork,
165139
},
166140
Pods: clusterv1a1.NetworkRanges{
167141
CIDRBlocks: pods,
@@ -189,7 +163,7 @@ func (no *Networking) Load(f asset.FileFetcher) (bool, error) {
189163
return false, err
190164
}
191165

192-
netConfig := &netopv1.NetworkConfig{}
166+
netConfig := &configv1.Network{}
193167
if err := yaml.Unmarshal(cfgFile.Data, netConfig); err != nil {
194168
return false, errors.Wrapf(err, "failed to unmarshal %s", noCfgFilename)
195169
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
package openshift
2+
3+
import (
4+
"os"
5+
"path/filepath"
6+
7+
"github.com/openshift/installer/pkg/asset"
8+
"github.com/openshift/installer/pkg/asset/templates/content"
9+
)
10+
11+
const (
12+
netCRDfilename = "cluster-network-crd.yaml"
13+
netopCRDfilename = "cluster-networkconfig-crd.yaml"
14+
)
15+
16+
var _ asset.WritableAsset = (*NetworkCRDs)(nil)
17+
18+
// NetworkCRDs is the custom resource definitions for the network operator types:
19+
// - Network.config.openshift.io
20+
// - NetworkConfig.networkoperator.openshift.io
21+
type NetworkCRDs struct {
22+
FileList []*asset.File
23+
}
24+
25+
// Dependencies returns all of the dependencies directly needed by the asset
26+
func (t *NetworkCRDs) Dependencies() []asset.Asset {
27+
return []asset.Asset{}
28+
}
29+
30+
// Name returns the human-friendly name of the asset.
31+
func (t *NetworkCRDs) Name() string {
32+
return "Network CRDs"
33+
}
34+
35+
// Generate generates the actual files by this asset
36+
func (t *NetworkCRDs) Generate(parents asset.Parents) error {
37+
for _, filename := range []string{netCRDfilename, netopCRDfilename} {
38+
data, err := content.GetOpenshiftTemplate(filename)
39+
if err != nil {
40+
return err
41+
}
42+
t.FileList = append(t.FileList, &asset.File{
43+
Filename: filepath.Join(content.TemplateDir, filename),
44+
Data: []byte(data),
45+
})
46+
}
47+
return nil
48+
}
49+
50+
// Files returns the files generated by the asset.
51+
func (t *NetworkCRDs) Files() []*asset.File {
52+
return t.FileList
53+
}
54+
55+
// Load returns the asset from disk.
56+
func (t *NetworkCRDs) Load(f asset.FileFetcher) (bool, error) {
57+
for _, filename := range []string{netCRDfilename, netopCRDfilename} {
58+
file, err := f.FetchByName(filepath.Join(content.TemplateDir, filename))
59+
if err != nil {
60+
if os.IsNotExist(err) {
61+
return false, nil
62+
}
63+
return false, err
64+
}
65+
t.FileList = append(t.FileList, file)
66+
}
67+
68+
return true, nil
69+
}

pkg/asset/templates/templates.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ func (m *Templates) Dependencies() []asset.Asset {
4242
&openshift.KubeadminPasswordSecret{},
4343
&openshift.RoleCloudCredsSecretReader{},
4444
&openshift.InfrastructureCRD{},
45+
&openshift.NetworkCRDs{},
4546
}
4647
}
4748

0 commit comments

Comments
 (0)