Skip to content

Commit

Permalink
refactored to remove deps from kit
Browse files Browse the repository at this point in the history
  • Loading branch information
xadhatter committed Dec 26, 2023
1 parent a92a07c commit 240dd7d
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 106 deletions.
2 changes: 1 addition & 1 deletion api/kubernetes/v1alpha1/virtual_env_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ type Problem struct {
// +kubebuilder:validation:Required

// ObservedTime at which the problem was recorded.
ObservedTime api.UncomparableTime `json:"observedTime"`
ObservedTime metav1.Time `json:"observedTime"`

Message string `json:"message,omitempty"`
// Resources and attributes causing problem.
Expand Down
25 changes: 0 additions & 25 deletions api/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@ one at https://mozilla.org/MPL/2.0/.
// +kubebuilder:object:generate=true
package api

import (
"k8s.io/apimachinery/pkg/api/equality"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

type VirtualEnvData struct {
// +kubebuilder:validation:Schemaless
// +kubebuilder:validation:Type=object
Expand Down Expand Up @@ -70,23 +65,3 @@ type Adapter interface {
GetName() string
GetComponentType() ComponentType
}

// +kubebuilder:object:generate=false

// UncomparableTime is a Kubernetes v1.Time object that will also be equal to
// another UncomparableTime object when using equality.Semantic, even if the
// times are different.
type UncomparableTime metav1.Time

// DeepCopyInto creates a deep-copy of the UncomparableTime value. The
// underlying time.Time type is effectively immutable in the time API, so it is
// safe to copy-by-assign, despite the presence of (unexported) Pointer fields.
func (t *UncomparableTime) DeepCopyInto(out *UncomparableTime) {
*out = *t
}

func init() {
equality.Semantic.AddFunc(func(a, b UncomparableTime) bool {
return true
})
}
32 changes: 0 additions & 32 deletions api/types_test.go

This file was deleted.

3 changes: 2 additions & 1 deletion components/broker/engine/broker.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"github.com/xigxog/kubefox/core"
"github.com/xigxog/kubefox/k8s"
"github.com/xigxog/kubefox/logkf"
"github.com/xigxog/kubefox/matcher"
authv1 "k8s.io/api/authentication/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
ctrl "sigs.k8s.io/controller-runtime"
Expand Down Expand Up @@ -400,7 +401,7 @@ func (brk *broker) findTarget(ctx context.Context, evt *BrokerEvent) error {
}

var (
matcher *core.EventMatcher
matcher *matcher.EventMatcher
err error
)
if evt.HasContext() {
Expand Down
17 changes: 9 additions & 8 deletions components/broker/engine/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/xigxog/kubefox/core"
"github.com/xigxog/kubefox/k8s"
"github.com/xigxog/kubefox/logkf"
"github.com/xigxog/kubefox/matcher"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
Expand All @@ -29,8 +30,8 @@ type Store struct {
resCache ctrlcache.Cache
compCache cache.Cache[*api.ComponentDefinition]

depMatchers cache.Cache[*core.EventMatcher]
relMatcher *core.EventMatcher
depMatchers cache.Cache[*matcher.EventMatcher]
relMatcher *matcher.EventMatcher

ctx context.Context
cancel context.CancelFunc
Expand All @@ -44,7 +45,7 @@ func NewStore(namespace string) *Store {
ctx, cancel := context.WithCancel(context.Background())
return &Store{
namespace: namespace,
depMatchers: cache.New[*core.EventMatcher](time.Minute * 15),
depMatchers: cache.New[*matcher.EventMatcher](time.Minute * 15),
ctx: ctx,
cancel: cancel,
log: logkf.Global,
Expand Down Expand Up @@ -211,7 +212,7 @@ func (str *Store) Adapters(ctx context.Context) (map[string]api.Adapter, error)
return adapters, nil
}

func (str *Store) ReleaseMatcher(ctx context.Context) (*core.EventMatcher, error) {
func (str *Store) ReleaseMatcher(ctx context.Context) (*matcher.EventMatcher, error) {
str.mutex.RLock()
if str.relMatcher != nil {
str.mutex.RUnlock()
Expand All @@ -225,7 +226,7 @@ func (str *Store) ReleaseMatcher(ctx context.Context) (*core.EventMatcher, error
return str.relMatcher, nil
}

func (str *Store) DeploymentMatcher(ctx context.Context, evtCtx *core.EventContext) (*core.EventMatcher, error) {
func (str *Store) DeploymentMatcher(ctx context.Context, evtCtx *core.EventContext) (*matcher.EventMatcher, error) {
dep, err := str.AppDeployment(ctx, evtCtx)
if err != nil {
return nil, err
Expand All @@ -245,7 +246,7 @@ func (str *Store) DeploymentMatcher(ctx context.Context, evtCtx *core.EventConte
return nil, err
}

depM := core.NewEventMatcher()
depM := matcher.New()
if err := depM.AddRoutes(routes...); err != nil {
return nil, err
}
Expand Down Expand Up @@ -333,7 +334,7 @@ func (str *Store) buildComponentCache(ctx context.Context) (cache.Cache[*api.Com
return compCache, nil
}

func (str *Store) buildReleaseMatcher(ctx context.Context) (*core.EventMatcher, error) {
func (str *Store) buildReleaseMatcher(ctx context.Context) (*matcher.EventMatcher, error) {
ctx, cancel := context.WithTimeout(ctx, time.Minute)
defer cancel()

Expand All @@ -342,7 +343,7 @@ func (str *Store) buildReleaseMatcher(ctx context.Context) (*core.EventMatcher,
return nil, err
}

relM := core.NewEventMatcher()
relM := matcher.New()
for _, env := range envList.Items {
release := env.Status.ActiveRelease
if release == nil {
Expand Down
16 changes: 8 additions & 8 deletions components/operator/controller/virtual_env_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ func (r *VirtualEnvReconciler) updateProblems(ctx context.Context, now metav1.Ti
value := string(metav1.ConditionFalse)
rel.Problems = append(rel.Problems, v1alpha1.Problem{
Type: api.ProblemTypeAppDeploymentUnavailable,
ObservedTime: api.UncomparableTime(now),
ObservedTime: now,
Message: msg,
Causes: []v1alpha1.ProblemSource{
{
Expand All @@ -316,7 +316,7 @@ func (r *VirtualEnvReconciler) updateProblems(ctx context.Context, now metav1.Ti
value := fmt.Sprintf("%s, %s", metav1.ConditionFalse, api.ConditionReasonComponentDeploymentFailed)
rel.Problems = append(rel.Problems, v1alpha1.Problem{
Type: api.ProblemTypeAppDeploymentFailed,
ObservedTime: api.UncomparableTime(now),
ObservedTime: now,
Message: msg,
Causes: []v1alpha1.ProblemSource{
{
Expand All @@ -337,7 +337,7 @@ func (r *VirtualEnvReconciler) updateProblems(ctx context.Context, now metav1.Ti

rel.Problems = append(rel.Problems, v1alpha1.Problem{
Type: api.ProblemTypeAppDeploymentFailed,
ObservedTime: api.UncomparableTime(now),
ObservedTime: now,
Message: msg,
Causes: []v1alpha1.ProblemSource{
{
Expand All @@ -363,7 +363,7 @@ func (r *VirtualEnvReconciler) updateProblems(ctx context.Context, now metav1.Ti

rel.Problems = append(rel.Problems, v1alpha1.Problem{
Type: api.ProblemTypeAppDeploymentFailed,
ObservedTime: api.UncomparableTime(now),
ObservedTime: now,
Message: msg,
Causes: []v1alpha1.ProblemSource{
{
Expand All @@ -389,7 +389,7 @@ func (r *VirtualEnvReconciler) updateProblems(ctx context.Context, now metav1.Ti

rel.Problems = append(rel.Problems, v1alpha1.Problem{
Type: api.ProblemTypeVirtualEnvSnapshotFailed,
ObservedTime: api.UncomparableTime(now),
ObservedTime: now,
Message: msg,
Causes: []v1alpha1.ProblemSource{
{
Expand All @@ -410,7 +410,7 @@ func (r *VirtualEnvReconciler) updateProblems(ctx context.Context, now metav1.Ti

rel.Problems = append(rel.Problems, v1alpha1.Problem{
Type: api.ProblemTypeVirtualEnvSnapshotFailed,
ObservedTime: api.UncomparableTime(now),
ObservedTime: now,
Message: msg,
Causes: []v1alpha1.ProblemSource{
{
Expand Down Expand Up @@ -438,7 +438,7 @@ func (r *VirtualEnvReconciler) updateProblems(ctx context.Context, now metav1.Ti
value := string(policy.VirtualEnvPolicy)
rel.Problems = append(rel.Problems, v1alpha1.Problem{
Type: api.ProblemTypePolicyViolation,
ObservedTime: api.UncomparableTime(now),
ObservedTime: now,
Message: msg,
Causes: []v1alpha1.ProblemSource{
{
Expand All @@ -462,7 +462,7 @@ func (r *VirtualEnvReconciler) updateProblems(ctx context.Context, now metav1.Ti
value := string(policy.AppDeploymentPolicy)
rel.Problems = append(rel.Problems, v1alpha1.Problem{
Type: api.ProblemTypePolicyViolation,
ObservedTime: api.UncomparableTime(now),
ObservedTime: now,
Message: msg,
Causes: []v1alpha1.ProblemSource{
{
Expand Down
6 changes: 1 addition & 5 deletions docs/reference/kubernetes-crds.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ Platform is the Schema for the Platforms API





### VirtualEnv

Expand Down Expand Up @@ -641,7 +640,7 @@ Used by:<br>
| Field | Type | Description | Validation |
| ----- | ---- | ----------- | ---------- |
| `type` | <div style="white-space:nowrap">enum[`AppDeploymentFailed`, `AppDeploymentUnavailable`, `ParseError`, `PolicyViolation`, `RouteConflict`, `SecretNotFound`, `VarNotFound`, `VarWrongType`, `VirtualEnvSnapshotFailed`]<div> | <div style="max-width:30rem"></div> | <div style="white-space:nowrap">required</div> |
| `observedTime` | <div style="white-space:nowrap">[UncomparableTime](#uncomparabletime)<div> | <div style="max-width:30rem">ObservedTime at which the problem was recorded.</div> | <div style="white-space:nowrap">required</div> |
| `observedTime` | <div style="white-space:nowrap">[Time](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.28/#time-v1-meta)<div> | <div style="max-width:30rem">ObservedTime at which the problem was recorded.</div> | <div style="white-space:nowrap">required</div> |
| `message` | <div style="white-space:nowrap">string<div> | <div style="max-width:30rem"></div> | <div style="white-space:nowrap"></div> |
| `causes` | <div style="white-space:nowrap">[ProblemSource](#problemsource) array<div> | <div style="max-width:30rem">Resources and attributes causing problem.</div> | <div style="white-space:nowrap"></div> |

Expand Down Expand Up @@ -805,9 +804,6 @@ Used by:<br>






### Val


Expand Down
Loading

0 comments on commit 240dd7d

Please sign in to comment.