Skip to content

Commit 7a2fd23

Browse files
Merge pull request #210 from 0sewa0/MCPs
Bug 1886751: Gather MachineConfigPools
2 parents 3f00deb + 436f4e9 commit 7a2fd23

File tree

5 files changed

+78
-0
lines changed

5 files changed

+78
-0
lines changed

docs/gathered-data.md

+10
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,16 @@ Response see https://docs.okd.io/latest/rest_api/policy_apis/poddisruptionbudget
249249
Location in archive: config/pdbs/
250250
See: docs/insights-archive-sample/config/pdbs
251251

252+
## MachineConfigPool
253+
254+
gathers the cluster's MachineConfigPools.
255+
256+
The Kubernetes api https://github.com/openshift/machine-config-operator/blob/master/pkg/apis/machineconfiguration.openshift.io/v1/types.go#L197
257+
Response see https://docs.okd.io/latest/rest_api/machine_apis/machineconfigpool-machineconfiguration-openshift-io-v1.html
258+
259+
Location in archive: config/machineconfigpools/
260+
See: docs/insights-archive-sample/config/machineconfigpools/
261+
252262

253263
## ServiceAccounts
254264

Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"apiVersion":"machineconfiguration.openshift.io/v1","kind":"MachineConfigPool","metadata":{"creationTimestamp":"2020-10-09T07:37:33Z","generation":2,"labels":{"machineconfiguration.openshift.io/mco-built-in":"","operator.machineconfiguration.openshift.io/required-for-upgrade":"","pools.operator.machineconfiguration.openshift.io/master":""},"managedFields":[{"apiVersion":"machineconfiguration.openshift.io/v1","fieldsType":"FieldsV1","fieldsV1":{"f:metadata":{"f:labels":{".":{},"f:machineconfiguration.openshift.io/mco-built-in":{},"f:operator.machineconfiguration.openshift.io/required-for-upgrade":{},"f:pools.operator.machineconfiguration.openshift.io/master":{}}},"f:spec":{".":{},"f:configuration":{},"f:machineConfigSelector":{".":{},"f:matchLabels":{".":{},"f:machineconfiguration.openshift.io/role":{}}},"f:nodeSelector":{".":{},"f:matchLabels":{".":{},"f:node-role.kubernetes.io/master":{}}},"f:paused":{}}},"manager":"machine-config-operator","operation":"Update","time":"2020-10-09T07:37:33Z"},{"apiVersion":"machineconfiguration.openshift.io/v1","fieldsType":"FieldsV1","fieldsV1":{"f:spec":{"f:configuration":{"f:name":{},"f:source":{}}},"f:status":{".":{},"f:conditions":{},"f:configuration":{".":{},"f:name":{},"f:source":{}},"f:degradedMachineCount":{},"f:machineCount":{},"f:observedGeneration":{},"f:readyMachineCount":{},"f:unavailableMachineCount":{},"f:updatedMachineCount":{}}},"manager":"machine-config-controller","operation":"Update","time":"2020-10-09T07:38:13Z"}],"name":"master","resourceVersion":"6958","selfLink":"/apis/machineconfiguration.openshift.io/v1/machineconfigpools/master","uid":"8b8a9ca6-642b-44ea-bec5-e4d17ff70215"},"spec":{"configuration":{"name":"rendered-master-5caa198d816b9b65c835158c6fbe65d0","source":[{"apiVersion":"machineconfiguration.openshift.io/v1","kind":"MachineConfig","name":"00-master"},{"apiVersion":"machineconfiguration.openshift.io/v1","kind":"MachineConfig","name":"01-master-container-runtime"},{"apiVersion":"machineconfiguration.openshift.io/v1","kind":"MachineConfig","name":"01-master-kubelet"},{"apiVersion":"machineconfiguration.openshift.io/v1","kind":"MachineConfig","name":"99-master-generated-registries"},{"apiVersion":"machineconfiguration.openshift.io/v1","kind":"MachineConfig","name":"99-master-ssh"}]},"machineConfigSelector":{"matchLabels":{"machineconfiguration.openshift.io/role":"master"}},"nodeSelector":{"matchLabels":{"node-role.kubernetes.io/master":""}},"paused":false},"status":{"conditions":[{"lastTransitionTime":"2020-10-09T07:38:03Z","message":"","reason":"","status":"False","type":"RenderDegraded"},{"lastTransitionTime":"2020-10-09T07:38:13Z","message":"All nodes are updated with rendered-master-5caa198d816b9b65c835158c6fbe65d0","reason":"","status":"True","type":"Updated"},{"lastTransitionTime":"2020-10-09T07:38:13Z","message":"","reason":"","status":"False","type":"Updating"},{"lastTransitionTime":"2020-10-09T07:38:13Z","message":"","reason":"","status":"False","type":"NodeDegraded"},{"lastTransitionTime":"2020-10-09T07:38:13Z","message":"","reason":"","status":"False","type":"Degraded"}],"configuration":{"name":"rendered-master-5caa198d816b9b65c835158c6fbe65d0","source":[{"apiVersion":"machineconfiguration.openshift.io/v1","kind":"MachineConfig","name":"00-master"},{"apiVersion":"machineconfiguration.openshift.io/v1","kind":"MachineConfig","name":"01-master-container-runtime"},{"apiVersion":"machineconfiguration.openshift.io/v1","kind":"MachineConfig","name":"01-master-kubelet"},{"apiVersion":"machineconfiguration.openshift.io/v1","kind":"MachineConfig","name":"99-master-generated-registries"},{"apiVersion":"machineconfiguration.openshift.io/v1","kind":"MachineConfig","name":"99-master-ssh"}]},"degradedMachineCount":0,"machineCount":3,"observedGeneration":2,"readyMachineCount":3,"unavailableMachineCount":0,"updatedMachineCount":3}}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"apiVersion":"machineconfiguration.openshift.io/v1","kind":"MachineConfigPool","metadata":{"creationTimestamp":"2020-10-09T07:37:33Z","generation":2,"labels":{"machineconfiguration.openshift.io/mco-built-in":"","pools.operator.machineconfiguration.openshift.io/worker":""},"managedFields":[{"apiVersion":"machineconfiguration.openshift.io/v1","fieldsType":"FieldsV1","fieldsV1":{"f:metadata":{"f:labels":{".":{},"f:machineconfiguration.openshift.io/mco-built-in":{},"f:pools.operator.machineconfiguration.openshift.io/worker":{}}},"f:spec":{".":{},"f:configuration":{},"f:machineConfigSelector":{".":{},"f:matchLabels":{".":{},"f:machineconfiguration.openshift.io/role":{}}},"f:nodeSelector":{".":{},"f:matchLabels":{".":{},"f:node-role.kubernetes.io/worker":{}}},"f:paused":{}}},"manager":"machine-config-operator","operation":"Update","time":"2020-10-09T07:37:33Z"},{"apiVersion":"machineconfiguration.openshift.io/v1","fieldsType":"FieldsV1","fieldsV1":{"f:spec":{"f:configuration":{"f:name":{},"f:source":{}}},"f:status":{".":{},"f:conditions":{},"f:configuration":{".":{},"f:name":{},"f:source":{}},"f:degradedMachineCount":{},"f:machineCount":{},"f:observedGeneration":{},"f:readyMachineCount":{},"f:unavailableMachineCount":{},"f:updatedMachineCount":{}}},"manager":"machine-config-controller","operation":"Update","time":"2020-10-09T07:45:32Z"}],"name":"worker","resourceVersion":"18898","selfLink":"/apis/machineconfiguration.openshift.io/v1/machineconfigpools/worker","uid":"e4c53efe-f489-41a6-98c4-786a640659ea"},"spec":{"configuration":{"name":"rendered-worker-39d3c3334fcddefcffe58854bcbbcd0a","source":[{"apiVersion":"machineconfiguration.openshift.io/v1","kind":"MachineConfig","name":"00-worker"},{"apiVersion":"machineconfiguration.openshift.io/v1","kind":"MachineConfig","name":"01-worker-container-runtime"},{"apiVersion":"machineconfiguration.openshift.io/v1","kind":"MachineConfig","name":"01-worker-kubelet"},{"apiVersion":"machineconfiguration.openshift.io/v1","kind":"MachineConfig","name":"99-worker-generated-registries"},{"apiVersion":"machineconfiguration.openshift.io/v1","kind":"MachineConfig","name":"99-worker-ssh"}]},"machineConfigSelector":{"matchLabels":{"machineconfiguration.openshift.io/role":"worker"}},"nodeSelector":{"matchLabels":{"node-role.kubernetes.io/worker":""}},"paused":false},"status":{"conditions":[{"lastTransitionTime":"2020-10-09T07:38:03Z","message":"","reason":"","status":"False","type":"RenderDegraded"},{"lastTransitionTime":"2020-10-09T07:38:08Z","message":"","reason":"","status":"False","type":"NodeDegraded"},{"lastTransitionTime":"2020-10-09T07:38:08Z","message":"","reason":"","status":"False","type":"Degraded"},{"lastTransitionTime":"2020-10-09T07:45:32Z","message":"All nodes are updated with rendered-worker-39d3c3334fcddefcffe58854bcbbcd0a","reason":"","status":"True","type":"Updated"},{"lastTransitionTime":"2020-10-09T07:45:32Z","message":"","reason":"","status":"False","type":"Updating"}],"configuration":{"name":"rendered-worker-39d3c3334fcddefcffe58854bcbbcd0a","source":[{"apiVersion":"machineconfiguration.openshift.io/v1","kind":"MachineConfig","name":"00-worker"},{"apiVersion":"machineconfiguration.openshift.io/v1","kind":"MachineConfig","name":"01-worker-container-runtime"},{"apiVersion":"machineconfiguration.openshift.io/v1","kind":"MachineConfig","name":"01-worker-kubelet"},{"apiVersion":"machineconfiguration.openshift.io/v1","kind":"MachineConfig","name":"99-worker-generated-registries"},{"apiVersion":"machineconfiguration.openshift.io/v1","kind":"MachineConfig","name":"99-worker-ssh"}]},"degradedMachineCount":0,"machineCount":3,"observedGeneration":2,"readyMachineCount":3,"unavailableMachineCount":0,"updatedMachineCount":3}}

