|
|
|
@ -24,6 +24,8 @@ import (
|
|
|
|
|
networkv1 "k8s.io/api/networking/v1"
|
|
|
|
|
"k8s.io/apimachinery/pkg/api/errors"
|
|
|
|
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
|
|
|
"k8s.io/apimachinery/pkg/runtime/schema"
|
|
|
|
|
"k8s.io/client-go/dynamic"
|
|
|
|
|
"reflect"
|
|
|
|
|
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
|
|
|
|
|
"strings"
|
|
|
|
@ -42,19 +44,38 @@ var WaitRequeue = 10 * time.Second
|
|
|
|
|
// MsbDeploymentReconciler reconciles a MsbDeployment object
|
|
|
|
|
type MsbDeploymentReconciler struct {
|
|
|
|
|
client.Client
|
|
|
|
|
Scheme *runtime.Scheme
|
|
|
|
|
DynamicClient dynamic.Interface // 用来访问 issuer和certificate资源
|
|
|
|
|
Scheme *runtime.Scheme
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 创建GVR, 共动态客户端使用
|
|
|
|
|
var (
|
|
|
|
|
// issuer
|
|
|
|
|
issuerGVR = schema.GroupVersionResource{
|
|
|
|
|
Group: "cert-manager.io",
|
|
|
|
|
Version: "v1",
|
|
|
|
|
Resource: "issuers",
|
|
|
|
|
}
|
|
|
|
|
// certificate
|
|
|
|
|
certGVR = schema.GroupVersionResource{
|
|
|
|
|
Group: "cert-manager.io",
|
|
|
|
|
Version: "v1",
|
|
|
|
|
Resource: "certificates",
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
//+kubebuilder:rbac:groups=apps.mashibing.com,resources=msbdeployments,verbs=get;list;watch;create;update;patch;delete
|
|
|
|
|
//+kubebuilder:rbac:groups=apps.mashibing.com,resources=msbdeployments/status,verbs=get;update;patch
|
|
|
|
|
//+kubebuilder:rbac:groups=apps.mashibing.com,resources=msbdeployments/finalizers,verbs=update
|
|
|
|
|
//+kubebuilder:rbac:groups="",resources=services,verbs=get;list;watch;create;update;patch;delete
|
|
|
|
|
//+kubebuilder:rbac:groups="apps",resources=deployments,verbs=get;list;watch;create;update;patch;delete
|
|
|
|
|
//+kubebuilder:rbac:groups="networking.k8s.io",resources=ingresses,verbs=get;list;watch;create;update;patch;delete
|
|
|
|
|
// 创建 issuer 和 certificate 资源需要的权限
|
|
|
|
|
//+kubebuilder:rbac:groups=cert-manager.io,resources=issuers,verbs=get;list;watch;create;update;patch
|
|
|
|
|
//+kubebuilder:rbac:groups=cert-manager.io,resources=certificates,verbs=get;list;watch;create;update;patch
|
|
|
|
|
|
|
|
|
|
// Reconcile is part of the main kubernetes reconciliation loop which aims to
|
|
|
|
|
// move the current state of the cluster closer to the desired state.
|
|
|
|
|
// TODO(user): Modify the Reconcile function to compare the state specified by
|
|
|
|
|
// the MsbDeployment object against the actual cluster state, and then
|
|
|
|
|
// perform operations to make the cluster state reflect the state specified by
|
|
|
|
|
// the user.
|
|
|
|
@ -226,6 +247,17 @@ func (r *MsbDeploymentReconciler) Reconcile(ctx context.Context, req ctrl.Reques
|
|
|
|
|
myAppsv1.ConditionReasonIngressNotReady); errStatus != nil {
|
|
|
|
|
return ctrl.Result{}, errStatus
|
|
|
|
|
}
|
|
|
|
|
if mdCopy.Spec.Expose.Tls {
|
|
|
|
|
// 创建 issuers
|
|
|
|
|
if err := r.createIssuer(ctx, mdCopy); err != nil {
|
|
|
|
|
return ctrl.Result{}, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 创建 certificates
|
|
|
|
|
if err := r.createCert(ctx, mdCopy); err != nil {
|
|
|
|
|
return ctrl.Result{}, err
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else if strings.ToLower(mdCopy.Spec.Expose.Mode) == myAppsv1.ModeNodePort {
|
|
|
|
|
// 4.1.2 mode 为 nodeport
|
|
|
|
|
// 4.1.2.1 退出
|
|
|
|
@ -258,6 +290,17 @@ func (r *MsbDeploymentReconciler) Reconcile(ctx context.Context, req ctrl.Reques
|
|
|
|
|
myAppsv1.ConditionReasonIngressReady); errStatus != nil {
|
|
|
|
|
return ctrl.Result{}, errStatus
|
|
|
|
|
}
|
|
|
|
|
if mdCopy.Spec.Expose.Tls {
|
|
|
|
|
// 创建 issuers
|
|
|
|
|
if err := r.createIssuer(ctx, mdCopy); err != nil {
|
|
|
|
|
return ctrl.Result{}, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 创建 certificates
|
|
|
|
|
if err := r.createCert(ctx, mdCopy); err != nil {
|
|
|
|
|
return ctrl.Result{}, err
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else if strings.ToLower(mdCopy.Spec.Expose.Mode) == myAppsv1.ModeNodePort {
|
|
|
|
|
// 4.2.2 mode 为 nodeport
|
|
|
|
|
// 4.2.2.1 删除 ingress
|
|
|
|
@ -290,7 +333,7 @@ func (r *MsbDeploymentReconciler) SetupWithManager(mgr ctrl.Manager) error {
|
|
|
|
|
return ctrl.NewControllerManagedBy(mgr).
|
|
|
|
|
For(&myAppsv1.MsbDeployment{}).
|
|
|
|
|
Owns(&appsv1.Deployment{}). // 监控 deployment 类型,变更就触发 reconciler
|
|
|
|
|
Owns(&corev1.Service{}). // 监控 service 类型,变更就触发 reconciler
|
|
|
|
|
Owns(&corev1.Service{}). // 监控 service 类型,变更就触发 reconciler
|
|
|
|
|
Owns(&networkv1.Ingress{}). // 监控 ingress 类型,变更就触发 reconciler
|
|
|
|
|
Complete(r)
|
|
|
|
|
}
|
|
|
|
@ -544,6 +587,14 @@ func (r *MsbDeploymentReconciler) deleteStatus(md *myAppsv1.MsbDeployment, condi
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (r *MsbDeploymentReconciler) createIssuer(ctx context.Context, mdCopy *myAppsv1.MsbDeployment) error {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (r *MsbDeploymentReconciler) createCert(ctx context.Context, mdCopy *myAppsv1.MsbDeployment) error {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// a := struct {
|
|
|
|
|
// len int
|
|
|
|
|
// cap int
|
|
|
|
|