-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SECURESIGN-1529] Keep url status up-to-date
- Loading branch information
Showing
16 changed files
with
262 additions
and
101 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package actions | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/securesign/operator/internal/controller/common/action" | ||
"github.com/securesign/operator/internal/controller/constants" | ||
v12 "k8s.io/api/networking/v1" | ||
"k8s.io/apimachinery/pkg/api/meta" | ||
"k8s.io/apimachinery/pkg/types" | ||
|
||
rhtasv1alpha1 "github.com/securesign/operator/api/v1alpha1" | ||
) | ||
|
||
func NewStatusUrlAction() action.Action[*rhtasv1alpha1.Fulcio] { | ||
return &statusUrlAction{} | ||
} | ||
|
||
type statusUrlAction struct { | ||
action.BaseAction | ||
} | ||
|
||
func (i statusUrlAction) Name() string { | ||
return "status-url" | ||
} | ||
|
||
func (i statusUrlAction) CanHandle(_ context.Context, instance *rhtasv1alpha1.Fulcio) bool { | ||
c := meta.FindStatusCondition(instance.Status.Conditions, constants.Ready) | ||
return c.Reason == constants.Creating || c.Reason == constants.Ready | ||
} | ||
|
||
func (i statusUrlAction) Handle(ctx context.Context, instance *rhtasv1alpha1.Fulcio) *action.Result { | ||
var url string | ||
if instance.Spec.ExternalAccess.Enabled { | ||
protocol := "http://" | ||
ingress := &v12.Ingress{} | ||
err := i.Client.Get(ctx, types.NamespacedName{Name: DeploymentName, Namespace: instance.Namespace}, ingress) | ||
if err != nil { | ||
return i.Failed(err) | ||
} | ||
if len(ingress.Spec.TLS) > 0 { | ||
protocol = "https://" | ||
} | ||
url = protocol + ingress.Spec.Rules[0].Host | ||
} else { | ||
url = fmt.Sprintf("http://%s.%s.svc", DeploymentName, instance.Namespace) | ||
} | ||
|
||
if url == instance.Status.Url { | ||
return i.Continue() | ||
} | ||
|
||
instance.Status.Url = url | ||
return i.StatusUpdate(ctx, instance) | ||
} |
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,50 @@ | ||
package ui | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/securesign/operator/internal/controller/common/action" | ||
"github.com/securesign/operator/internal/controller/common/utils" | ||
"github.com/securesign/operator/internal/controller/rekor/actions" | ||
v12 "k8s.io/api/networking/v1" | ||
"k8s.io/apimachinery/pkg/types" | ||
|
||
rhtasv1alpha1 "github.com/securesign/operator/api/v1alpha1" | ||
) | ||
|
||
func NewStatusURLAction() action.Action[*rhtasv1alpha1.Rekor] { | ||
return &statusUrlAction{} | ||
} | ||
|
||
type statusUrlAction struct { | ||
action.BaseAction | ||
} | ||
|
||
func (i statusUrlAction) Name() string { | ||
return "status-url" | ||
} | ||
|
||
func (i statusUrlAction) CanHandle(ctx context.Context, instance *rhtasv1alpha1.Rekor) bool { | ||
return utils.IsEnabled(instance.Spec.RekorSearchUI.Enabled) | ||
} | ||
|
||
func (i statusUrlAction) Handle(ctx context.Context, instance *rhtasv1alpha1.Rekor) *action.Result { | ||
protocol := "http://" | ||
ingress := &v12.Ingress{} | ||
err := i.Client.Get(ctx, types.NamespacedName{Name: actions.SearchUiDeploymentName, Namespace: instance.Namespace}, ingress) | ||
if err != nil { | ||
// condition error | ||
return i.FailedWithStatusUpdate(ctx, err, instance) | ||
} | ||
if len(ingress.Spec.TLS) > 0 { | ||
protocol = "https://" | ||
} | ||
url := protocol + ingress.Spec.Rules[0].Host | ||
|
||
if url == instance.Status.RekorSearchUIUrl { | ||
return i.Continue() | ||
} | ||
|
||
instance.Status.RekorSearchUIUrl = url | ||
return i.StatusUpdate(ctx, instance) | ||
} |
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
Oops, something went wrong.