pkg/gather/clusterconfig/clusterconfig.go

+29
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ func (i *Gatherer) Gather(ctx context.Context, recorder record.Interface) error
164164
GatherHostSubnet(i),
165165
GatherMachineSet(i),
166166
GatherServiceAccounts(i),
167+
GatherMachineConfigPool(i),
167168
)
168169
}
169170

@@ -839,6 +840,34 @@ func GatherMachineSet(i *Gatherer) func() ([]record.Record, []error) {
839840
}
840841
}
841842

843+
844+
//GatherMachineConfigPool collects MachineConfigPool information
845+
//
846+
// The Kubernetes api https://github.com/openshift/machine-config-operator/blob/master/pkg/apis/machineconfiguration.openshift.io/v1/types.go#L197
847+
// Response see https://docs.okd.io/latest/rest_api/machine_apis/machineconfigpool-machineconfiguration-openshift-io-v1.html
848+
//
849+
// Location in archive: config/machineconfigpools/
850+
func GatherMachineConfigPool(i *Gatherer) func() ([]record.Record, []error) {
851+
return func() ([]record.Record, []error) {
852+
mcp := schema.GroupVersionResource{Group: "machineconfiguration.openshift.io", Version: "v1", Resource: "machineconfigpools"}
853+
machineCPs, err := i.dynamicClient.Resource(mcp).List(i.ctx, metav1.ListOptions{})
854+
if errors.IsNotFound(err) {
855+
return nil, nil
856+
}
857+
if err != nil {
858+
return nil, []error{err}
859+
}
860+
records := []record.Record{}
861+
for _, i := range machineCPs.Items {
862+
records = append(records, record.Record{
863+
Name: fmt.Sprintf("config/machineconfigpools/%s", i.GetName()),
864+
Item: record.JSONMarshaller{Object: i.Object},
865+
})
866+
}
867+
return records, nil
868+
}
869+
}
870+
842871
func (i *Gatherer) gatherNamespaceEvents(namespace string) ([]record.Record, []error) {
843872
// do not accidentally collect events for non-openshift namespace
844873
if !strings.HasPrefix(namespace, "openshift-") {

pkg/gather/clusterconfig/clusterconfig_test.go

+37
Original file line numberDiff line numberDiff line change
@@ -629,6 +629,43 @@ metadata:
629629
}
630630
}
631631

