Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug 1886751: Gather MachineConfigPools #210

Merged
merged 1 commit into from
Oct 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions docs/gathered-data.md
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,16 @@ Response see https://docs.okd.io/latest/rest_api/policy_apis/poddisruptionbudget
Location in archive: config/pdbs/
See: docs/insights-archive-sample/config/pdbs

## MachineConfigPool

gathers the cluster's MachineConfigPools.

The Kubernetes api https://github.com/openshift/machine-config-operator/blob/master/pkg/apis/machineconfiguration.openshift.io/v1/types.go#L197
Response see https://docs.okd.io/latest/rest_api/machine_apis/machineconfigpool-machineconfiguration-openshift-io-v1.html

Location in archive: config/machineconfigpools/
See: docs/insights-archive-sample/config/machineconfigpools/


## ServiceAccounts

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +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 number Diff line number Diff line change
@@ -0,0 +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}}
29 changes: 29 additions & 0 deletions pkg/gather/clusterconfig/clusterconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ func (i *Gatherer) Gather(ctx context.Context, recorder record.Interface) error
GatherHostSubnet(i),
GatherMachineSet(i),
GatherServiceAccounts(i),
GatherMachineConfigPool(i),
)
}

Expand Down Expand Up @@ -816,6 +817,34 @@ func GatherMachineSet(i *Gatherer) func() ([]record.Record, []error) {
}
}


//GatherMachineConfigPool collects MachineConfigPool information
//
// The Kubernetes api https://github.com/openshift/machine-config-operator/blob/master/pkg/apis/machineconfiguration.openshift.io/v1/types.go#L197
// Response see https://docs.okd.io/latest/rest_api/machine_apis/machineconfigpool-machineconfiguration-openshift-io-v1.html
//
// Location in archive: config/machineconfigpools/
func GatherMachineConfigPool(i *Gatherer) func() ([]record.Record, []error) {
return func() ([]record.Record, []error) {
mcp := schema.GroupVersionResource{Group: "machineconfiguration.openshift.io", Version: "v1", Resource: "machineconfigpools"}
machineCPs, err := i.dynamicClient.Resource(mcp).List(i.ctx, metav1.ListOptions{})
if errors.IsNotFound(err) {
return nil, nil
}
if err != nil {
return nil, []error{err}
}
records := []record.Record{}
for _, i := range machineCPs.Items {
records = append(records, record.Record{
Name: fmt.Sprintf("config/machineconfigpools/%s", i.GetName()),
Item: record.JSONMarshaller{Object: i.Object},
})
}
return records, nil
}
}

func (i *Gatherer) gatherNamespaceEvents(namespace string) ([]record.Record, []error) {
// do not accidentally collect events for non-openshift namespace
if !strings.HasPrefix(namespace, "openshift-") {
Expand Down
37 changes: 37 additions & 0 deletions pkg/gather/clusterconfig/clusterconfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,43 @@ metadata:
}
}

func TestGatherMachineConfigPool(t *testing.T) {
var machineconfigpoolYAML = `
apiVersion: machineconfiguration.openshift.io/v1
kind: MachineConfigPool
metadata:
name: master-t
`
gvr := schema.GroupVersionResource{Group: "machineconfiguration.openshift.io", Version: "v1", Resource: "machineconfigpools"}
client := dynamicfake.NewSimpleDynamicClient(runtime.NewScheme())
decUnstructured := yaml.NewDecodingSerializer(unstructured.UnstructuredJSONScheme)

testMachineConfigPools := &unstructured.Unstructured{}

_, _, err := decUnstructured.Decode([]byte(machineconfigpoolYAML), nil, testMachineConfigPools)
if err != nil {
t.Fatal("unable to decode machineconfigpool ", err)
}
_, err = client.Resource(gvr).Create(context.Background(), testMachineConfigPools, metav1.CreateOptions{})
if err != nil {
t.Fatal("unable to create fake machineconfigpool ", err)
}

gatherer := &Gatherer{dynamicClient: client}
records, errs := GatherMachineConfigPool(gatherer)()
if len(errs) > 0 {
t.Errorf("unexpected errors: %#v", errs)
return
}
if len(records) != 1 {
t.Fatalf("unexpected number or records %d", len(records))
}
if records[0].Name != "config/machineconfigpools/master-t" {
t.Fatalf("unexpected machineconfigpool name %s", records[0].Name)
}
}


func TestGatherServiceAccounts(t *testing.T) {
tests := []struct {
name string
Expand Down