-
Notifications
You must be signed in to change notification settings - Fork 150
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: rewrite activestandby task to remove external dioscuri requ…
…irement (#3592)
- Loading branch information
1 parent
8e7272e
commit 8228981
Showing
40 changed files
with
2,296 additions
and
274 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
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
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
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
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
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
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 |
---|---|---|
@@ -1,3 +1,11 @@ | ||
# tasks-activestandby | ||
|
||
This image is used by the activestandby task when using the Lagoon Kubernetes Controllers | ||
This image is used by the activestandby task. The remote-controller has knowledge of this task and will create a role binding between the two namespaces to allow them to temporarily talk and create/edit/delete resources between them as part of the task process. | ||
|
||
The resulting payload contains information about the actions that were performed, which are sent back to Lagoon via the message queue to be reflected in the API. | ||
|
||
The basic idea is that when activestandby is triggered, it collects the ingress in both namespaces that match the labels `dioscuri.amazee.io/migrate=true` and `activestandby.lagoon.sh/migrate=true` and will then perform the action of storing information about them, removing them from the source namespace, and then creating them in the destination namespace. | ||
|
||
Part of this process also involves copying secrets and certificates if they are present, so that they are also available in the destination namespace. | ||
|
||
When the process of migrating is taking place, all ingress have a new label added which is `activestandby.lagoon.sh/migrating=true`, which at the end of the migration process is set to `false`. This label will only be true while migrations are taking place. This allows external systems to be aware of the migration if they need to take any action, or prevent some actions from taking place. |
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,43 @@ | ||
package dioscuri | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
certv1 "github.com/cert-manager/cert-manager/pkg/apis/certmanager/v1" | ||
networkv1 "k8s.io/api/networking/v1" | ||
"k8s.io/apimachinery/pkg/types" | ||
client "sigs.k8s.io/controller-runtime/pkg/client" | ||
) | ||
|
||
// copy any certificate into a slice of certificates | ||
func copyCertificates(ctx context.Context, c client.Client, ingress *networkv1.Ingress) []*certv1.Certificate { | ||
var certificates []*certv1.Certificate | ||
for _, tls := range ingress.Spec.TLS { | ||
certificate := &certv1.Certificate{} | ||
err := c.Get(ctx, types.NamespacedName{Namespace: ingress.ObjectMeta.Namespace, Name: tls.SecretName}, certificate) | ||
if err != nil { | ||
break | ||
} | ||
certificates = append(certificates, certificate) | ||
fmt.Println(fmt.Sprintf(">> Copying certificate %s in namespace %s", certificate.ObjectMeta.Name, certificate.ObjectMeta.Namespace)) | ||
} | ||
return certificates | ||
} | ||
|
||
// create any certificates in the destination namespace | ||
func createCertificates(ctx context.Context, c client.Client, destinationNamespace string, certificates []*certv1.Certificate) error { | ||
for _, certificate := range certificates { | ||
certificate.ObjectMeta.Namespace = destinationNamespace | ||
certificate.ResourceVersion = "" | ||
certificate.SelfLink = "" | ||
certificate.UID = "" | ||
err := c.Create(ctx, certificate) | ||
if err != nil { | ||
break | ||
} | ||
// secrets = append(secrets, certificate) | ||
fmt.Println(fmt.Sprintf(">> Creating certificate %s in namespace %s", certificate.ObjectMeta.Name, certificate.ObjectMeta.Namespace)) | ||
} | ||
return nil | ||
} |
Oops, something went wrong.