-
Notifications
You must be signed in to change notification settings - Fork 408
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: improve readiness probe for yurthub component (#2284)
1. yurthub becomes ready after certificate, yurt-hub-cfg configmap, and resource for filters is synced. 2. improve multiplexer storage to lazy cache, this means multiplexer manager starts to list/watch pool scope metadata only when corresponding requests are received. 3. pool scope metadata requests will be rejected before multiplexer storage cache is ready. Signed-off-by: rambohe-ch <[email protected]>
- Loading branch information
1 parent
21473cf
commit 175c309
Showing
34 changed files
with
1,116 additions
and
693 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
Copyright 2025 The OpenYurt Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package options | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
|
||
"k8s.io/apimachinery/pkg/runtime/schema" | ||
) | ||
|
||
type PoolScopeMetadatas []schema.GroupVersionResource | ||
|
||
// String returns the string representation of the GVR slice. | ||
func (psm *PoolScopeMetadatas) String() string { | ||
var result strings.Builder | ||
for i, gvr := range *psm { | ||
if i > 0 { | ||
result.WriteString(",") | ||
} | ||
|
||
result.WriteString(gvr.Group) | ||
result.WriteString("/") | ||
result.WriteString(gvr.Version) | ||
result.WriteString("/") | ||
result.WriteString(gvr.Resource) | ||
} | ||
|
||
return result.String() | ||
} | ||
|
||
// Set parses the input string and updates the PoolScopeMetadata slice. | ||
func (psm *PoolScopeMetadatas) Set(value string) error { | ||
parts := strings.Split(value, ",") | ||
for _, part := range parts { | ||
subParts := strings.Split(part, "/") | ||
if len(subParts) != 3 { | ||
return fmt.Errorf("invalid GVR format: %s, expected format is Group/Version/Resource", part) | ||
} | ||
|
||
*psm = append(*psm, schema.GroupVersionResource{ | ||
Group: strings.TrimSpace(subParts[0]), | ||
Version: strings.TrimSpace(subParts[1]), | ||
Resource: strings.TrimSpace(subParts[2]), | ||
}) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// Type returns the type of the flag as a string. | ||
func (psm *PoolScopeMetadatas) Type() string { | ||
return "PoolScopeMetadatas" | ||
} |
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,118 @@ | ||
/* | ||
Copyright 2025 The OpenYurt Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package options | ||
|
||
import ( | ||
"testing" | ||
|
||
"k8s.io/apimachinery/pkg/runtime/schema" | ||
) | ||
|
||
func TestSet(t *testing.T) { | ||
testcases := map[string]struct { | ||
input string | ||
expected []schema.GroupVersionResource | ||
expectErr bool | ||
}{ | ||
"single pool scope metadata": { | ||
input: "group1/v1/resource1", | ||
expected: []schema.GroupVersionResource{ | ||
{Group: "group1", Version: "v1", Resource: "resource1"}, | ||
}, | ||
}, | ||
"multiple pool scope metadatas": { | ||
input: "group1/v1/resource1, group2/v2/resource2", | ||
expected: []schema.GroupVersionResource{ | ||
{Group: "group1", Version: "v1", Resource: "resource1"}, | ||
{Group: "group2", Version: "v2", Resource: "resource2"}, | ||
}, | ||
}, | ||
"multiple pool scope metadatas with empty group": { | ||
input: "/v1/resource1, /v2/resource2", | ||
expected: []schema.GroupVersionResource{ | ||
{Group: "", Version: "v1", Resource: "resource1"}, | ||
{Group: "", Version: "v2", Resource: "resource2"}, | ||
}, | ||
}, | ||
"invalid format of pool scope metadata": { | ||
input: "group1/v1", | ||
expectErr: true, | ||
}, | ||
"empty string of pool scope metadata": { | ||
input: "", | ||
expectErr: true, | ||
}, | ||
} | ||
|
||
for k, tc := range testcases { | ||
t.Run(k, func(t *testing.T) { | ||
var psm PoolScopeMetadatas | ||
err := psm.Set(tc.input) | ||
if (err != nil) != tc.expectErr { | ||
t.Errorf("expected error %v, but got %v", tc.expectErr, err != nil) | ||
} | ||
|
||
if !tc.expectErr && !comparePoolScopeMetadatas(psm, tc.expected) { | ||
t.Errorf("expected pool scope metadatas: %+v, but got %+v", tc.expected, psm) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func comparePoolScopeMetadatas(a, b []schema.GroupVersionResource) bool { | ||
if len(a) != len(b) { | ||
return false | ||
} | ||
|
||
for i := range a { | ||
if a[i] != b[i] { | ||
return false | ||
} | ||
} | ||
|
||
return true | ||
} | ||
|
||
func TestString(t *testing.T) { | ||
testcases := map[string]struct { | ||
psm PoolScopeMetadatas | ||
expectedStr string | ||
}{ | ||
"single pool scope metadata": { | ||
psm: PoolScopeMetadatas{ | ||
{Group: "group1", Version: "v1", Resource: "resource1"}, | ||
}, | ||
expectedStr: "group1/v1/resource1", | ||
}, | ||
"multiple pool scope metadatas": { | ||
psm: PoolScopeMetadatas{ | ||
{Group: "group1", Version: "v1", Resource: "resource1"}, | ||
{Group: "group2", Version: "v2", Resource: "resource2"}, | ||
}, | ||
|
||
expectedStr: "group1/v1/resource1,group2/v2/resource2", | ||
}, | ||
} | ||
|
||
for k, tc := range testcases { | ||
t.Run(k, func(t *testing.T) { | ||
if tc.psm.String() != tc.expectedStr { | ||
t.Errorf("expected string %s, but got %s", tc.expectedStr, tc.psm.String()) | ||
} | ||
}) | ||
} | ||
} |
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.