632+
func TestGatherMachineConfigPool(t *testing.T) {
633+
var machineconfigpoolYAML = `
634+
apiVersion: machineconfiguration.openshift.io/v1
635+
kind: MachineConfigPool
636+
metadata:
637+
name: master-t
638+
`
639+
gvr := schema.GroupVersionResource{Group: "machineconfiguration.openshift.io", Version: "v1", Resource: "machineconfigpools"}
640+
client := dynamicfake.NewSimpleDynamicClient(runtime.NewScheme())
641+
decUnstructured := yaml.NewDecodingSerializer(unstructured.UnstructuredJSONScheme)
642+
643+
testMachineConfigPools := &unstructured.Unstructured{}
644+
645+
_, _, err := decUnstructured.Decode([]byte(machineconfigpoolYAML), nil, testMachineConfigPools)
646+
if err != nil {
647+
t.Fatal("unable to decode machineconfigpool ", err)
648+
}
649+
_, err = client.Resource(gvr).Create(context.Background(), testMachineConfigPools, metav1.CreateOptions{})
650+
if err != nil {
651+
t.Fatal("unable to create fake machineconfigpool ", err)
652+
}
653+
654+
gatherer := &Gatherer{dynamicClient: client}
655+
records, errs := GatherMachineConfigPool(gatherer)()
656+
if len(errs) > 0 {
657+
t.Errorf("unexpected errors: %#v", errs)
658+
return
659+
}
660+
if len(records) != 1 {
661+
t.Fatalf("unexpected number or records %d", len(records))
662+
}
663+
if records[0].Name != "config/machineconfigpools/master-t" {
664+
t.Fatalf("unexpected machineconfigpool name %s", records[0].Name)
665+
}
666+
}
667+
668+
632669
func TestGatherServiceAccounts(t *testing.T) {
633670
tests := []struct {
634671
name string

0 commit comments

Comments
 (0)