Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add short names for alert objects #228

Merged
merged 1 commit into from
Oct 10, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ spec:
names:
kind: PodAlert
plural: podalerts
shortNames: ["poa"]
scope: Namespaced
version: v1alpha1
---
Expand All @@ -23,6 +24,7 @@ spec:
names:
kind: NodeAlert
plural: nodealerts
shortNames: ["noa"]
scope: Namespaced
version: v1alpha1
---
Expand All @@ -37,5 +39,6 @@ spec:
names:
kind: ClusterAlert
plural: clusteralerts
shortNames: ["ca"]
scope: Namespaced
version: v1alpha1
13 changes: 7 additions & 6 deletions pkg/operator/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,19 +62,19 @@ func New(kubeClient clientset.Interface, apiExtKubeClient apiextensionsclient.In
func (op *Operator) Setup() error {
log.Infoln("Ensuring CustomResourceDefinition")

if err := op.ensureCustomResourceDefinition(aci.ResourceKindClusterAlert, aci.ResourceTypeClusterAlert); err != nil {
if err := op.ensureCustomResourceDefinition(aci.ResourceKindClusterAlert, aci.ResourceTypeClusterAlert, "ca"); err != nil {
return err
}
if err := op.ensureCustomResourceDefinition(aci.ResourceKindNodeAlert, aci.ResourceTypeNodeAlert); err != nil {
if err := op.ensureCustomResourceDefinition(aci.ResourceKindNodeAlert, aci.ResourceTypeNodeAlert, "noa"); err != nil {
return err
}
if err := op.ensureCustomResourceDefinition(aci.ResourceKindPodAlert, aci.ResourceTypePodAlert); err != nil {
if err := op.ensureCustomResourceDefinition(aci.ResourceKindPodAlert, aci.ResourceTypePodAlert, "poa"); err != nil {
return err
}
return nil
}

func (op *Operator) ensureCustomResourceDefinition(resourceKind, resourceType string) error {
func (op *Operator) ensureCustomResourceDefinition(resourceKind, resourceType, shortName string) error {
name := resourceType + "." + api.SchemeGroupVersion.Group
_, err := op.ApiExtKubeClient.ApiextensionsV1beta1().CustomResourceDefinitions().Get(name, metav1.GetOptions{})
if !kerr.IsNotFound(err) {
Expand All @@ -93,8 +93,9 @@ func (op *Operator) ensureCustomResourceDefinition(resourceKind, resourceType st
Version: api.SchemeGroupVersion.Version,
Scope: extensionsobj.NamespaceScoped,
Names: extensionsobj.CustomResourceDefinitionNames{
Plural: resourceType,
Kind: resourceKind,
Plural: resourceType,
Kind: resourceKind,
ShortNames: []string{shortName},
},
},
}
Expand Down