Skip to content

Commit 9284746

Browse files
committed
WIP Gather MachineSet info
1 parent 4d8fa44 commit 9284746

File tree

6 files changed

+540
-2
lines changed

6 files changed

+540
-2
lines changed

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-") {

vendor/k8s.io/client-go/dynamic/interface.go

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

vendor/k8s.io/client-go/dynamic/scheme.go

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

0 commit comments

Comments
 (0)