Skip to content

Commit

Permalink
Adds ContainerRuntimeConfig gatherer
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcell Sevcsik committed Jan 28, 2021
1 parent c8cc7d6 commit 1c4fdbe
Show file tree
Hide file tree
Showing 4 changed files with 158 additions and 2 deletions.
13 changes: 12 additions & 1 deletion docs/gathered-data.md
Original file line number Diff line number Diff line change
Expand Up @@ -247,4 +247,15 @@ The Kubernetes api https://github.com/kubernetes/client-go/blob/v11.0.0/kubernet
Response see https://docs.okd.io/latest/rest_api/policy_apis/poddisruptionbudget-policy-v1beta1.html

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

## ContainerRuntimeConfig

collects ContainerRuntimeConfig information

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

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
{
"apiVersion": "machineconfiguration.openshift.io/v1",
"kind": "ContainerRuntimeConfig",
"metadata": {
"creationTimestamp": "2020-10-13T10:24:51Z",
"generation": 1,
"managedFields": [
{
"apiVersion": "machineconfiguration.openshift.io/v1",
"fieldsType": "FieldsV1",
"fieldsV1": {
"f:spec": {
".": {},
"f:containerRuntimeConfig": {
".": {},
"f:logLevel": {},
"f:pidsLimit": {}
},
"f:machineConfigPoolSelector": {
".": {},
"f:matchLabels": {
".": {},
"f:debug-crio": {}
}
}
}
},
"manager": "kubectl-create",
"operation": "Update",
"time": "2020-10-13T10:24:51Z"
},
{
"apiVersion": "machineconfiguration.openshift.io/v1",
"fieldsType": "FieldsV1",
"fieldsV1": {
"f:spec": {
"f:containerRuntimeConfig": {
"f:logSizeMax": {},
"f:overlaySize": {}
}
},
"f:status": {
".": {},
"f:conditions": {},
"f:observedGeneration": {}
}
},
"manager": "machine-config-controller",
"operation": "Update",
"time": "2020-10-13T10:25:12Z"
}
],
"name": "set-log-and-pid",
"resourceVersion": "45056",
"selfLink": "/apis/machineconfiguration.openshift.io/v1/containerruntimeconfigs/set-log-and-pid",
"uid": "949e59e4-8b90-42e1-8467-6369aa1ea932"
},
"spec": {
"containerRuntimeConfig": {
"logLevel": "debug",
"pidsLimit": 2048
},
"machineConfigPoolSelector": {
"matchLabels": {
"debug-crio": "config-log-and-pid"
}
}
},
"status": {
"conditions": [
{
"lastTransitionTime": "2020-10-13T10:25:11Z",
"message": "Error: could not find any MachineConfigPool set for ContainerRuntimeConfig set-log-and-pid",
"status": "False",
"type": "Failure"
}
],
"observedGeneration": 1
}
}
29 changes: 29 additions & 0 deletions pkg/gather/clusterconfig/clusterconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ func (i *Gatherer) Gather(ctx context.Context, recorder record.Interface) error
GatherCRD(i),
GatherHostSubnet(i),
GatherMachineSet(i),
GatherContainerRuntimeConfig(i),
)
}

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

// GatherContainerRuntimeConfig collects ContainerRuntimeConfig information
//
// The Kubernetes api https://github.com/openshift/machine-config-operator/blob/master/pkg/apis/machineconfiguration.openshift.io/v1/types.go#L402
// Response see https://docs.okd.io/latest/rest_api/machine_apis/containerruntimeconfig-machineconfiguration-openshift-io-v1.html
//
// Location in archive: config/containerruntimeconfigs/
func GatherContainerRuntimeConfig(i *Gatherer) func() ([]record.Record, []error) {
return func() ([]record.Record, []error) {
crc := schema.GroupVersionResource{Group: "machineconfiguration.openshift.io", Version: "v1", Resource: "containerruntimeconfigs"}
containerRCs, err := i.dynamicClient.Resource(crc).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 containerRCs.Items {
records = append(records, record.Record{
Name: fmt.Sprintf("config/containerruntimeconfigs/%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
38 changes: 37 additions & 1 deletion pkg/gather/clusterconfig/clusterconfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,7 @@ metadata:
}
}


func TestGatherClusterOperator(t *testing.T) {
testOperator := &configv1.ClusterOperator{
ObjectMeta: metav1.ObjectMeta{
Expand All @@ -648,7 +649,6 @@ func TestGatherClusterOperator(t *testing.T) {
t.Errorf("unexpected errors: %#v", errs)
return
}

item, _ := records[0].Item.Marshal(context.TODO())
var gatheredCO configv1.ClusterOperator
_, _, err = openshiftSerializer.Decode(item, nil, &gatheredCO)
Expand All @@ -661,6 +661,42 @@ func TestGatherClusterOperator(t *testing.T) {

}

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

testContainerRuntimeConfigs := &unstructured.Unstructured{}

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

gatherer := &Gatherer{dynamicClient: client}
records, errs := GatherContainerRuntimeConfig(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/containerruntimeconfigs/test-ContainerRC" {
t.Fatalf("unexpected containerruntimeconfig name %s", records[0].Name)
}
}

func ExampleGatherMostRecentMetrics_Test() {
b, err := ExampleMostRecentMetrics()
if err != nil {
Expand Down

0 comments on commit 1c4fdbe

Please sign in to comment.