Skip to content

Commit 4349644

Browse files
committed
Bug 1881816: Gather MachineSet info
1 parent 7ceac48 commit 4349644

File tree

10 files changed

+1031
-23
lines changed

10 files changed

+1031
-23
lines changed

docs/gathered-data.md

+33-21
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
This document is auto-generated by `make gen-doc`
22

3+
## CRD
4+
5+
collects the specified Custom Resource Definitions.
6+
7+
The following CRDs are gathered:
8+
- volumesnapshots.snapshot.storage.k8s.io (10745 bytes)
9+
- volumesnapshotcontents.snapshot.storage.k8s.io (13149 bytes)
10+
11+
The CRD sizes above are in the raw (uncompressed) state.
12+
13+
Location in archive: config/crd/
14+
15+
316
## CertificateSigningRequests
417

518
collects anonymized CertificateSigningRequests.
@@ -115,13 +128,6 @@ See: docs/insights-archive-sample/config/clusteroperator
115128
Location of pods in archive: config/pod/
116129

117130

118-
Output raw size: 245
119-
120-
### Examples
121-
122-
#### ClusterOperators
123-
[{"Name":"config/clusteroperator/","Captured":"0001-01-01T00:00:00Z","Fingerprint":"","Item":{"metadata":{"creationTimestamp":null},"spec":{},"status":{"conditions":[{"type":"Degraded","status":"","lastTransitionTime":null}],"extension":null}}}]
124-
125131
## ClusterProxy
126132

127133
fetches the cluster Proxy - the Proxy with name cluster.
@@ -167,6 +173,26 @@ Specifically, the age of pods, the set of running images and the container names
167173
Location in archive: config/running_containers.json
168174

169175

176+
## HostSubnet
177+
178+
collects HostSubnet information
179+
180+
The Kubernetes api https://github.com/openshift/client-go/blob/master/network/clientset/versioned/typed/network/v1/hostsubnet.go
181+
Response see https://docs.openshift.com/container-platform/4.3/rest_api/index.html#hostsubnet-v1-network-openshift-io
182+
183+
Location in archive: config/hostsubnet/
184+
185+
186+
## MachineSet
187+
188+
collects MachineSet information
189+
190+
The Kubernetes api https://github.com/openshift/machine-api-operator/blob/master/pkg/generated/clientset/versioned/typed/machine/v1beta1/machineset.go
191+
Response see https://docs.openshift.com/container-platform/4.3/rest_api/index.html#machineset-v1beta1-machine-openshift-io
192+
193+
Location in archive: machinesets/
194+
195+
170196
## MostRecentMetrics
171197

172198
gathers cluster Federated Monitoring metrics.
@@ -182,13 +208,6 @@ Location in archive: config/metrics/
182208
See: docs/insights-archive-sample/config/metrics
183209

184210

185-
Output raw size: 148
186-
187-
### Examples
188-
189-
#### MostRecentMetrics
190-
[{"Name":"config/metrics","Captured":"0001-01-01T00:00:00Z","Fingerprint":"","Item":"SGVsbG8sIGNsaWVudAojIEFMRVJUUyAyLzEwMDAKSGVsbG8sIGNsaWVudAo="}]
191-
192211
## Nodes
193212

194213
collects all Nodes.
@@ -199,10 +218,3 @@ Response see https://docs.openshift.com/container-platform/4.3/rest_api/index.ht
199218
Location in archive: config/node/
200219

201220

202-
Output raw size: 491
203-
204-
### Examples
205-
206-
#### Nodes
207-
[{"Name":"config/node/","Captured":"0001-01-01T00:00:00Z","Fingerprint":"","Item":{"metadata":{"creationTimestamp":null},"spec":{},"status":{"conditions":[{"type":"Ready","status":"False","lastHeartbeatTime":null,"lastTransitionTime":null}],"daemonEndpoints":{"kubeletEndpoint":{"Port":0}},"nodeInfo":{"machineID":"","systemUUID":"","bootID":"","kernelVersion":"","osImage":"","containerRuntimeVersion":"","kubeletVersion":"","kubeProxyVersion":"","operatingSystem":"","architecture":""}}}}]
208-

pkg/controller/operator.go

