Skip to content

Commit

Permalink
ztp: Suppress NMStateConfig when nodeNetwork empty
Browse files Browse the repository at this point in the history
If the user does not supply any networking data in the nodeNetwork field
for a given node we should not generate the NMStateConfig CR. The
resultant NMStateConfig CR would be empty (no config/interfaces) and
causes the install to not complete (crash noted in infraenv). This patch
detects the empty nodeNetwork configuration in the user supplied
SiteConfig and suppresses the generation of NMStateConfig for that node.

Signed-off-by: Ian Miller <[email protected]>
  • Loading branch information
imiller0 authored and pixelsoccupied committed Feb 23, 2022
1 parent 7370b67 commit b1379e6
Show file tree
Hide file tree
Showing 3 changed files with 124 additions and 1 deletion.
8 changes: 8 additions & 0 deletions ztp/siteconfig-generator/siteConfig/siteConfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,14 @@ func (node *Nodes) CrTemplateSearch(kind string, cluster *Clusters, site *Spec)
return cluster.CrTemplateSearch(kind, site)
}

// Return true if the NodeNetwork content is empty or not defined
func (node *Nodes) nodeNetworkIsEmpty() bool {
if len(node.NodeNetwork.Config) == 0 && len(node.NodeNetwork.Interfaces) == 0 {
return true
}
return false
}

// MachineNetwork
type MachineNetwork struct {
Cidr string `yaml:"cidr"`
Expand Down
8 changes: 7 additions & 1 deletion ztp/siteconfig-generator/siteConfig/siteConfigBuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,13 @@ func (scbuilder *SiteConfigBuilder) getClusterCRs(clusterId int, siteConfigTemp
return clusterCRs, err
}

clusterCRs = append(clusterCRs, instantiatedCR)
// BZ 2028510 -- Empty NMStateConfig causes issues and
// should simply be left out.
if kind == "NMStateConfig" && node.nodeNetworkIsEmpty() {
// noop, leave the empty NMStateConfig CR out of the generated set
} else {
clusterCRs = append(clusterCRs, instantiatedCR)
}
}
} else {
// cluster-level CR
Expand Down
109 changes: 109 additions & 0 deletions ztp/siteconfig-generator/siteConfig/siteConfigBuilder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,17 @@ func Test_grtManifestFromTemplate(t *testing.T) {
}
}

// Helper function to find the generated CR of the given kind. Returns nil,error when not found
func getKind(builtCRs []interface{}, kind string) (map[string]interface{}, error) {
for _, cr := range builtCRs {
mapSourceCR := cr.(map[string]interface{})
if mapSourceCR["kind"] == kind {
return mapSourceCR, nil
}
}
return nil, errors.New("Error: Did not find " + kind + " in result")
}

func Test_siteConfigBuildValidation(t *testing.T) {

sc := SiteConfig{}
Expand Down Expand Up @@ -673,3 +684,101 @@ func Test_translateTemplateKey(t *testing.T) {
}
}
}

func Test_nmstateConfig(t *testing.T) {
network := `
apiVersion: ran.openshift.io/v1
kind: SiteConfig
metadata:
name: "test-site"
namespace: "test-site"
spec:
baseDomain: "example.com"
clusterImageSetNameRef: "openshift-v4.8.0"
sshPublicKey:
clusters:
- clusterName: "cluster1"
clusterLabels:
group-du-sno: ""
common: true
sites : "test-site"
nodes:
- hostName: "node1"
nodeNetwork:
interfaces:
- name: "eno1"
macAddress: E4:43:4B:F6:12:E0
config:
interfaces:
- name: eno1
type: ethernet
state: up
`
sc := SiteConfig{}
err := yaml.Unmarshal([]byte(network), &sc)
assert.Equal(t, err, nil)

scBuilder, _ := NewSiteConfigBuilder()
scBuilder.SetLocalExtraManifestPath("../../source-crs/extra-manifest")
// Check good case, network creates NMStateConfig
result, err := scBuilder.Build(sc)
nmState, err := getKind(result["test-site/cluster1"], "NMStateConfig")
assert.NotNil(t, nmState, nil)

noNetwork := `
apiVersion: ran.openshift.io/v1
kind: SiteConfig
metadata:
name: "test-site"
namespace: "test-site"
spec:
baseDomain: "example.com"
clusterImageSetNameRef: "openshift-v4.8.0"
sshPublicKey:
clusters:
- clusterName: "cluster1"
clusterLabels:
group-du-sno: ""
common: true
sites : "test-site"
nodes:
- hostName: "node1"
`

// Set empty case, no network means no NMStateConfig
err = yaml.Unmarshal([]byte(noNetwork), &sc)
assert.Equal(t, err, nil)
result, err = scBuilder.Build(sc)
nmState, err = getKind(result["test-site/cluster1"], "NMStateConfig")
assert.Nil(t, nmState, nil)

emptyNetwork := `
apiVersion: ran.openshift.io/v1
kind: SiteConfig
metadata:
name: "test-site"
namespace: "test-site"
spec:
baseDomain: "example.com"
clusterImageSetNameRef: "openshift-v4.8.0"
sshPublicKey:
clusters:
- clusterName: "cluster1"
clusterLabels:
group-du-sno: ""
common: true
sites : "test-site"
nodes:
- hostName: "node1"
nodeNetwork:
interfaces: []
config: {}
`

// With empty config and interfaces
err = yaml.Unmarshal([]byte(emptyNetwork), &sc)
assert.Equal(t, err, nil)
result, err = scBuilder.Build(sc)
nmState, err = getKind(result["test-site/cluster1"], "NMStateConfig")
assert.Nil(t, nmState, nil)
}

0 comments on commit b1379e6

Please sign in to comment.