Skip to content
This repository has been archived by the owner on Mar 26, 2024. It is now read-only.

Commit

Permalink
Merge pull request #11 from amazeeio/admissionfix
Browse files Browse the repository at this point in the history
Minor fixes
  • Loading branch information
shreddedbacon authored Dec 2, 2020
2 parents 7d36925 + 73dbc14 commit 0742c13
Show file tree
Hide file tree
Showing 9 changed files with 240 additions and 74 deletions.
Binary file added charts/dioscuri-0.1.5.tgz
Binary file not shown.
4 changes: 2 additions & 2 deletions charts/dioscuri/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ type: application

# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
version: 0.1.4
version: 0.1.5

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application.
appVersion: 0.1.6
appVersion: 0.1.7
2 changes: 1 addition & 1 deletion charts/dioscuri/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ replicaCount: 1

image:
repository: amazeeio/dioscuri
tag: v0.1.6
tag: v0.1.7
pullPolicy: IfNotPresent

kubeRbacProxy:
Expand Down
22 changes: 16 additions & 6 deletions charts/index.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
apiVersion: v1
entries:
dioscuri:
- apiVersion: v2
appVersion: 0.1.7
created: "2020-12-02T12:28:09.451492+11:00"
description: A Helm chart for dioscuri
digest: 282b5b1255ab4a70e7fd8b0e592711db50b14c35fdfca931a3c587aaa1b1cf2d
name: dioscuri
type: application
urls:
- dioscuri-0.1.5.tgz
version: 0.1.5
- apiVersion: v2
appVersion: 0.1.6
created: "2020-11-02T09:18:35.139741+11:00"
created: "2020-12-02T12:28:09.450482+11:00"
description: A Helm chart for dioscuri
digest: ad08ced993bb6926a6c26cf78262c09d1926a6c3b8444e1b0af46e5fbe5e33ae
name: dioscuri
Expand All @@ -13,7 +23,7 @@ entries:
version: 0.1.4
- apiVersion: v2
appVersion: 0.1.6rc2
created: "2020-11-02T09:18:35.139337+11:00"
created: "2020-12-02T12:28:09.449815+11:00"
description: A Helm chart for dioscuri
digest: a135357d009a3e4070bedaf72d7b5c96cc71d8d21f54f54094efc237371bfac0
name: dioscuri
Expand All @@ -23,7 +33,7 @@ entries:
version: 0.1.3
- apiVersion: v2
appVersion: 0.1.6rc2
created: "2020-11-02T09:18:35.138651+11:00"
created: "2020-12-02T12:28:09.449151+11:00"
description: A Helm chart for dioscuri
digest: 057df5c8fcc93af6f11a6ff897380993afa7d19ecc4a22de693903759dab44b5
name: dioscuri
Expand All @@ -33,7 +43,7 @@ entries:
version: 0.1.2
- apiVersion: v2
appVersion: 0.1.6rc2
created: "2020-11-02T09:18:35.137789+11:00"
created: "2020-12-02T12:28:09.448129+11:00"
description: A Helm chart for dioscuri
digest: 26dabd76ba6be80d2d2bb96be56a9072c9898171bea55db946b6f55156a83ea2
name: dioscuri
Expand All @@ -43,12 +53,12 @@ entries:
version: 0.1.1
- apiVersion: v2
appVersion: 0.1.6rc1
created: "2020-11-02T09:18:35.136305+11:00"
created: "2020-12-02T12:28:09.447401+11:00"
description: A Helm chart for dioscuri
digest: 061da4faee494f78731af48db46d3af8c1e388c0c292b91f5ebb00e3c4c16e84
name: dioscuri
type: application
urls:
- dioscuri-0.1.0.tgz
version: 0.1.0
generated: "2020-11-02T09:18:35.135326+11:00"
generated: "2020-12-02T12:28:09.444566+11:00"
16 changes: 14 additions & 2 deletions controllers/hostmigration_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ package controllers

