зеркало из https://github.com/Azure/ARO-RP.git
Move each controller into it's own sub-package
This commit is contained in:
Родитель
7ef54183a4
Коммит
54d6598b10
|
@ -16,6 +16,10 @@ import (
|
|||
pkgoperator "github.com/Azure/ARO-RP/pkg/operator"
|
||||
aroclient "github.com/Azure/ARO-RP/pkg/operator/clientset/versioned/typed/aro.openshift.io/v1alpha1"
|
||||
"github.com/Azure/ARO-RP/pkg/operator/controllers"
|
||||
"github.com/Azure/ARO-RP/pkg/operator/controllers/alertwebhook"
|
||||
"github.com/Azure/ARO-RP/pkg/operator/controllers/genevalogging"
|
||||
"github.com/Azure/ARO-RP/pkg/operator/controllers/internetchecker"
|
||||
"github.com/Azure/ARO-RP/pkg/operator/controllers/pullsecret"
|
||||
utillog "github.com/Azure/ARO-RP/pkg/util/log"
|
||||
// +kubebuilder:scaffold:imports
|
||||
)
|
||||
|
@ -57,25 +61,25 @@ func operator(ctx context.Context, log *logrus.Entry) error {
|
|||
}
|
||||
|
||||
if role == pkgoperator.RoleMaster {
|
||||
if err = (controllers.NewGenevaloggingReconciler(
|
||||
if err = (genevalogging.NewReconciler(
|
||||
log.WithField("controller", controllers.GenevaLoggingControllerName),
|
||||
kubernetescli, securitycli, arocli,
|
||||
restConfig)).SetupWithManager(mgr); err != nil {
|
||||
return fmt.Errorf("unable to create controller Genevalogging: %v", err)
|
||||
}
|
||||
if err = (controllers.NewPullSecretReconciler(
|
||||
if err = (pullsecret.NewReconciler(
|
||||
log.WithField("controller", controllers.PullSecretControllerName),
|
||||
kubernetescli, arocli)).SetupWithManager(mgr); err != nil {
|
||||
return fmt.Errorf("unable to create controller PullSecret: %v", err)
|
||||
}
|
||||
if err = (controllers.NewAlertWebhookReconciler(
|
||||
if err = (alertwebhook.NewReconciler(
|
||||
log.WithField("controller", controllers.AlertwebhookControllerName),
|
||||
kubernetescli)).SetupWithManager(mgr); err != nil {
|
||||
return fmt.Errorf("unable to create controller AlertWebhook: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
if err = (controllers.NewInternetChecker(
|
||||
if err = (internetchecker.NewReconciler(
|
||||
log.WithField("controller", controllers.InternetCheckerControllerName),
|
||||
kubernetescli, arocli,
|
||||
role,
|
||||
|
|
|
@ -31,7 +31,7 @@ import (
|
|||
"k8s.io/apimachinery/pkg/util/wait"
|
||||
|
||||
"github.com/Azure/ARO-RP/pkg/api"
|
||||
"github.com/Azure/ARO-RP/pkg/genevalogging"
|
||||
"github.com/Azure/ARO-RP/pkg/bootstraplogging"
|
||||
"github.com/Azure/ARO-RP/pkg/install"
|
||||
"github.com/Azure/ARO-RP/pkg/util/azureerrors"
|
||||
"github.com/Azure/ARO-RP/pkg/util/pullsecret"
|
||||
|
@ -314,7 +314,7 @@ func (m *Manager) Create(ctx context.Context) error {
|
|||
return err
|
||||
}
|
||||
|
||||
bootstrapLoggingConfig, err := genevalogging.GetBootstrapLoggingConfig(m.env, m.doc)
|
||||
bootstrapLoggingConfig, err := bootstraplogging.GetConfig(m.env, m.doc)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package genevalogging
|
||||
package bootstraplogging
|
||||
|
||||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the Apache License 2.0.
|
||||
|
@ -9,13 +9,14 @@ import (
|
|||
|
||||
"github.com/Azure/ARO-RP/pkg/api"
|
||||
"github.com/Azure/ARO-RP/pkg/env"
|
||||
"github.com/Azure/ARO-RP/pkg/operator/controllers/genevalogging"
|
||||
"github.com/Azure/ARO-RP/pkg/util/tls"
|
||||
"github.com/Azure/ARO-RP/pkg/util/version"
|
||||
)
|
||||
|
||||
// GetBootstrapLoggingConfig prepares a bootstraplogging.Config object based on
|
||||
// GetConfig prepares a bootstraplogging.Config object based on
|
||||
// the environment
|
||||
func GetBootstrapLoggingConfig(env env.Interface, doc *api.OpenShiftClusterDocument) (*bootstraplogging.Config, error) {
|
||||
func GetConfig(env env.Interface, doc *api.OpenShiftClusterDocument) (*bootstraplogging.Config, error) {
|
||||
r, err := azure.ParseResourceID(doc.OpenShiftCluster.ID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -36,7 +37,7 @@ func GetBootstrapLoggingConfig(env env.Interface, doc *api.OpenShiftClusterDocum
|
|||
return &bootstraplogging.Config{
|
||||
Certificate: string(gcsCertBytes),
|
||||
Key: string(gcsKeyBytes),
|
||||
Namespace: genevaClusterLogsNamespace,
|
||||
Namespace: genevalogging.ClusterLogsNamespace,
|
||||
Environment: env.ClustersGenevaLoggingEnvironment(),
|
||||
ConfigVersion: env.ClustersGenevaLoggingConfigVersion(),
|
||||
Region: env.Location(),
|
|
@ -1,4 +1,4 @@
|
|||
package controllers
|
||||
package alertwebhook
|
||||
|
||||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the Apache License 2.0.
|
||||
|
@ -20,6 +20,8 @@ import (
|
|||
"sigs.k8s.io/controller-runtime/pkg/event"
|
||||
"sigs.k8s.io/controller-runtime/pkg/predicate"
|
||||
"sigs.k8s.io/controller-runtime/pkg/reconcile"
|
||||
|
||||
"github.com/Azure/ARO-RP/pkg/operator/controllers"
|
||||
)
|
||||
|
||||
var alertManagerName = types.NamespacedName{Name: "alertmanager-main", Namespace: "openshift-monitoring"}
|
||||
|
@ -30,7 +32,7 @@ type AlertWebhookReconciler struct {
|
|||
log *logrus.Entry
|
||||
}
|
||||
|
||||
func NewAlertWebhookReconciler(log *logrus.Entry, kubernetescli kubernetes.Interface) *AlertWebhookReconciler {
|
||||
func NewReconciler(log *logrus.Entry, kubernetescli kubernetes.Interface) *AlertWebhookReconciler {
|
||||
return &AlertWebhookReconciler{
|
||||
kubernetescli: kubernetescli,
|
||||
log: log,
|
||||
|
@ -139,6 +141,6 @@ func (r *AlertWebhookReconciler) SetupWithManager(mgr ctrl.Manager) error {
|
|||
return ctrl.NewControllerManagedBy(mgr).
|
||||
For(&v1.Secret{}).
|
||||
WithEventFilter(isAlertManager).
|
||||
Named(AlertwebhookControllerName).
|
||||
Named(controllers.AlertwebhookControllerName).
|
||||
Complete(r)
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package controllers
|
||||
package alertwebhook
|
||||
|
||||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the Apache License 2.0.
|
|
@ -14,7 +14,7 @@ import (
|
|||
"github.com/Azure/ARO-RP/pkg/util/version"
|
||||
)
|
||||
|
||||
func setCondition(arocli aroclient.AroV1alpha1Interface, cond *status.Condition, role string) error {
|
||||
func SetCondition(arocli aroclient.AroV1alpha1Interface, cond *status.Condition, role string) error {
|
||||
return retry.RetryOnConflict(retry.DefaultRetry, func() error {
|
||||
cluster, err := arocli.Clusters().Get(arov1alpha1.SingletonClusterName, metav1.GetOptions{})
|
||||
if err != nil {
|
||||
|
|
|
@ -8,8 +8,8 @@ const (
|
|||
kubeServiceAccount = "system:serviceaccount:" + kubeNamespace + ":geneva"
|
||||
certificatesSecretName = "certificates"
|
||||
|
||||
genevaClusterLogsNamespace = "AROClusterLogs"
|
||||
parsersConf = `
|
||||
ClusterLogsNamespace = "AROClusterLogs"
|
||||
parsersConf = `
|
||||
[PARSER]
|
||||
Name audit
|
||||
Format json
|
|
@ -287,7 +287,7 @@ func (g *genevaLogging) daemonset(r azure.Resource) *appsv1.DaemonSet {
|
|||
},
|
||||
{
|
||||
Name: "MONITORING_GCS_NAMESPACE",
|
||||
Value: genevaClusterLogsNamespace,
|
||||
Value: ClusterLogsNamespace,
|
||||
},
|
||||
{
|
||||
Name: "MONITORING_CONFIG_VERSION",
|
|
@ -1,4 +1,4 @@
|
|||
package controllers
|
||||
package genevalogging
|
||||
|
||||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the Apache License 2.0.
|
||||
|
@ -22,10 +22,10 @@ import (
|
|||
"sigs.k8s.io/controller-runtime/pkg/reconcile"
|
||||
|
||||
"github.com/Azure/ARO-RP/pkg/dynamichelper"
|
||||
"github.com/Azure/ARO-RP/pkg/genevalogging"
|
||||
"github.com/Azure/ARO-RP/pkg/operator"
|
||||
arov1alpha1 "github.com/Azure/ARO-RP/pkg/operator/apis/aro.openshift.io/v1alpha1"
|
||||
aroclient "github.com/Azure/ARO-RP/pkg/operator/clientset/versioned/typed/aro.openshift.io/v1alpha1"
|
||||
"github.com/Azure/ARO-RP/pkg/operator/controllers"
|
||||
)
|
||||
|
||||
// GenevaloggingReconciler reconciles a Cluster object
|
||||
|
@ -37,7 +37,7 @@ type GenevaloggingReconciler struct {
|
|||
log *logrus.Entry
|
||||
}
|
||||
|
||||
func NewGenevaloggingReconciler(log *logrus.Entry, kubernetescli kubernetes.Interface, securitycli securityclient.Interface, arocli aroclient.AroV1alpha1Interface, restConfig *rest.Config) *GenevaloggingReconciler {
|
||||
func NewReconciler(log *logrus.Entry, kubernetescli kubernetes.Interface, securitycli securityclient.Interface, arocli aroclient.AroV1alpha1Interface, restConfig *rest.Config) *GenevaloggingReconciler {
|
||||
return &GenevaloggingReconciler{
|
||||
securitycli: securitycli,
|
||||
kubernetescli: kubernetescli,
|
||||
|
@ -71,7 +71,7 @@ func (r *GenevaloggingReconciler) Reconcile(request ctrl.Request) (ctrl.Result,
|
|||
r.log.Error(err)
|
||||
return reconcile.Result{}, err
|
||||
}
|
||||
gl := genevalogging.New(r.log, instance, r.securitycli, mysec.Data[genevalogging.GenevaCertName], mysec.Data[genevalogging.GenevaKeyName])
|
||||
gl := New(r.log, instance, r.securitycli, mysec.Data[GenevaCertName], mysec.Data[GenevaKeyName])
|
||||
|
||||
resources, err := gl.Resources()
|
||||
if err != nil {
|
||||
|
@ -137,6 +137,6 @@ func (r *GenevaloggingReconciler) SetupWithManager(mgr ctrl.Manager) error {
|
|||
Owns(&corev1.Secret{}).
|
||||
Owns(&corev1.ServiceAccount{}).
|
||||
Owns(&securityv1.SecurityContextConstraints{}).
|
||||
Named(GenevaLoggingControllerName).
|
||||
Named(controllers.GenevaLoggingControllerName).
|
||||
Complete(r)
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package controllers
|
||||
package internetchecker
|
||||
|
||||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the Apache License 2.0.
|
||||
|
@ -21,6 +21,7 @@ import (
|
|||
"github.com/Azure/ARO-RP/pkg/operator"
|
||||
arov1alpha1 "github.com/Azure/ARO-RP/pkg/operator/apis/aro.openshift.io/v1alpha1"
|
||||
aroclient "github.com/Azure/ARO-RP/pkg/operator/clientset/versioned/typed/aro.openshift.io/v1alpha1"
|
||||
"github.com/Azure/ARO-RP/pkg/operator/controllers"
|
||||
)
|
||||
|
||||
// InternetChecker reconciles a Cluster object
|
||||
|
@ -31,7 +32,7 @@ type InternetChecker struct {
|
|||
role string
|
||||
}
|
||||
|
||||
func NewInternetChecker(log *logrus.Entry, kubernetescli kubernetes.Interface, arocli aroclient.AroV1alpha1Interface, role string) *InternetChecker {
|
||||
func NewReconciler(log *logrus.Entry, kubernetescli kubernetes.Interface, arocli aroclient.AroV1alpha1Interface, role string) *InternetChecker {
|
||||
return &InternetChecker{
|
||||
kubernetescli: kubernetescli,
|
||||
arocli: arocli,
|
||||
|
@ -82,14 +83,14 @@ func (r *InternetChecker) Reconcile(request ctrl.Request) (ctrl.Result, error) {
|
|||
for url, err := range urlErrors {
|
||||
fmt.Fprintf(sb, "%s: %s\n", url, err)
|
||||
}
|
||||
err = setCondition(r.arocli, &status.Condition{
|
||||
err = controllers.SetCondition(r.arocli, &status.Condition{
|
||||
Type: condition,
|
||||
Status: corev1.ConditionFalse,
|
||||
Message: sb.String(),
|
||||
Reason: "CheckFailed",
|
||||
}, r.role)
|
||||
} else {
|
||||
err = setCondition(r.arocli, &status.Condition{
|
||||
err = controllers.SetCondition(r.arocli, &status.Condition{
|
||||
Type: condition,
|
||||
Status: corev1.ConditionTrue,
|
||||
Message: "Outgoing connection successful.",
|
||||
|
@ -125,6 +126,6 @@ func (r *InternetChecker) check(client simpleHTTPClient, url string) error {
|
|||
func (r *InternetChecker) SetupWithManager(mgr ctrl.Manager) error {
|
||||
return ctrl.NewControllerManagedBy(mgr).
|
||||
For(&arov1alpha1.Cluster{}).
|
||||
Named(InternetCheckerControllerName).
|
||||
Named(controllers.InternetCheckerControllerName).
|
||||
Complete(r)
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package controllers
|
||||
package internetchecker
|
||||
|
||||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the Apache License 2.0.
|
|
@ -1,4 +1,4 @@
|
|||
package controllers
|
||||
package pullsecret
|
||||
|
||||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the Apache License 2.0.
|
||||
|
@ -22,6 +22,7 @@ import (
|
|||
"github.com/Azure/ARO-RP/pkg/operator"
|
||||
arov1alpha1 "github.com/Azure/ARO-RP/pkg/operator/apis/aro.openshift.io/v1alpha1"
|
||||
aroclient "github.com/Azure/ARO-RP/pkg/operator/clientset/versioned/typed/aro.openshift.io/v1alpha1"
|
||||
"github.com/Azure/ARO-RP/pkg/operator/controllers"
|
||||
"github.com/Azure/ARO-RP/pkg/util/pullsecret"
|
||||
)
|
||||
|
||||
|
@ -34,7 +35,7 @@ type PullSecretReconciler struct {
|
|||
log *logrus.Entry
|
||||
}
|
||||
|
||||
func NewPullSecretReconciler(log *logrus.Entry, kubernetescli kubernetes.Interface, arocli aroclient.AroV1alpha1Interface) *PullSecretReconciler {
|
||||
func NewReconciler(log *logrus.Entry, kubernetescli kubernetes.Interface, arocli aroclient.AroV1alpha1Interface) *PullSecretReconciler {
|
||||
return &PullSecretReconciler{
|
||||
log: log,
|
||||
kubernetescli: kubernetescli,
|
||||
|
@ -182,6 +183,6 @@ func (r *PullSecretReconciler) SetupWithManager(mgr ctrl.Manager) error {
|
|||
For(&v1.Secret{}).
|
||||
Owns(&v1.Secret{}).
|
||||
WithEventFilter(isPullSecret).
|
||||
Named(PullSecretControllerName).
|
||||
Named(controllers.PullSecretControllerName).
|
||||
Complete(r)
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package controllers
|
||||
package pullsecret
|
||||
|
||||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the Apache License 2.0.
|
|
@ -25,10 +25,10 @@ import (
|
|||
"github.com/Azure/ARO-RP/pkg/api"
|
||||
"github.com/Azure/ARO-RP/pkg/dynamichelper"
|
||||
"github.com/Azure/ARO-RP/pkg/env"
|
||||
"github.com/Azure/ARO-RP/pkg/genevalogging"
|
||||
pkgoperator "github.com/Azure/ARO-RP/pkg/operator"
|
||||
arov1alpha1 "github.com/Azure/ARO-RP/pkg/operator/apis/aro.openshift.io/v1alpha1"
|
||||
aroclient "github.com/Azure/ARO-RP/pkg/operator/clientset/versioned/typed/aro.openshift.io/v1alpha1"
|
||||
"github.com/Azure/ARO-RP/pkg/operator/controllers/genevalogging"
|
||||
"github.com/Azure/ARO-RP/pkg/util/pullsecret"
|
||||
"github.com/Azure/ARO-RP/pkg/util/ready"
|
||||
"github.com/Azure/ARO-RP/pkg/util/restconfig"
|
||||
|
|
|
@ -14,7 +14,7 @@ package operator
|
|||
//go:generate go run ../../vendor/sigs.k8s.io/controller-tools/cmd/controller-gen "crd:trivialVersions=true" paths="./apis/..." output:crd:dir=deploy/staticresources
|
||||
// for worker deployment - less privledges as it only runs the internetchecker
|
||||
// rbac (based on in-code tags - search for "+kubebuilder:rbac")
|
||||
//go:generate go run ../../vendor/sigs.k8s.io/controller-tools/cmd/controller-gen rbac:roleName=aro-operator-worker paths="controllers/internetchecker_controller.go" output:dir=deploy/staticresources/worker
|
||||
//go:generate go run ../../vendor/sigs.k8s.io/controller-tools/cmd/controller-gen rbac:roleName=aro-operator-worker paths="controllers/internetchecker/..." output:dir=deploy/staticresources/worker
|
||||
|
||||
// bindata for the above yaml files
|
||||
//go:generate go run ../../vendor/github.com/go-bindata/go-bindata/go-bindata -nometadata -pkg deploy -prefix deploy/staticresources/ -o deploy/bindata.go deploy/staticresources/...
|
||||
|
|
Загрузка…
Ссылка в новой задаче