-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This adds the machinehealthcheck gathering with dynamic client. Documentation and testing
- Loading branch information
Ricardo Lüders
committed
May 17, 2021
1 parent
c06cbce
commit e615ba3
Showing
5 changed files
with
282 additions
and
25 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
73 changes: 73 additions & 0 deletions
73
...ple/config/machinehealthchecks/openshift-machine-api/machine-api-termination-handler.json
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,73 @@ | ||
{ | ||
"apiVersion": "machine.openshift.io/v1beta1", | ||
"kind": "MachineHealthCheck", | ||
"metadata": { | ||
"annotations": { | ||
"exclude.release.openshift.io/internal-openshift-hosted": "true", | ||
"include.release.openshift.io/self-managed-high-availability": "true" | ||
}, | ||
"creationTimestamp": "2021-05-06T14:22:08Z", | ||
"generation": 1, | ||
"labels": { | ||
"api": "clsuterapi", | ||
"k8s-app": "termination-handler" | ||
}, | ||
"managedFields": [ | ||
{ | ||
"apiVersion": "machine.openshift.io/v1beta1", | ||
"fieldsType": "FieldsV1", | ||
"fieldsV1": { | ||
"f:metadata": { | ||
"f:annotations": { | ||
".": {}, | ||
"f:exclude.release.openshift.io/internal-openshift-hosted": {}, | ||
"f:include.release.openshift.io/self-managed-high-availability": {} | ||
}, | ||
"f:labels": { | ||
".": {}, | ||
"f:api": {}, | ||
"f:k8s-app": {} | ||
} | ||
}, | ||
"f:spec": { | ||
".": {}, | ||
"f:maxUnhealthy": {}, | ||
"f:nodeStartupTimeout": {}, | ||
"f:selector": { | ||
".": {}, | ||
"f:matchLabels": { | ||
".": {}, | ||
"f:machine.openshift.io/interruptible-instance": {} | ||
} | ||
}, | ||
"f:unhealthyConditions": {} | ||
} | ||
}, | ||
"manager": "cluster-version-operator", | ||
"operation": "Update", | ||
"time": "2021-05-06T14:22:08Z" | ||
} | ||
], | ||
"name": "machine-api-termination-handler", | ||
"namespace": "openshift-machine-api", | ||
"resourceVersion": "7446", | ||
"selfLink": "/apis/machine.openshift.io/v1beta1/namespaces/openshift-machine-api/machinehealthchecks/machine-api-termination-handler", | ||
"uid": "7892d287-be94-4ae7-a65b-29dd78057e32" | ||
}, | ||
"spec": { | ||
"maxUnhealthy": "100%", | ||
"nodeStartupTimeout": "10m", | ||
"selector": { | ||
"matchLabels": { | ||
"machine.openshift.io/interruptible-instance": "" | ||
} | ||
}, | ||
"unhealthyConditions": [ | ||
{ | ||
"status": "True", | ||
"timeout": "0s", | ||
"type": "Terminating" | ||
} | ||
] | ||
} | ||
} |
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,60 @@ | ||
package clusterconfig | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/openshift/insights-operator/pkg/record" | ||
"k8s.io/apimachinery/pkg/api/errors" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/apimachinery/pkg/runtime/schema" | ||
"k8s.io/client-go/dynamic" | ||
) | ||
|
||
// GatherMachineHealthCheck collects MachineHealthCheck information | ||
// | ||
// The Kubernetes api: | ||
// https://github.com/openshift/machine-api-operator/blob/master/pkg/generated/clientset/versioned/typed/machine/v1beta1/machinehealthcheck.go | ||
// Response see: | ||
// https://docs.openshift.com/container-platform/4.3/rest_api/index.html#machinehealthcheck-v1beta1-machine-openshift-io | ||
// | ||
// * Location in archive: config/machinehealthchecks | ||
// * Id in config: machine_healthchecks | ||
// * Since versions: | ||
// * 4.4.29+ | ||
// * 4.5.15+ | ||
// * 4.6+ | ||
func (g *Gatherer) GatherMachineHealthCheck(ctx context.Context) ([]record.Record, []error) { | ||
dynamicClient, err := dynamic.NewForConfig(g.gatherKubeConfig) | ||
if err != nil { | ||
return nil, []error{err} | ||
} | ||
|
||
return gatherMachineHealthCheck(ctx, dynamicClient) | ||
} | ||
|
||
func gatherMachineHealthCheck(ctx context.Context, dynamicClient dynamic.Interface) ([]record.Record, []error) { | ||
gvr := schema.GroupVersionResource{Group: "machine.openshift.io", Version: "v1beta1", Resource: "machinehealthchecks"} | ||
machineHealthcheck, err := dynamicClient.Resource(gvr).List(ctx, metav1.ListOptions{}) | ||
if errors.IsNotFound(err) { | ||
return nil, nil | ||
} | ||
if err != nil { | ||
return nil, []error{err} | ||
} | ||
|
||
var records []record.Record | ||
for _, i := range machineHealthcheck.Items { | ||
recordName := fmt.Sprintf("config/machinehealthchecks/%s", i.GetName()) | ||
if i.GetNamespace() != "" { | ||
recordName = fmt.Sprintf("config/machinehealthchecks/%s/%s", i.GetNamespace(), i.GetName()) | ||
} | ||
records = append(records, record.Record{ | ||
Name: recordName, | ||
Item: record.JSONMarshaller{Object: i.Object}, | ||
}) | ||
|
||
} | ||
|
||
return records, nil | ||
} |
Oops, something went wrong.