import (
"context"
"encoding/json"

"github.com/go-logr/logr"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"

Expand Down Expand Up @@ -87,7 +89,12 @@ func (r *HostMigrationReconciler) Reconcile(req ctrl.Request) (ctrl.Result, erro
// registering our finalizer.
if !ContainsString(dioscuri.ObjectMeta.Finalizers, finalizerName) {
dioscuri.ObjectMeta.Finalizers = append(dioscuri.ObjectMeta.Finalizers, finalizerName)
if err := r.Update(ctx, &dioscuri); err != nil {
mergePatch, _ := json.Marshal(map[string]interface{}{
"metadata": map[string]interface{}{
"finalizers": dioscuri.ObjectMeta.Finalizers,
},
})
if err := r.Patch(ctx, &dioscuri, client.ConstantPatch(types.MergePatchType, mergePatch)); err != nil {
return ctrl.Result{}, err
}
}
Expand All @@ -102,7 +109,12 @@ func (r *HostMigrationReconciler) Reconcile(req ctrl.Request) (ctrl.Result, erro
}
// remove our finalizer from the list and update it.
dioscuri.ObjectMeta.Finalizers = RemoveString(dioscuri.ObjectMeta.Finalizers, finalizerName)
if err := r.Update(ctx, &dioscuri); err != nil {
mergePatch, _ := json.Marshal(map[string]interface{}{
"metadata": map[string]interface{}{
"finalizers": dioscuri.ObjectMeta.Finalizers,
},
})
if err := r.Patch(ctx, &dioscuri, client.ConstantPatch(types.MergePatchType, mergePatch)); err != nil {
return ctrl.Result{}, err
}
}
Expand Down
66 changes: 51 additions & 15 deletions controllers/ingress_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,12 @@ func (r *HostMigrationReconciler) KubernetesHandler(ctx context.Context, opLog l
return ctrl.Result{}, nil
}

func (r *HostMigrationReconciler) checkKubernetesServices(ctx context.Context, dioscuri *dioscuriv1.HostMigration, ingressList *networkv1beta1.IngressList, ingressToMigrate *networkv1beta1.IngressList, destinationNamespace string) error {
func (r *HostMigrationReconciler) checkKubernetesServices(ctx context.Context,
dioscuri *dioscuriv1.HostMigration,
ingressList *networkv1beta1.IngressList,
ingressToMigrate *networkv1beta1.IngressList,
destinationNamespace string,
) error {
// check service for ingress exists in destination namespace
for _, ingress := range ingressList.Items {
for _, host := range ingress.Spec.Rules {
Expand All @@ -334,7 +339,8 @@ func (r *HostMigrationReconciler) checkKubernetesServices(ctx context.Context, d
)
if err != nil {
if apierrors.IsNotFound(err) {
return fmt.Errorf("Service %s for ingress %s doesn't exist in namespace %s, skipping ingress", path.Backend.ServiceName, host.Host, destinationNamespace)
return fmt.Errorf("Service %s for ingress %s doesn't exist in namespace %s, skipping ingress",
path.Backend.ServiceName, host.Host, destinationNamespace)
}
return fmt.Errorf("Error getting service, error was: %v", err)
}
Expand All @@ -345,7 +351,11 @@ func (r *HostMigrationReconciler) checkKubernetesServices(ctx context.Context, d
return nil
}

func (r *HostMigrationReconciler) checkSecrets(ctx context.Context, dioscuri *dioscuriv1.HostMigration, ingressList *networkv1beta1.IngressList, destinationNamespace string) error {
func (r *HostMigrationReconciler) checkSecrets(ctx context.Context,
dioscuri *dioscuriv1.HostMigration,
ingressList *networkv1beta1.IngressList,
destinationNamespace string,
) error {
// check service for ingress exists in destination namespace
opLog := r.Log.WithValues("ingressmigrate", dioscuri.ObjectMeta.Namespace)
for _, ingress := range ingressList.Items {
Expand All @@ -371,7 +381,11 @@ func (r *HostMigrationReconciler) checkSecrets(ctx context.Context, dioscuri *di
return nil
}

func (r *HostMigrationReconciler) getIngressWithLabel(dioscuri *dioscuriv1.HostMigration, ingress *networkv1beta1.IngressList, namespace string, labels map[string]string) error {
func (r *HostMigrationReconciler) getIngressWithLabel(dioscuri *dioscuriv1.HostMigration,
ingress *networkv1beta1.IngressList,
namespace string,
labels map[string]string,
) error {
// collect any ingress with specific labels
listOption := (&client.ListOptions{}).ApplyOptions([]client.ListOption{
client.InNamespace(namespace),
Expand Down Expand Up @@ -399,7 +413,12 @@ func (r *HostMigrationReconciler) getIngressWithLabel(dioscuri *dioscuriv1.HostM
// return nil
// }

func (r *HostMigrationReconciler) individualIngressMigration(ctx context.Context, dioscuri *dioscuriv1.HostMigration, ingress *networkv1beta1.Ingress, sourceNamespace string, destinationNamespace string) (*networkv1beta1.Ingress, error) {
func (r *HostMigrationReconciler) individualIngressMigration(ctx context.Context,
dioscuri *dioscuriv1.HostMigration,
ingress *networkv1beta1.Ingress,
sourceNamespace string,
destinationNamespace string,
) (*networkv1beta1.Ingress, error) {
opLog := r.Log.WithValues("ingressmigrate", dioscuri.ObjectMeta.Namespace)
oldIngress := &networkv1beta1.Ingress{}
newIngress := &networkv1beta1.Ingress{}
Expand Down Expand Up @@ -435,17 +454,21 @@ func (r *HostMigrationReconciler) individualIngressMigration(ctx context.Context
}

// add ingress, and then remove the old one only if we successfully create the new one
func (r *HostMigrationReconciler) migrateIngress(ctx context.Context, dioscuri *dioscuriv1.HostMigration, newIngress *networkv1beta1.Ingress, oldIngress *networkv1beta1.Ingress) error {
// add ingress
func (r *HostMigrationReconciler) migrateIngress(ctx context.Context,
dioscuri *dioscuriv1.HostMigration,
newIngress *networkv1beta1.Ingress,
oldIngress *networkv1beta1.Ingress,
) error {
opLog := r.Log.WithValues("ingressmigrate", dioscuri.ObjectMeta.Namespace)
if err := r.addIngressIfNotExist(ctx, dioscuri, newIngress); err != nil {
return fmt.Errorf("Unable to create ingress %s in %s: %v", newIngress.ObjectMeta.Name, newIngress.ObjectMeta.Namespace, err)
}
// delete old ingress from the old namespace
opLog.Info(fmt.Sprintf("Removing old ingress %s in namespace %s", oldIngress.ObjectMeta.Name, oldIngress.ObjectMeta.Namespace))
if err := r.removeIngress(ctx, oldIngress); err != nil {
return fmt.Errorf("Unable to remove old ingress %s in %s: %v", oldIngress.ObjectMeta.Name, oldIngress.ObjectMeta.Namespace, err)
}
// add ingress
if err := r.addIngressIfNotExist(ctx, dioscuri, newIngress); err != nil {
return fmt.Errorf("Unable to create ingress %s in %s: %v", newIngress.ObjectMeta.Name, newIngress.ObjectMeta.Namespace, err)
}
return nil
}

Expand Down Expand Up @@ -527,14 +550,27 @@ func (r *HostMigrationReconciler) removeIngress(ctx context.Context, ingress *ne
}

// update status
func (r *HostMigrationReconciler) updateKubernetesStatusCondition(ctx context.Context, dioscuri *dioscuriv1.HostMigration, condition dioscuriv1.HostMigrationConditions, activeIngress []string, standbyIngress []string) error {
dioscuri.Spec.Hosts.ActiveHosts = strings.Join(activeIngress, ",")
dioscuri.Spec.Hosts.StandbyHosts = strings.Join(standbyIngress, ",")
func (r *HostMigrationReconciler) updateKubernetesStatusCondition(ctx context.Context,
dioscuri *dioscuriv1.HostMigration,
condition dioscuriv1.HostMigrationConditions,
activeIngress []string,
standbyIngress []string) error {
// set the transition time
condition.LastTransitionTime = time.Now().Format(time.RFC3339)
condition.LastTransitionTime = time.Now().UTC().Format(time.RFC3339)
if !HostMigrationContainsStatus(dioscuri.Status.Conditions, condition) {
dioscuri.Status.Conditions = append(dioscuri.Status.Conditions, condition)
if err := r.Update(ctx, dioscuri); err != nil {
mergePatch, _ := json.Marshal(map[string]interface{}{
"status": map[string]interface{}{
"conditions": dioscuri.Status.Conditions,
},
"spec": map[string]interface{}{
"hosts": map[string]string{
"activeHosts": strings.Join(activeIngress, ","),
"standbyHosts": strings.Join(standbyIngress, ","),
},
},
})
if err := r.Patch(ctx, dioscuri, client.ConstantPatch(types.MergePatchType, mergePatch)); err != nil {
return fmt.Errorf("Unable to update status condition: %v", err)
}
}
Expand Down
78 changes: 62 additions & 16 deletions controllers/ingressmigrate_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,12 @@ func (r *IngressMigrateReconciler) Reconcile(req ctrl.Request) (ctrl.Result, err
// registering our finalizer.
if !ContainsString(dioscuri.ObjectMeta.Finalizers, finalizerName) {
dioscuri.ObjectMeta.Finalizers = append(dioscuri.ObjectMeta.Finalizers, finalizerName)
if err := r.Update(ctx, &dioscuri); err != nil {
mergePatch, _ := json.Marshal(map[string]interface{}{
"metadata": map[string]interface{}{
"finalizers": dioscuri.ObjectMeta.Finalizers,
},
})
if err := r.Patch(ctx, &dioscuri, client.ConstantPatch(types.MergePatchType, mergePatch)); err != nil {
return ctrl.Result{}, err
}
}
Expand All @@ -398,7 +403,12 @@ func (r *IngressMigrateReconciler) Reconcile(req ctrl.Request) (ctrl.Result, err
}
// remove our finalizer from the list and update it.
dioscuri.ObjectMeta.Finalizers = RemoveString(dioscuri.ObjectMeta.Finalizers, finalizerName)
if err := r.Update(ctx, &dioscuri); err != nil {
mergePatch, _ := json.Marshal(map[string]interface{}{
"metadata": map[string]interface{}{
"finalizers": dioscuri.ObjectMeta.Finalizers,
},
})
if err := r.Patch(ctx, &dioscuri, client.ConstantPatch(types.MergePatchType, mergePatch)); err != nil {
return ctrl.Result{}, err
}
}
Expand All @@ -418,7 +428,12 @@ func (r *IngressMigrateReconciler) deleteExternalResources(dioscuri *dioscuriv1.
return nil
}

func (r *IngressMigrateReconciler) checkServices(ctx context.Context, dioscuri *dioscuriv1.IngressMigrate, ingressList *networkv1beta1.IngressList, ingressToMigrate *networkv1beta1.IngressList, destinationNamespace string) error {
func (r *IngressMigrateReconciler) checkServices(ctx context.Context,
dioscuri *dioscuriv1.IngressMigrate,
ingressList *networkv1beta1.IngressList,
ingressToMigrate *networkv1beta1.IngressList,
destinationNamespace string,
) error {
// check service for ingress exists in destination namespace
for _, ingress := range ingressList.Items {
for _, host := range ingress.Spec.Rules {
Expand All @@ -444,7 +459,11 @@ func (r *IngressMigrateReconciler) checkServices(ctx context.Context, dioscuri *
return nil
}

func (r *IngressMigrateReconciler) checkSecrets(ctx context.Context, dioscuri *dioscuriv1.IngressMigrate, ingressList *networkv1beta1.IngressList, destinationNamespace string) error {
func (r *IngressMigrateReconciler) checkSecrets(ctx context.Context,
dioscuri *dioscuriv1.IngressMigrate,
ingressList *networkv1beta1.IngressList,
destinationNamespace string,
) error {
// check service for ingress exists in destination namespace
opLog := r.Log.WithValues("ingressmigrate", dioscuri.ObjectMeta.Namespace)
for _, ingress := range ingressList.Items {
Expand All @@ -470,7 +489,11 @@ func (r *IngressMigrateReconciler) checkSecrets(ctx context.Context, dioscuri *d
return nil
}

func (r *IngressMigrateReconciler) getIngressWithLabel(dioscuri *dioscuriv1.IngressMigrate, ingress *networkv1beta1.IngressList, namespace string, labels map[string]string) error {
func (r *IngressMigrateReconciler) getIngressWithLabel(dioscuri *dioscuriv1.IngressMigrate,
ingress *networkv1beta1.IngressList,
namespace string,
labels map[string]string,
) error {
// collect any ingress with specific labels
listOption := (&client.ListOptions{}).ApplyOptions([]client.ListOption{
client.InNamespace(namespace),
Expand Down Expand Up @@ -498,7 +521,12 @@ func (r *IngressMigrateReconciler) cleanUpAcmeChallenges(dioscuri *dioscuriv1.In
return nil
}

func (r *IngressMigrateReconciler) individualIngressMigration(ctx context.Context, dioscuri *dioscuriv1.IngressMigrate, ingress *networkv1beta1.Ingress, sourceNamespace string, destinationNamespace string) (*networkv1beta1.Ingress, error) {
func (r *IngressMigrateReconciler) individualIngressMigration(ctx context.Context,
dioscuri *dioscuriv1.IngressMigrate,
ingress *networkv1beta1.Ingress,
sourceNamespace string,
destinationNamespace string,
) (*networkv1beta1.Ingress, error) {
opLog := r.Log.WithValues("ingressmigrate", dioscuri.ObjectMeta.Namespace)
oldIngress := &networkv1beta1.Ingress{}
newIngress := &networkv1beta1.Ingress{}
Expand Down Expand Up @@ -534,17 +562,21 @@ func (r *IngressMigrateReconciler) individualIngressMigration(ctx context.Contex
}

// add ingress, and then remove the old one only if we successfully create the new one
func (r *IngressMigrateReconciler) migrateIngress(ctx context.Context, dioscuri *dioscuriv1.IngressMigrate, newIngress *networkv1beta1.Ingress, oldIngress *networkv1beta1.Ingress) error {
// add ingress
func (r *IngressMigrateReconciler) migrateIngress(ctx context.Context,
dioscuri *dioscuriv1.IngressMigrate,
newIngress *networkv1beta1.Ingress,
oldIngress *networkv1beta1.Ingress,
) error {
opLog := r.Log.WithValues("ingressmigrate", dioscuri.ObjectMeta.Namespace)
if err := r.addIngressIfNotExist(ctx, dioscuri, newIngress); err != nil {
return fmt.Errorf("Unable to create ingress %s in %s: %v", newIngress.ObjectMeta.Name, newIngress.ObjectMeta.Namespace, err)
}
// delete old ingress from the old namespace
opLog.Info(fmt.Sprintf("Removing old ingress %s in namespace %s", oldIngress.ObjectMeta.Name, oldIngress.ObjectMeta.Namespace))
if err := r.removeIngress(ctx, oldIngress); err != nil {
return fmt.Errorf("Unable to remove old ingress %s in %s: %v", oldIngress.ObjectMeta.Name, oldIngress.ObjectMeta.Namespace, err)
}
// add ingress
if err := r.addIngressIfNotExist(ctx, dioscuri, newIngress); err != nil {
return fmt.Errorf("Unable to create ingress %s in %s: %v", newIngress.ObjectMeta.Name, newIngress.ObjectMeta.Namespace, err)
}
return nil
}

Expand Down Expand Up @@ -626,14 +658,28 @@ func (r *IngressMigrateReconciler) removeIngress(ctx context.Context, ingress *n
}

// update status
func (r *IngressMigrateReconciler) updateStatusCondition(ctx context.Context, dioscuri *dioscuriv1.IngressMigrate, condition dioscuriv1.IngressMigrateConditions, activeIngress []string, standbyIngress []string) error {
dioscuri.Spec.Ingress.ActiveIngress = strings.Join(activeIngress, ",")
dioscuri.Spec.Ingress.StandbyIngress = strings.Join(standbyIngress, ",")
func (r *IngressMigrateReconciler) updateStatusCondition(ctx context.Context,
dioscuri *dioscuriv1.IngressMigrate,
condition dioscuriv1.IngressMigrateConditions,
activeIngress []string,
standbyIngress []string,
) error {
// set the transition time
condition.LastTransitionTime = time.Now().Format(time.RFC3339)
condition.LastTransitionTime = time.Now().UTC().Format(time.RFC3339)
if !IngressContainsStatus(dioscuri.Status.Conditions, condition) {
dioscuri.Status.Conditions = append(dioscuri.Status.Conditions, condition)
if err := r.Update(ctx, dioscuri); err != nil {
mergePatch, _ := json.Marshal(map[string]interface{}{
"status": map[string]interface{}{
"conditions": dioscuri.Status.Conditions,
},
"spec": map[string]interface{}{
"ingress": map[string]string{
"activeIngress": strings.Join(activeIngress, ","),
"standbyIngress": strings.Join(standbyIngress, ","),
},
},
})
if err := r.Patch(ctx, dioscuri, client.ConstantPatch(types.MergePatchType, mergePatch)); err != nil {
return fmt.Errorf("Unable to update status condition: %v", err)
}
}
Expand Down
Loading

0 comments on commit 0742c13

Please sign in to comment.