Skip to content

Commit 70b4e38

Browse files
committed
Add operator CI
Signed-off-by: Zike Yang <[email protected]>
1 parent 5e23817 commit 70b4e38

File tree

8 files changed

+41
-11
lines changed

8 files changed

+41
-11
lines changed

.github/workflows/ci.yaml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
runs-on: ubuntu-latest
2828
strategy:
2929
matrix:
30-
go-version: [ '1.22' ]
30+
go-version: [ '1.24' ]
3131
steps:
3232
- uses: actions/checkout@v3
3333
- uses: actions/setup-go@v3
@@ -73,3 +73,17 @@ jobs:
7373
run: |
7474
make test
7575
76+
test-operator:
77+
runs-on: ubuntu-latest
78+
strategy:
79+
matrix:
80+
go-version: [ '1.24' ]
81+
steps:
82+
- uses: actions/checkout@v3
83+
- uses: actions/setup-go@v3
84+
with:
85+
go-version: ${{ matrix.go-version }}
86+
- name: Test Operator
87+
working-directory: operator
88+
run: |
89+
make test

operator/cmd/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ func main() {
242242
// nolint:goconst
243243
if os.Getenv("ENABLE_WEBHOOKS") != "false" {
244244
if err = webhookfsv1alpha1.SetupPackagesWebhookWithManager(mgr); err != nil {
245-
setupLog.Error(err, "unable to create webhook", "webhook", "Packages")
245+
setupLog.Error(err, "unable to create webhook", "webhook", "Package")
246246
os.Exit(1)
247247
}
248248
}

operator/config/crd/kustomization.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
# since it depends on service name and namespace that are out of this kustomize package.
33
# It should be run by config/default
44
resources:
5-
- ./bases/fs.functionstream.github.io_packages.yaml
65
- bases/fs.functionstream.github.io_functions.yaml
76
- bases/fs.functionstream.github.io_packages.yaml
87
# +kubebuilder:scaffold:crdkustomizeresource

operator/config/webhook/manifests.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ webhooks:
6767
operations:
6868
- CREATE
6969
- UPDATE
70+
- DELETE
7071
resources:
7172
- functions
7273
sideEffects: None
@@ -87,6 +88,7 @@ webhooks:
8788
operations:
8889
- CREATE
8990
- UPDATE
91+
- DELETE
9092
resources:
91-
- package
93+
- packages
9294
sideEffects: None

operator/internal/controller/function_controller.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ func (r *FunctionReconciler) Reconcile(ctx context.Context, req ctrl.Request) (c
169169
Containers: []corev1.Container{{
170170
Name: "function",
171171
Image: image,
172-
ImagePullPolicy: corev1.PullNever,
172+
ImagePullPolicy: corev1.PullIfNotPresent,
173173
VolumeMounts: []corev1.VolumeMount{{
174174
Name: "function-config",
175175
MountPath: "/function/config.yaml",
@@ -203,13 +203,13 @@ func (r *FunctionReconciler) Reconcile(ctx context.Context, req ctrl.Request) (c
203203
existingDeploy.Labels = deployment.Labels
204204
err = r.Update(ctx, &existingDeploy)
205205
if err != nil {
206-
return ctrl.Result{}, err
206+
return HandleReconcileError(log, err, "Conflict when updating Deployment, will retry automatically")
207207
}
208208
}
209209
} else if errors.IsNotFound(deployErr) {
210210
err = r.Create(ctx, deployment)
211211
if err != nil {
212-
return ctrl.Result{}, err
212+
return HandleReconcileError(log, err, "Conflict when creating Deployment, will retry automatically")
213213
}
214214
} else {
215215
return ctrl.Result{}, deployErr
@@ -219,8 +219,7 @@ func (r *FunctionReconciler) Reconcile(ctx context.Context, req ctrl.Request) (c
219219
if err := r.Get(ctx, types.NamespacedName{Name: deployName, Namespace: fn.Namespace}, &existingDeploy); err == nil {
220220
fn.Status = convertDeploymentStatusToFunctionStatus(&existingDeploy.Status)
221221
if err := r.Status().Update(ctx, &fn); err != nil {
222-
log.Error(err, "Failed to update Function status")
223-
return ctrl.Result{}, err
222+
return HandleReconcileError(log, err, "Conflict when updating Function status, will retry automatically")
224223
}
225224
}
226225

operator/internal/controller/util.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package controller
2+
3+
import (
4+
"github.com/go-logr/logr"
5+
"k8s.io/apimachinery/pkg/api/errors"
6+
ctrl "sigs.k8s.io/controller-runtime"
7+
)
8+
9+
// HandleReconcileError handles errors in reconcile loops, logging conflicts as info and returning nil error for them.
10+
func HandleReconcileError(log logr.Logger, err error, conflictMsg string) (ctrl.Result, error) {
11+
if errors.IsConflict(err) {
12+
log.V(1).Info(conflictMsg, "error", err)
13+
return ctrl.Result{}, nil
14+
}
15+
return ctrl.Result{}, err
16+
}

operator/internal/webhook/v1alpha1/function_webhook.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ func (d *FunctionCustomDefaulter) Default(ctx context.Context, obj runtime.Objec
8080
// TODO(user): change verbs to "verbs=create;update;delete" if you want to enable deletion validation.
8181
// NOTE: The 'path' attribute must follow a specific pattern and should not be modified directly here.
8282
// Modifying the path for an invalid path can cause API server errors; failing to locate the webhook.
83-
// +kubebuilder:webhook:path=/validate-fs-functionstream-github-io-v1alpha1-function,mutating=false,failurePolicy=fail,sideEffects=None,groups=fs.functionstream.github.io,resources=functions,verbs=create;update,versions=v1alpha1,name=vfunction-v1alpha1.kb.io,admissionReviewVersions=v1
83+
// +kubebuilder:webhook:path=/validate-fs-functionstream-github-io-v1alpha1-function,mutating=false,failurePolicy=fail,sideEffects=None,groups=fs.functionstream.github.io,resources=functions,verbs=create;update;delete,versions=v1alpha1,name=vfunction-v1alpha1.kb.io,admissionReviewVersions=v1
8484

8585
// FunctionCustomValidator struct is responsible for validating the Function resource
8686
// when it is created, updated, or deleted.

operator/internal/webhook/v1alpha1/packages_webhook.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ func (d *PackagesCustomDefaulter) Default(ctx context.Context, obj runtime.Objec
7474
// TODO(user): change verbs to "verbs=create;update;delete" if you want to enable deletion validation.
7575
// NOTE: The 'path' attribute must follow a specific pattern and should not be modified directly here.
7676
// Modifying the path for an invalid path can cause API server errors; failing to locate the webhook.
77-
// +kubebuilder:webhook:path=/validate-fs-functionstream-github-io-v1alpha1-package,mutating=false,failurePolicy=fail,sideEffects=None,groups=fs.functionstream.github.io,resources=package,verbs=create;update,versions=v1alpha1,name=vpackage-v1alpha1.kb.io,admissionReviewVersions=v1
77+
// +kubebuilder:webhook:path=/validate-fs-functionstream-github-io-v1alpha1-package,mutating=false,failurePolicy=fail,sideEffects=None,groups=fs.functionstream.github.io,resources=packages,verbs=create;update;delete,versions=v1alpha1,name=vpackage-v1alpha1.kb.io,admissionReviewVersions=v1
7878

7979
// PackagesCustomValidator struct is responsible for validating the Packages resource
8080
// when it is created, updated, or deleted.

0 commit comments

Comments
 (0)