Skip to content

Commit 504e350

Browse files
britaniarRyan Zhang
authored andcommitted
feat: add svc export trackability (Azure#1061)
1 parent bbacaf3 commit 504e350

File tree

5 files changed

+363
-3
lines changed

5 files changed

+363
-3
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ require (
1919
github.com/spf13/pflag v1.0.5
2020
github.com/stretchr/testify v1.10.0
2121
github.com/wI2L/jsondiff v0.6.0
22-
go.goms.io/fleet-networking v0.3.3
22+
go.goms.io/fleet-networking v0.3.5
2323
go.uber.org/atomic v1.11.0
2424
go.uber.org/zap v1.27.0
2525
golang.org/x/exp v0.0.0-20241004190924-225e2abe05e6

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,8 +253,8 @@ github.com/x448/float16 v0.8.4/go.mod h1:14CWIYCyZA/cWjXOioeEpHeN/83MdbZDRQHoFcY
253253
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
254254
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
255255
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
256-
go.goms.io/fleet-networking v0.3.3 h1:5rwBntaUoLF+E1CzaWAEL4GdvLJPQorKhjgkbLlllPE=
257-
go.goms.io/fleet-networking v0.3.3/go.mod h1:Qgbi8M1fGaz/p5rtb6HJPmTDATWRnMt9HD1gz57WKUc=
256+
go.goms.io/fleet-networking v0.3.5 h1:nR0LFEbpu9cfBwYFVV8cGB8OARemIwtzaaFpRpp1GtQ=
257+
go.goms.io/fleet-networking v0.3.5/go.mod h1:zegH1iEZScjUWiGnXL67D/ZfWTM9DBUaSo1gPWaxLek=
258258
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.53.0 h1:4K4tsIXefpVJtvA/8srF4V4y0akAoPHkIslgAkjixJA=
259259
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.53.0/go.mod h1:jjdQuTGVsXV4vSs+CJ2qYDeDPf9yIJV23qlIzBm73Vg=
260260
go.opentelemetry.io/otel v1.31.0 h1:NsJcKPIW0D0H3NgzPDHmo0WW6SptzPdqg/L1zsIm2hY=

pkg/controllers/workapplier/availability_tracker.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,18 @@ import (
2525
policyv1 "k8s.io/api/policy/v1"
2626
apiextensionshelpers "k8s.io/apiextensions-apiserver/pkg/apihelpers"
2727
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
28+
"k8s.io/apimachinery/pkg/api/meta"
2829
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
2930
"k8s.io/apimachinery/pkg/runtime"
3031
"k8s.io/apimachinery/pkg/runtime/schema"
3132
"k8s.io/component-helpers/apps/poddisruptionbudget"
3233
"k8s.io/klog/v2"
3334

35+
fleetnetworkingv1alpha1 "go.goms.io/fleet-networking/api/v1alpha1"
36+
"go.goms.io/fleet-networking/pkg/common/objectmeta"
37+
3438
"go.goms.io/fleet/pkg/utils"
39+
"go.goms.io/fleet/pkg/utils/condition"
3540
"go.goms.io/fleet/pkg/utils/controller"
3641
)
3742

@@ -104,6 +109,8 @@ func trackInMemberClusterObjAvailabilityByGVR(
104109
return trackCRDAvailability(inMemberClusterObj)
105110
case utils.PodDisruptionBudgetGVR:
106111
return trackPDBAvailability(inMemberClusterObj)
112+
case utils.ServiceExportGVR:
113+
return trackServiceExportAvailability(inMemberClusterObj)
107114
default:
108115
if isDataResource(*gvr) {
109116
klog.V(2).InfoS("The object from the member cluster is a data object, consider it to be immediately available",
@@ -268,6 +275,44 @@ func trackPDBAvailability(curObj *unstructured.Unstructured) (ManifestProcessing
268275
return ManifestProcessingAvailabilityResultTypeNotYetAvailable, nil
269276
}
270277

278+
// trackServiceExportAvailability tracks the availability of a service export in the member cluster.
279+
// It is available if the ServiceExportValid condition is true (will be false if annotation value is invalid).
280+
// If the weight is not 0, ServiceExportValid condition must be true and the ServiceExportConflict condition must be false.
281+
func trackServiceExportAvailability(curObj *unstructured.Unstructured) (ManifestProcessingAvailabilityResultType, error) {
282+
var svcExport fleetnetworkingv1alpha1.ServiceExport
283+
if err := runtime.DefaultUnstructuredConverter.FromUnstructured(curObj.Object, &svcExport); err != nil {
284+
return ManifestProcessingAvailabilityResultTypeFailed, controller.NewUnexpectedBehaviorError(err)
285+
}
286+
287+
// Check if ServiceExport is valid and up to date
288+
svcExportObj := klog.KObj(curObj)
289+
validCond := meta.FindStatusCondition(svcExport.Status.Conditions, string(fleetnetworkingv1alpha1.ServiceExportValid))
290+
if !condition.IsConditionStatusTrue(validCond, svcExport.Generation) {
291+
klog.V(2).InfoS("Still need to wait for ServiceExport to be valid", "serviceExport", svcExportObj, "validCondition", validCond)
292+
return ManifestProcessingAvailabilityResultTypeNotYetAvailable, nil
293+
}
294+
// Validate annotation weight. Updating the annotation won't change the object generation,
295+
// so the current status is not reliable and need to validate the annotation again here
296+
weight, err := objectmeta.ExtractWeightFromServiceExport(&svcExport)
297+
if err != nil {
298+
klog.Errorf(err.Error(), "ServiceExport has invalid weight", "serviceExport", svcExportObj)
299+
return ManifestProcessingAvailabilityResultTypeNotYetAvailable, err
300+
}
301+
if weight != 0 {
302+
// Check conflict condition for non-zero weight
303+
conflictCond := meta.FindStatusCondition(svcExport.Status.Conditions, string(fleetnetworkingv1alpha1.ServiceExportConflict))
304+
if !condition.IsConditionStatusFalse(conflictCond, svcExport.Generation) {
305+
klog.V(2).InfoS("Still need to wait for ServiceExport to not have conflicts", "serviceExport", svcExportObj, "conflictCondition", conflictCond)
306+
return ManifestProcessingAvailabilityResultTypeNotYetAvailable, nil
307+
}
308+
} else {
309+
klog.V(2).InfoS("Skipping checking the conflict condition for the weight 0", "serviceExport", svcExportObj)
310+
}
311+
312+
klog.V(2).InfoS("ServiceExport is available", "serviceExport", svcExportObj)
313+
return ManifestProcessingAvailabilityResultTypeAvailable, nil
314+
}
315+
271316
// isDataResource checks if the resource is a data resource; such resources are
272317
// available immediately after creation.
273318
func isDataResource(gvr schema.GroupVersionResource) bool {

0 commit comments

Comments
 (0)