+7-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
apixv1beta1client "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset/typed/apiextensions/v1beta1"
1212
"k8s.io/apimachinery/pkg/runtime"
1313
"k8s.io/apimachinery/pkg/runtime/schema"
14+
"k8s.io/client-go/dynamic"
1415
"k8s.io/client-go/kubernetes"
1516
"k8s.io/client-go/kubernetes/scheme"
1617
"k8s.io/client-go/pkg/version"
@@ -126,6 +127,11 @@ func (s *Support) Run(ctx context.Context, controller *controllercmd.ControllerC
126127
return err
127128
}
128129

130+
dynamicClient, err := dynamic.NewForConfig(gatherKubeConfig)
131+
if err != nil {
132+
return err
133+
}
134+
129135
// ensure the insight snapshot directory exists
130136
if _, err := os.Stat(s.StoragePath); err != nil && os.IsNotExist(err) {
131137
if err := os.MkdirAll(s.StoragePath, 0777); err != nil {
@@ -148,7 +154,7 @@ func (s *Support) Run(ctx context.Context, controller *controllercmd.ControllerC
148154

149155
// the gatherers periodically check the state of the cluster and report any
150156
// config to the recorder
151-
configPeriodic := clusterconfig.New(gatherConfigClient, gatherKubeClient.CoreV1(), gatherKubeClient.CertificatesV1beta1(), metricsClient, registryClient.ImageregistryV1(), crdClient, gatherNetworkClient)
157+
configPeriodic := clusterconfig.New(gatherConfigClient, gatherKubeClient.CoreV1(), gatherKubeClient.CertificatesV1beta1(), metricsClient, registryClient.ImageregistryV1(), crdClient, gatherNetworkClient, dynamicClient)
152158
periodic := periodic.New(configObserver, recorder, map[string]gather.Interface{
153159
"config": configPeriodic,
154160
})

pkg/gather/clusterconfig/clusterconfig.go

+33-1
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,12 @@ import (
2020
"k8s.io/apimachinery/pkg/api/errors"
2121
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2222
"k8s.io/apimachinery/pkg/runtime"
23+
"k8s.io/apimachinery/pkg/runtime/schema"
2324
"k8s.io/apimachinery/pkg/runtime/serializer"
2425
"k8s.io/apimachinery/pkg/util/json"
2526
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
2627
"k8s.io/apimachinery/pkg/util/sets"
28+
"k8s.io/client-go/dynamic"
2729
kubescheme "k8s.io/client-go/kubernetes/scheme"
2830
certificatesv1beta1 "k8s.io/client-go/kubernetes/typed/certificates/v1beta1"
2931
corev1client "k8s.io/client-go/kubernetes/typed/core/v1"
@@ -93,6 +95,7 @@ type Gatherer struct {
9395
client configv1client.ConfigV1Interface
9496
coreClient corev1client.CoreV1Interface
9597
networkClient networkv1client.NetworkV1Interface
98+
dynamicClient dynamic.Interface
9699
metricsClient rest.Interface
97100
certClient certificatesv1beta1.CertificatesV1beta1Interface
98101
registryClient imageregistryv1.ImageregistryV1Interface
@@ -103,7 +106,7 @@ type Gatherer struct {
103106

104107
// New creates new Gatherer
105108
func New(client configv1client.ConfigV1Interface, coreClient corev1client.CoreV1Interface, certClient certificatesv1beta1.CertificatesV1beta1Interface, metricsClient rest.Interface,
106-
registryClient imageregistryv1.ImageregistryV1Interface, crdClient apixv1beta1client.ApiextensionsV1beta1Interface, networkClient networkv1client.NetworkV1Interface) *Gatherer {
109+
registryClient imageregistryv1.ImageregistryV1Interface, crdClient apixv1beta1client.ApiextensionsV1beta1Interface, networkClient networkv1client.NetworkV1Interface, dynamicClient dynamic.Interface) *Gatherer {
107110
return &Gatherer{
108111
client: client,
109112
coreClient: coreClient,
@@ -112,6 +115,7 @@ func New(client configv1client.ConfigV1Interface, coreClient corev1client.CoreV1
112115
registryClient: registryClient,
113116
crdClient: crdClient,
114117
networkClient: networkClient,
118+
dynamicClient: dynamicClient,
115119
}
116120
}
117121

@@ -139,6 +143,7 @@ func (i *Gatherer) Gather(ctx context.Context, recorder record.Interface) error
139143
GatherCertificateSigningRequests(i),
140144
GatherCRD(i),
141145
GatherHostSubnet(i),
146+
GatherMachineSet(i),
142147
)
143148
}
144149

@@ -732,6 +737,33 @@ func GatherCRD(i *Gatherer) func() ([]record.Record, []error) {
732737
}
733738
}
734739

740+
//GatherMachineSet collects MachineSet information
741+
//
742+
// The Kubernetes api https://github.com/openshift/machine-api-operator/blob/master/pkg/generated/clientset/versioned/typed/machine/v1beta1/machineset.go
743+
// Response see https://docs.openshift.com/container-platform/4.3/rest_api/index.html#machineset-v1beta1-machine-openshift-io
744+
//
745+
// Location in archive: machinesets/
746+
func GatherMachineSet(i *Gatherer) func() ([]record.Record, []error) {
747+
return func() ([]record.Record, []error) {
748+
gvr := schema.GroupVersionResource{Group: "machine.openshift.io", Version: "v1beta1", Resource: "machinesets"}
749+
machineSets, err := i.dynamicClient.Resource(gvr).List(metav1.ListOptions{})
750+
if errors.IsNotFound(err) {
751+
return nil, nil
752+
}
753+
if err != nil {
754+
return nil, []error{err}
755+
}
756+
records := []record.Record{}
757+
for _, i := range machineSets.Items {
758+
records = append(records, record.Record{
759+
Name: fmt.Sprintf("machinesets/%s", i.GetName()),
760+
Item: record.JSONMarshaller{Object: i},
761+
})
762+
}
763+
return records, nil
764+
}
765+
}
766+
735767
func (i *Gatherer) gatherNamespaceEvents(namespace string) ([]record.Record, []error) {
736768
// do not accidentally collect events for non-openshift namespace
737769
if !strings.HasPrefix(namespace, "openshift-") {

pkg/gather/clusterconfig/clusterconfig_test.go

+40
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@ import (
1515
"k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1"
1616
apixv1beta1clientfake "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset/fake"
1717
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
18+
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
1819
"k8s.io/apimachinery/pkg/runtime"
20+
"k8s.io/apimachinery/pkg/runtime/schema"
21+
"k8s.io/apimachinery/pkg/runtime/serializer/yaml"
22+
dynamicfake "k8s.io/client-go/dynamic/fake"
1923
kubefake "k8s.io/client-go/kubernetes/fake"
2024
"k8s.io/klog"
2125

@@ -537,6 +541,42 @@ func TestGatherHostSubnet(t *testing.T) {
537541
}
538542
}
539543

544+
func TestGatherMachineSet(t *testing.T) {
545+
var machineSetYAML = `
546+
apiVersion: machine.openshift.io/v1beta1
547+
kind: MachineSet
548+
metadata:
549+
name: test-worker
550+
`
551+
gvr := schema.GroupVersionResource{Group: "machine.openshift.io", Version: "v1beta1", Resource: "machinesets"}
552+
client := dynamicfake.NewSimpleDynamicClient(runtime.NewScheme())
553+
decUnstructured := yaml.NewDecodingSerializer(unstructured.UnstructuredJSONScheme)
554+
555+
testMachineSet := &unstructured.Unstructured{}
556+
557+
_, _, err := decUnstructured.Decode([]byte(machineSetYAML), nil, testMachineSet)
558+
if err != nil {
559+
t.Fatal("unable to decode machineset ", err)
560+
}
561+
_, err = client.Resource(gvr).Create(testMachineSet, metav1.CreateOptions{})
562+
if err != nil {
563+
t.Fatal("unable to create fake machineset ", err)
564+
}
565+
566+
gatherer := &Gatherer{dynamicClient: client}
567+
records, errs := GatherMachineSet(gatherer)()
568+
if len(errs) > 0 {
569+
t.Errorf("unexpected errors: %#v", errs)
570+
return
571+
}
572+
if len(records) != 1 {
573+
t.Fatalf("unexpected number or records %d", len(records))
574+
}
575+
if records[0].Name != "machinesets/test-worker" {
576+
t.Fatalf("unexpected machineset name %s", records[0].Name)
577+
}
578+
}
579+
540580
func ExampleGatherMostRecentMetrics_Test() {
541581
b, err := ExampleMostRecentMetrics()
542582
if err != nil {

vendor/k8s.io/apimachinery/pkg/runtime/serializer/yaml/yaml.go

+46
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)