forked from openshift/machine-config-operator
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
controller/bootstrap: use files with multiple yaml documents
Users can push manifests during bootstrap that of the form: ```yaml --- ``` Especially for the installer: setting authorizes_keys [1] and setting hyperthreading [2] will push a manifest that includes multiple machineconfig objects for control-plane (master) and compute (worker) roles. Single file with multiple k8s objects separated by `---` is also a supported structure for `oc create|apply` ie. there is a high chance that users trying to push machineconfigs at install time might create such files. This commit allows bootstrap controller to read all k8s objects, even ones described above to find all the `machineconfiguration.openshift.io` Objects. [1]: openshift/installer#1150 [2]: openshift/installer#1392
- Loading branch information
1 parent
c83a2df
commit 7273740
Showing
2 changed files
with
191 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
package bootstrap | ||
|
||
import ( | ||
"reflect" | ||
"strings" | ||
"testing" | ||
|
||
"k8s.io/apimachinery/pkg/util/diff" | ||
) | ||
|
||
func TestParseManifests(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
raw string | ||
want []manifest | ||
}{{ | ||
name: "ingress", | ||
raw: ` | ||
apiVersion: extensions/v1beta1 | ||
kind: Ingress | ||
metadata: | ||
name: test-ingress | ||
namespace: test-namespace | ||
spec: | ||
rules: | ||
- http: | ||
paths: | ||
- path: /testpath | ||
backend: | ||
serviceName: test | ||
servicePort: 80 | ||
`, | ||
want: []manifest{{ | ||
Raw: []byte(`{"apiVersion":"extensions/v1beta1","kind":"Ingress","metadata":{"name":"test-ingress","namespace":"test-namespace"},"spec":{"rules":[{"http":{"paths":[{"backend":{"serviceName":"test","servicePort":80},"path":"/testpath"}]}}]}}`), | ||
}}, | ||
}, { | ||
name: "two-resources", | ||
raw: ` | ||
apiVersion: extensions/v1beta1 | ||
kind: Ingress | ||
metadata: | ||
name: test-ingress | ||
namespace: test-namespace | ||
spec: | ||
rules: | ||
- http: | ||
paths: | ||
- path: /testpath | ||
backend: | ||
serviceName: test | ||
servicePort: 80 | ||
--- | ||
apiVersion: v1 | ||
kind: ConfigMap | ||
metadata: | ||
name: a-config | ||
namespace: default | ||
data: | ||
color: "red" | ||
multi-line: | | ||
hello world | ||
how are you? | ||
`, | ||
want: []manifest{{ | ||
Raw: []byte(`{"apiVersion":"extensions/v1beta1","kind":"Ingress","metadata":{"name":"test-ingress","namespace":"test-namespace"},"spec":{"rules":[{"http":{"paths":[{"backend":{"serviceName":"test","servicePort":80},"path":"/testpath"}]}}]}}`), | ||
}, { | ||
Raw: []byte(`{"apiVersion":"v1","data":{"color":"red","multi-line":"hello world\nhow are you?\n"},"kind":"ConfigMap","metadata":{"name":"a-config","namespace":"default"}}`), | ||
}}, | ||
}, { | ||
name: "two-resources-with-empty", | ||
raw: ` | ||
--- | ||
apiVersion: extensions/v1beta1 | ||
kind: Ingress | ||
metadata: | ||
name: test-ingress | ||
namespace: test-namespace | ||
spec: | ||
rules: | ||
- http: | ||
paths: | ||
- path: /testpath | ||
backend: | ||
serviceName: test | ||
servicePort: 80 | ||
--- | ||
--- | ||
apiVersion: v1 | ||
kind: ConfigMap | ||
metadata: | ||
name: a-config | ||
namespace: default | ||
data: | ||
color: "red" | ||
multi-line: | | ||
hello world | ||
how are you? | ||
--- | ||
`, | ||
want: []manifest{{ | ||
Raw: []byte(`{"apiVersion":"extensions/v1beta1","kind":"Ingress","metadata":{"name":"test-ingress","namespace":"test-namespace"},"spec":{"rules":[{"http":{"paths":[{"backend":{"serviceName":"test","servicePort":80},"path":"/testpath"}]}}]}}`), | ||
}, { | ||
Raw: []byte(`{"apiVersion":"v1","data":{"color":"red","multi-line":"hello world\nhow are you?\n"},"kind":"ConfigMap","metadata":{"name":"a-config","namespace":"default"}}`), | ||
}}, | ||
}} | ||
for _, test := range tests { | ||
t.Run(test.name, func(t *testing.T) { | ||
got, err := parseManifests("dummy-file-name", strings.NewReader(test.raw)) | ||
if err != nil { | ||
t.Fatalf("failed to parse manifest: %v", err) | ||
} | ||
|
||
if !reflect.DeepEqual(got, test.want) { | ||
t.Fatalf("mismatch found %s", diff.ObjectDiff(got, test.want)) | ||
} | ||
}) | ||
} | ||
|
||
} |