-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #148 from uselagoon/support-activestandby
- Loading branch information
Showing
6 changed files
with
148 additions
and
89 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package v1beta1 | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/uselagoon/remote-controller/internal/helpers" | ||
rbacv1 "k8s.io/api/rbac/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/apimachinery/pkg/types" | ||
) | ||
|
||
// createActiveStandbyRole will create the rolebinding for allowing lagoon-deployer to talk between namespaces for active/standby functionality | ||
func (r *LagoonTaskReconciler) createActiveStandbyRole(ctx context.Context, sourceNamespace, destinationNamespace string) error { | ||
activeStandbyRoleBinding := &rbacv1.RoleBinding{} | ||
activeStandbyRoleBinding.ObjectMeta = metav1.ObjectMeta{ | ||
Name: "lagoon-deployer-activestandby", | ||
Namespace: destinationNamespace, | ||
} | ||
activeStandbyRoleBinding.RoleRef = rbacv1.RoleRef{ | ||
Name: "admin", | ||
Kind: "ClusterRole", | ||
APIGroup: "rbac.authorization.k8s.io", | ||
} | ||
activeStandbyRoleBinding.Subjects = []rbacv1.Subject{ | ||
{ | ||
Name: "lagoon-deployer", | ||
Kind: "ServiceAccount", | ||
Namespace: sourceNamespace, | ||
}, | ||
} | ||
err := r.Get(ctx, types.NamespacedName{ | ||
Namespace: destinationNamespace, | ||
Name: "lagoon-deployer-activestandby", | ||
}, activeStandbyRoleBinding) | ||
if err != nil { | ||
if err := r.Create(ctx, activeStandbyRoleBinding); err != nil { | ||
return fmt.Errorf("There was an error creating the lagoon-deployer-activestandby role binding. Error was: %v", err) | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
// deleteActiveStandbyRole | ||
func (r *LagoonMonitorReconciler) deleteActiveStandbyRole(ctx context.Context, destinationNamespace string) error { | ||
activeStandbyRoleBinding := &rbacv1.RoleBinding{} | ||
err := r.Get(ctx, types.NamespacedName{ | ||
Namespace: destinationNamespace, | ||
Name: "lagoon-deployer-activestandby", | ||
}, activeStandbyRoleBinding) | ||
if err != nil { | ||
helpers.IgnoreNotFound(err) | ||
} | ||
err = r.Delete(ctx, activeStandbyRoleBinding) | ||
if err != nil { | ||
return fmt.Errorf("Unable to delete lagoon-deployer-activestandby role binding") | ||
} | ||
return nil | ||
} |
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