Skip to content

Commit

Permalink
Refactor to phase and health controllers
Browse files Browse the repository at this point in the history
  • Loading branch information
int128 committed Jan 1, 2024
1 parent 0684606 commit cf15278
Show file tree
Hide file tree
Showing 22 changed files with 731 additions and 571 deletions.
23 changes: 11 additions & 12 deletions PROJECT
Original file line number Diff line number Diff line change
Expand Up @@ -11,35 +11,34 @@ resources:
- controller: true
domain: int128.github.io
group: argocdcommenter
kind: ApplicationHealthComment
kind: ApplicationDeletionDeployment
version: v1
- api:
crdVersion: v1
namespaced: true
controller: true
- controller: true
domain: int128.github.io
group: argocdcommenter
kind: ApplicationHealth
path: github.com/int128/argocd-commenter/api/v1
kind: ApplicationPhase
version: v1
- controller: true
domain: int128.github.io
group: argocdcommenter
kind: ApplicationHealthDeployment
kind: ApplicationHealth
version: v1
- controller: true
- api:
crdVersion: v1
namespaced: true
domain: int128.github.io
group: argocdcommenter
kind: ApplicationPhaseComment
kind: Notification
path: github.com/int128/argocd-commenter/api/v1
version: v1
- controller: true
domain: int128.github.io
group: argocdcommenter
kind: ApplicationPhaseDeployment
kind: NotificationComment
version: v1
- controller: true
domain: int128.github.io
group: argocdcommenter
kind: ApplicationDeletionDeployment
kind: NotificationDeployment
version: v1
version: "3"
60 changes: 0 additions & 60 deletions api/v1/applicationhealth_types.go

This file was deleted.

72 changes: 72 additions & 0 deletions api/v1/notification_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
Copyright 2021.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package v1

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// NotificationSpec defines the desired state of Notification
type NotificationSpec struct{}

// NotificationStatus defines the observed state of Notification
type NotificationStatus struct {
// +optional
State NotificationState `json:"state,omitempty"`

// +optional
CommentState NotificationState `json:"commentState,omitempty"`

// +optional
DeploymentState NotificationState `json:"deploymentState,omitempty"`
}

type NotificationState string

const (
NotificationStateSyncing NotificationState = "Syncing"
NotificationStateSynced NotificationState = "Synced"
NotificationStateSyncFailed NotificationState = "SyncFailed"
NotificationStateProgressing NotificationState = "Progressing"
NotificationStateHealthy NotificationState = "Healthy"
NotificationStateDegraded NotificationState = "Degraded"
)

//+kubebuilder:object:root=true
//+kubebuilder:subresource:status

// Notification is the Schema for the notifications API
type Notification struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec NotificationSpec `json:"spec,omitempty"`
Status NotificationStatus `json:"status,omitempty"`
}

//+kubebuilder:object:root=true

// NotificationList contains a list of Notification
type NotificationList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []Notification `json:"items"`
}

func init() {
SchemeBuilder.Register(&Notification{}, &NotificationList{})
}
38 changes: 19 additions & 19 deletions api/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

43 changes: 17 additions & 26 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,55 +106,46 @@ func main() {
}
notificationClient := notification.NewClient(ghc)

if err = (&controller.ApplicationHealthReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "ApplicationHealth")
os.Exit(1)
}

// comment controller
if err = (&controller.ApplicationPhaseCommentReconciler{
if err = (&controller.ApplicationDeletionDeploymentReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
Notification: notificationClient,
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "ApplicationPhaseComment")
setupLog.Error(err, "unable to create controller", "controller", "ApplicationDeletionDeployment")
os.Exit(1)
}
if err = (&controller.ApplicationHealthCommentReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
Notification: notificationClient,

if err = (&controller.ApplicationPhaseReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "ApplicationHealthComment")
setupLog.Error(err, "unable to create controller", "controller", "ApplicationPhase")
os.Exit(1)
}

// deployment controller
if err = (&controller.ApplicationPhaseDeploymentReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
Notification: notificationClient,
if err = (&controller.ApplicationHealthReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "ApplicationPhaseDeployment")
setupLog.Error(err, "unable to create controller", "controller", "ApplicationHealth")
os.Exit(1)
}
if err = (&controller.ApplicationHealthDeploymentReconciler{

if err = (&controller.NotificationCommentReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
Notification: notificationClient,
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "ApplicationHealthDeployment")
setupLog.Error(err, "unable to create controller", "controller", "NotificationComment")
os.Exit(1)
}
if err = (&controller.ApplicationDeletionDeploymentReconciler{

if err = (&controller.NotificationDeploymentReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
Notification: notificationClient,
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "ApplicationDeletionDeployment")
setupLog.Error(err, "unable to create controller", "controller", "NotificationDeployment")
os.Exit(1)
}
//+kubebuilder:scaffold:builder
Expand Down
Loading

0 comments on commit cf15278

Please sign in to comment.