-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add base of alert and refacto kubeclient (#24)
- Loading branch information
Showing
17 changed files
with
879 additions
and
181 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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package v1alpha1 | ||
|
||
type ( | ||
AlertCoreSpec struct{} | ||
|
||
AlertCoreStatus struct { | ||
Synced bool `json:"synced"` | ||
} | ||
) |
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,50 @@ | ||
package v1alpha1 | ||
|
||
import ( | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
type ( | ||
// AlertDiscordSpec defines the desired state of AlertDiscord | ||
AlertDiscordSpec struct { | ||
// +kubebuilder:validation:Required | ||
// +kubebuilder:validation:MinItems=1 | ||
// +kubebuilder:validation:example:="123456789012345678" | ||
ChannelIDs []string `json:"channelIDs"` | ||
|
||
// +kubebuilder:validation:Optional | ||
CredentialBotToken *ValueOrValueFrom `json:"credentialBotToken,omitempty"` | ||
|
||
// +kubebuilder:validation:Optional | ||
CredentialOAuth2Token *ValueOrValueFrom `json:"credentialOAuth2,omitempty"` | ||
} | ||
|
||
// AlertDiscordStatus defines the observed state of AlertDiscord | ||
AlertDiscordStatus struct { | ||
AlertCoreStatus `json:",inline"` | ||
} | ||
) | ||
|
||
// +kubebuilder:object:root=true | ||
// +kubebuilder:subresource:status | ||
// +kubebuilder:resource:path=alertdiscords,scope=Cluster | ||
|
||
type AlertDiscord struct { | ||
metav1.TypeMeta `json:",inline"` | ||
metav1.ObjectMeta `json:"metadata,omitempty"` | ||
|
||
Spec AlertDiscordSpec `json:"spec,omitempty"` | ||
Status AlertDiscordStatus `json:"status,omitempty"` | ||
} | ||
|
||
// +kubebuilder:object:root=true | ||
|
||
type AlertDiscordList struct { | ||
metav1.TypeMeta `json:",inline"` | ||
metav1.ListMeta `json:"metadata,omitempty"` | ||
Items []AlertDiscord `json:"items"` | ||
} | ||
|
||
func init() { | ||
// SchemeBuilder.Register(&AlertDiscord{}, &AlertDiscordList{}) | ||
} |
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,78 @@ | ||
package v1alpha1 | ||
|
||
import ( | ||
corev1 "k8s.io/api/core/v1" | ||
) | ||
|
||
type ( | ||
ValueOrValueFrom struct { | ||
// Value is a string value to assign to the key. | ||
// if ValueFrom is specified, this value is ignored. | ||
// +optional | ||
Value string `json:"value,omitempty"` | ||
|
||
// ValueFrom is a reference to a field in a secret or config map. | ||
// +optional | ||
ValueFrom *ValueFromSource `json:"valueFrom,omitempty"` | ||
} | ||
|
||
// ValueFromSource is a reference to a field in a secret or config map. | ||
ValueFromSource struct { | ||
// SecretKeyRef is a reference to a field in a secret. | ||
// +optional | ||
SecretKeyRef *corev1.SecretKeySelector `json:"secretKeyRef,omitempty"` | ||
|
||
// ConfigMapKeyRef is a reference to a field in a config map. | ||
// +optional | ||
ConfigMapKeyRef *corev1.ConfigMapKeySelector `json:"configMapKeyRef,omitempty"` | ||
} | ||
) | ||
|
||
// func (v *ValueOrValueFrom) GetValue(ctx context.Context, namespace, name string) (string, error) { | ||
|
||
// // If ValueFrom is nil, return the value | ||
// if v.ValueFrom == nil { | ||
// return v.Value, nil | ||
// } | ||
|
||
// if v.ValueFrom.SecretKeyRef == nil && v.ValueFrom.ConfigMapKeyRef == nil { | ||
// return "", fmt.Errorf("ValueFrom is specified but neither SecretKeyRef nor ConfigMapKeyRef is set") | ||
// } | ||
|
||
// // // Read from config map | ||
// // if p.ConfigMapKeyRef != nil { | ||
// // var configMap coreV1.ConfigMap | ||
// // objectKey := types.NamespacedName{Namespace: namespace, Name: p.ConfigMapKeyRef.Name} | ||
// // err := r.GetKubeClient().Get(ctx, objectKey, &configMap) | ||
// // if errors.IsNotFound(err) { | ||
// // return "", err | ||
// // } | ||
// // key := p.ConfigMapKeyRef.Key | ||
// // if value, found := configMap.Data[key]; found { | ||
// // return value, nil | ||
// // } | ||
// // return "", brose_errors.NewMapEntryNotFoundError(key, nil) | ||
// // } | ||
|
||
// // // Read from secret | ||
// // if p.SecretKeyRef != nil { | ||
// // var secret coreV1.Secret | ||
// // objectKey := types.NamespacedName{Namespace: namespace, Name: p.SecretKeyRef.Name} | ||
// // err := r.Get(ctx, objectKey, &secret) | ||
// // if errors.IsNotFound(err) { | ||
// // return "", err | ||
// // } | ||
// // key := p.SecretKeyRef.Key | ||
// // valueBase64, foundBase64 := secret.Data[key] | ||
// // valueString, foundString := secret.StringData[key] | ||
// // if !foundBase64 && !foundString { | ||
// // return "", brose_errors.NewMapEntryNotFoundError(key, nil) | ||
// // } else if foundString { | ||
// // return valueString, nil | ||
// // } | ||
// // return string(valueBase64), nil | ||
// // } | ||
// // return "", brose_errors.NewMissingPropertyValueError(name, nil) | ||
|
||
// return "", nil | ||
// } |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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.