Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove old config parsing and switch to new client
- Loading branch information
Showing
4 changed files
with
29 additions
and
477 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,74 +1,4 @@ | ||
package operatorclient | ||
|
||
import ( | ||
"context" | ||
|
||
operatorv1 "github.com/openshift/api/operator/v1" | ||
operatorconfigclientv1beta1 "github.com/openshift/cluster-kube-descheduler-operator/pkg/generated/clientset/versioned/typed/descheduler/v1beta1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
v1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/client-go/tools/cache" | ||
) | ||
|
||
const OperatorNamespace = "openshift-kube-descheduler-operator" | ||
const OperatorConfigName = "cluster" | ||
|
||
type DeschedulerClient struct { | ||
Ctx context.Context | ||
SharedInformer cache.SharedIndexInformer | ||
OperatorClient operatorconfigclientv1beta1.KubedeschedulersV1beta1Interface | ||
} | ||
|
||
func (c *DeschedulerClient) Informer() cache.SharedIndexInformer { | ||
return c.SharedInformer | ||
} | ||
|
||
func (c *DeschedulerClient) GetOperatorState() (spec *operatorv1.OperatorSpec, status *operatorv1.OperatorStatus, resourceVersion string, err error) { | ||
instance, err := c.OperatorClient.KubeDeschedulers(OperatorNamespace).Get(c.Ctx, OperatorConfigName, metav1.GetOptions{}) | ||
if err != nil { | ||
return nil, nil, "", err | ||
} | ||
return &instance.Spec.OperatorSpec, &instance.Status.OperatorStatus, instance.ResourceVersion, nil | ||
} | ||
|
||
func (c *DeschedulerClient) UpdateOperatorSpec(resourceVersion string, spec *operatorv1.OperatorSpec) (out *operatorv1.OperatorSpec, newResourceVersion string, err error) { | ||
original, err := c.OperatorClient.KubeDeschedulers(OperatorNamespace).Get(c.Ctx, OperatorConfigName, metav1.GetOptions{}) | ||
if err != nil { | ||
return nil, "", err | ||
} | ||
copy := original.DeepCopy() | ||
copy.ResourceVersion = resourceVersion | ||
copy.Spec.OperatorSpec = *spec | ||
|
||
ret, err := c.OperatorClient.KubeDeschedulers(OperatorNamespace).Update(c.Ctx, copy, v1.UpdateOptions{}) | ||
if err != nil { | ||
return nil, "", err | ||
} | ||
|
||
return &ret.Spec.OperatorSpec, ret.ResourceVersion, nil | ||
} | ||
|
||
func (c *DeschedulerClient) UpdateOperatorStatus(resourceVersion string, status *operatorv1.OperatorStatus) (out *operatorv1.OperatorStatus, err error) { | ||
original, err := c.OperatorClient.KubeDeschedulers(OperatorNamespace).Get(c.Ctx, OperatorConfigName, metav1.GetOptions{}) | ||
if err != nil { | ||
return nil, err | ||
} | ||
copy := original.DeepCopy() | ||
copy.ResourceVersion = resourceVersion | ||
copy.Status.OperatorStatus = *status | ||
|
||
ret, err := c.OperatorClient.KubeDeschedulers(OperatorNamespace).UpdateStatus(c.Ctx, copy, v1.UpdateOptions{}) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &ret.Status.OperatorStatus, nil | ||
} | ||
|
||
func (c *DeschedulerClient) GetObjectMeta() (meta *metav1.ObjectMeta, err error) { | ||
instance, err := c.OperatorClient.KubeDeschedulers(OperatorNamespace).Get(c.Ctx, OperatorConfigName, metav1.GetOptions{}) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return &instance.ObjectMeta, nil | ||
} |
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
Oops, something went wrong.