Skip to content

Commit

Permalink
removing duplicate conditiontype, updating api
Browse files Browse the repository at this point in the history
Signed-off-by: Feny Mehta <[email protected]>
  • Loading branch information
fbm3307 committed May 29, 2024
1 parent a1bc979 commit 3c5d4e2
Show file tree
Hide file tree
Showing 11 changed files with 25 additions and 25 deletions.
4 changes: 2 additions & 2 deletions controllers/toolchaincluster/healthchecker.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func (hc *HealthChecker) getClusterHealthStatus(ctx context.Context) *toolchainv
func clusterReadyCondition() toolchainv1alpha1.Condition {
currentTime := metav1.Now()
return toolchainv1alpha1.Condition{
Type: toolchainv1alpha1.ToolchainClusterReady,
Type: toolchainv1alpha1.ConditionReady,
Status: corev1.ConditionTrue,
Reason: toolchainv1alpha1.ToolchainClusterClusterReadyReason,
Message: healthzOk,
Expand All @@ -79,7 +79,7 @@ func clusterReadyCondition() toolchainv1alpha1.Condition {
func clusterNotReadyCondition() toolchainv1alpha1.Condition {
currentTime := metav1.Now()
return toolchainv1alpha1.Condition{
Type: toolchainv1alpha1.ToolchainClusterReady,
Type: toolchainv1alpha1.ConditionReady,
Status: corev1.ConditionFalse,
Reason: toolchainv1alpha1.ToolchainClusterClusterNotReadyReason,
Message: healthzNotOk,
Expand Down
4 changes: 2 additions & 2 deletions controllers/toolchaincluster/healthchecker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,14 +148,14 @@ ExpConditions:
}
func healthy() toolchainv1alpha1.Condition {
return toolchainv1alpha1.Condition{
Type: toolchainv1alpha1.ToolchainClusterReady,
Type: toolchainv1alpha1.ConditionReady,
Status: corev1.ConditionTrue,
Reason: "ClusterReady",
Message: "/healthz responded with ok",
}
}
func unhealthy() toolchainv1alpha1.Condition {
return toolchainv1alpha1.Condition{Type: toolchainv1alpha1.ToolchainClusterReady,
return toolchainv1alpha1.Condition{Type: toolchainv1alpha1.ConditionReady,
Status: corev1.ConditionFalse,
Reason: "ClusterNotReady",
Message: "/healthz responded without ok",
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,4 @@ require (
sigs.k8s.io/yaml v1.3.0 // indirect
)

replace github.com/codeready-toolchain/api => github.com/fbm3307/toolchainapi v0.0.0-20240527070911-f37a60567c8b
replace github.com/codeready-toolchain/api => github.com/fbm3307/toolchainapi v0.0.0-20240529064820-9bb19ad24c69
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,8 @@ github.com/exponent-io/jsonpath v0.0.0-20151013193312-d6023ce2651d/go.mod h1:ZZM
github.com/fatih/camelcase v1.0.0/go.mod h1:yN2Sb0lFhZJUdVvtELVWefmrXpuZESvPmqwoZc+/fpc=
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
github.com/fatih/set v0.2.1/go.mod h1:+RKtMCH+favT2+3YecHGxcc0b4KyVWA1QWWJUs4E0CI=
github.com/fbm3307/toolchainapi v0.0.0-20240527070911-f37a60567c8b h1:fF3V9dFDmZCzbV2rWkII7b/LJ9hj5yL2zR0vdaXzeK4=
github.com/fbm3307/toolchainapi v0.0.0-20240527070911-f37a60567c8b/go.mod h1:ie9p4LenCCS0LsnbWp6/xwpFDdCWYE0KWzUO6Sk1g0E=
github.com/fbm3307/toolchainapi v0.0.0-20240529064820-9bb19ad24c69 h1:WiMpRk3NnsEeCVzQzD2gzc2EFx15eWCrkdfmGeG2ltU=
github.com/fbm3307/toolchainapi v0.0.0-20240529064820-9bb19ad24c69/go.mod h1:ie9p4LenCCS0LsnbWp6/xwpFDdCWYE0KWzUO6Sk1g0E=
github.com/felixge/httpsnoop v1.0.1/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U=
github.com/form3tech-oss/jwt-go v3.2.2+incompatible/go.mod h1:pbq4aXjuKjdthFRnoDwaVPLA+WlJuPGy+QneDUgJi2k=
github.com/form3tech-oss/jwt-go v3.2.3+incompatible/go.mod h1:pbq4aXjuKjdthFRnoDwaVPLA+WlJuPGy+QneDUgJi2k=
Expand Down
4 changes: 2 additions & 2 deletions pkg/cluster/cache_whitebox_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -399,15 +399,15 @@ type clusterOption func(*CachedToolchainCluster)
// Ready an option to state the cluster as "ready"
var ready clusterOption = func(c *CachedToolchainCluster) {
c.ClusterStatus.Conditions = append(c.ClusterStatus.Conditions, toolchainv1alpha1.Condition{
Type: toolchainv1alpha1.ToolchainClusterReady,
Type: toolchainv1alpha1.ConditionReady,
Status: v1.ConditionTrue,
})
}

// clusterNotReady an option to state the cluster as "not ready"
var notReady clusterOption = func(c *CachedToolchainCluster) {
c.ClusterStatus.Conditions = append(c.ClusterStatus.Conditions, toolchainv1alpha1.Condition{
Type: toolchainv1alpha1.ToolchainClusterReady,
Type: toolchainv1alpha1.ConditionReady,
Status: v1.ConditionFalse,
})
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/cluster/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ func NewClusterConfig(cl client.Client, toolchainCluster *toolchainv1alpha1.Tool

func IsReady(clusterStatus *toolchainv1alpha1.ToolchainClusterStatus) bool {
for _, condition := range clusterStatus.Conditions {
if condition.Type == toolchainv1alpha1.ToolchainClusterReady {
if condition.Type == toolchainv1alpha1.ConditionReady {
if condition.Status == v1.ConditionTrue {
return true
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/cluster/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func TestDeleteToolchainClusterWhenDoesNotExist(t *testing.T) {

func TestListToolchainClusterConfigs(t *testing.T) {
// given
status := test.NewClusterStatus(toolchainv1alpha1.ToolchainClusterReady, corev1.ConditionTrue)
status := test.NewClusterStatus(toolchainv1alpha1.ConditionReady, corev1.ConditionTrue)
require.NoError(t, toolchainv1alpha1.AddToScheme(scheme.Scheme))

m1, sec1 := test.NewToolchainClusterWithEndpoint("east", test.HostOperatorNs, "secret1", "http://m1.com", status, map[string]string{"ownerClusterName": "m1ClusterName", "namespace": test.MemberOperatorNs, cluster.RoleLabel(cluster.Tenant): ""})
Expand Down
4 changes: 2 additions & 2 deletions pkg/cluster/service_whitebox_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
func TestRefreshCacheInService(t *testing.T) {
// given
defer gock.Off()
status := test.NewClusterStatus(toolchainv1alpha1.ToolchainClusterReady, corev1.ConditionTrue)
status := test.NewClusterStatus(toolchainv1alpha1.ConditionReady, corev1.ConditionTrue)
toolchainCluster, sec := test.NewToolchainCluster("east", test.HostOperatorNs, "secret", status, map[string]string{"ownerClusterName": test.NameMember, "namespace": test.MemberOperatorNs})
s := scheme.Scheme
err := toolchainv1alpha1.AddToScheme(s)
Expand Down Expand Up @@ -74,7 +74,7 @@ func TestRefreshCacheInService(t *testing.T) {
func TestUpdateClientBasedOnRestConfig(t *testing.T) {
// given
defer gock.Off()
statusTrue := test.NewClusterStatus(toolchainv1alpha1.ToolchainClusterReady, corev1.ConditionTrue)
statusTrue := test.NewClusterStatus(toolchainv1alpha1.ConditionReady, corev1.ConditionTrue)
toolchainCluster1, sec1 := test.NewToolchainCluster("east", test.HostOperatorNs, "secret1", statusTrue,
map[string]string{"namespace": test.HostOperatorNs})

Expand Down
2 changes: 1 addition & 1 deletion pkg/status/toolchaincluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func GetToolchainClusterConditions(logger logr.Logger, attrs ToolchainClusterAtt
var lastUpdatedTime metav1.Time
foundLastProbeTime := false
for _, condition := range toolchainCluster.ClusterStatus.Conditions {
if condition.Type == toolchainv1alpha1.ToolchainClusterReady {
if condition.Type == toolchainv1alpha1.ConditionReady {
lastUpdatedTime = *condition.LastUpdatedTime
foundLastProbeTime = true
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/status/toolchaincluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,23 +176,23 @@ func TestGetToolchainClusterConditions(t *testing.T) {
}

func newGetHostClusterReady() cluster.GetHostClusterFunc {
return NewFakeGetHostCluster(true, toolchainv1alpha1.ToolchainClusterReady, corev1.ConditionTrue, fakeToolchainClusterReason, "", &updatetime)
return NewFakeGetHostCluster(true, toolchainv1alpha1.ConditionReady, corev1.ConditionTrue, fakeToolchainClusterReason, "", &updatetime)
}

func newGetHostClusterNotOk() cluster.GetHostClusterFunc {
return NewFakeGetHostCluster(false, toolchainv1alpha1.ToolchainClusterReady, corev1.ConditionFalse, fakeToolchainClusterReason, fakeToolchainClusterMsg, &updatetime)
return NewFakeGetHostCluster(false, toolchainv1alpha1.ConditionReady, corev1.ConditionFalse, fakeToolchainClusterReason, fakeToolchainClusterMsg, &updatetime)
}

func newGetHostClusterOkButNotReady(message string) cluster.GetHostClusterFunc {
return NewFakeGetHostCluster(true, toolchainv1alpha1.ToolchainClusterReady, corev1.ConditionFalse, fakeToolchainClusterReason, message, &updatetime)
return NewFakeGetHostCluster(true, toolchainv1alpha1.ConditionReady, corev1.ConditionFalse, fakeToolchainClusterReason, message, &updatetime)
}

func newGetHostClusterOkWithClusterOfflineCondition() cluster.GetHostClusterFunc {
return NewFakeGetHostCluster(true, toolchainv1alpha1.ToolchainClusterOffline, corev1.ConditionFalse, fakeToolchainClusterReason, fakeToolchainClusterMsg, &updatetime)
}

func newGetHostClusterLastProbeTimeExceeded() cluster.GetHostClusterFunc {
return NewFakeGetHostCluster(true, toolchainv1alpha1.ToolchainClusterReady, corev1.ConditionTrue, fakeToolchainClusterReason, fakeToolchainClusterMsg, &updatetime1)
return NewFakeGetHostCluster(true, toolchainv1alpha1.ConditionReady, corev1.ConditionTrue, fakeToolchainClusterReason, fakeToolchainClusterMsg, &updatetime1)
}

// NewGetHostCluster returns cluster.GetHostClusterFunc function. The cluster.CachedToolchainCluster
Expand Down
14 changes: 7 additions & 7 deletions pkg/test/verify/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type FunctionToVerify func(toolchainCluster *toolchainv1alpha1.ToolchainCluster,
func AddToolchainClusterAsMember(t *testing.T, functionToVerify FunctionToVerify) {
// given
defer gock.Off()
status := test.NewClusterStatus(toolchainv1alpha1.ToolchainClusterReady, corev1.ConditionTrue)
status := test.NewClusterStatus(toolchainv1alpha1.ConditionReady, corev1.ConditionTrue)

t.Run("add member ToolchainCluster with namespace label set", func(t *testing.T) {
for _, withCA := range []bool{true, false} {
Expand Down Expand Up @@ -77,7 +77,7 @@ func AddToolchainClusterAsMember(t *testing.T, functionToVerify FunctionToVerify
func AddToolchainClusterAsHost(t *testing.T, functionToVerify FunctionToVerify) {
// given
defer gock.Off()
status := test.NewClusterStatus(toolchainv1alpha1.ToolchainClusterReady, corev1.ConditionFalse)
status := test.NewClusterStatus(toolchainv1alpha1.ConditionReady, corev1.ConditionFalse)
t.Run("add host ToolchainCluster with namespace label set", func(t *testing.T) {
for _, withCA := range []bool{true, false} {
toolchainCluster, sec := test.NewToolchainCluster("east", test.MemberOperatorNs, "secret", status, Labels("host-ns", test.NameMember))
Expand Down Expand Up @@ -134,7 +134,7 @@ func AddToolchainClusterAsHost(t *testing.T, functionToVerify FunctionToVerify)
func AddToolchainClusterFailsBecauseOfMissingSecret(t *testing.T, functionToVerify FunctionToVerify) {
// given
defer gock.Off()
status := test.NewClusterStatus(toolchainv1alpha1.ToolchainClusterReady, corev1.ConditionTrue)
status := test.NewClusterStatus(toolchainv1alpha1.ConditionReady, corev1.ConditionTrue)
toolchainCluster, _ := test.NewToolchainCluster("east", test.MemberOperatorNs, "secret", status, Labels("", test.NameHost))
cl := test.NewFakeClient(t, toolchainCluster)
service := newToolchainClusterService(t, cl, false)
Expand All @@ -152,7 +152,7 @@ func AddToolchainClusterFailsBecauseOfMissingSecret(t *testing.T, functionToVeri
func AddToolchainClusterFailsBecauseOfEmptySecret(t *testing.T, functionToVerify FunctionToVerify) {
// given
defer gock.Off()
status := test.NewClusterStatus(toolchainv1alpha1.ToolchainClusterReady, corev1.ConditionTrue)
status := test.NewClusterStatus(toolchainv1alpha1.ConditionReady, corev1.ConditionTrue)
toolchainCluster, _ := test.NewToolchainCluster("east", test.MemberOperatorNs, "secret", status,
Labels(test.MemberOperatorNs, test.NameHost))
secret := &corev1.Secret{
Expand All @@ -176,10 +176,10 @@ func AddToolchainClusterFailsBecauseOfEmptySecret(t *testing.T, functionToVerify
func UpdateToolchainCluster(t *testing.T, functionToVerify FunctionToVerify) {
// given
defer gock.Off()
statusTrue := test.NewClusterStatus(toolchainv1alpha1.ToolchainClusterReady, corev1.ConditionTrue)
statusTrue := test.NewClusterStatus(toolchainv1alpha1.ConditionReady, corev1.ConditionTrue)
toolchainCluster1, sec1 := test.NewToolchainCluster("east", test.HostOperatorNs, "secret1", statusTrue,
Labels(test.HostOperatorNs, test.NameMember))
statusFalse := test.NewClusterStatus(toolchainv1alpha1.ToolchainClusterReady, corev1.ConditionFalse)
statusFalse := test.NewClusterStatus(toolchainv1alpha1.ConditionReady, corev1.ConditionFalse)
toolchainCluster2, sec2 := test.NewToolchainCluster("east", test.HostOperatorNs, "secret2", statusFalse,
Labels(test.HostOperatorNs, test.NameMember))
cl := test.NewFakeClient(t, toolchainCluster2, sec1, sec2)
Expand Down Expand Up @@ -207,7 +207,7 @@ func UpdateToolchainCluster(t *testing.T, functionToVerify FunctionToVerify) {
func DeleteToolchainCluster(t *testing.T, functionToVerify FunctionToVerify) {
// given
defer gock.Off()
status := test.NewClusterStatus(toolchainv1alpha1.ToolchainClusterReady, corev1.ConditionTrue)
status := test.NewClusterStatus(toolchainv1alpha1.ConditionReady, corev1.ConditionTrue)
toolchainCluster, sec := test.NewToolchainCluster("east", test.MemberOperatorNs, "sec", status,
Labels(test.MemberOperatorNs, test.NameHost))
cl := test.NewFakeClient(t, sec)
Expand Down

0 comments on commit 3c5d4e2

Please sign in to comment.