curl -LO https://github.com/operator-framework/operator-sdk/releases/download/v1.21.0/operator-sdk_darwin_amd64
chmod +x operator-sdk_darwin_amd64
sudo cp operator-sdk_darwin_amd64 /usr/local/go/bin/operator-sdk
or
brew install operator-sdk
- golang 1.17
- operator-sdk v1.21.0
mkdir podset-operator
cd podset-operator
operator-sdk init --domain pixiu.io --repo github.com/caoyingjunz/podset-operator
# Create a PodSet API with Group: pixiu, Version: v1beta1 and Kind: PodSet
operator-sdk create api --group pixiu --version v1alpha1 --kind PodSet --resource --controller
operator-sdk create webhook --group pixiu --version v1alpha1 --kind PodSet --defaulting --programmatic-validation
make manifests
// Reconcile is part of the main kubernetes reconciliation loop which aims to
// move the current state of the cluster closer to the desired state.
func (r *PodSetReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
log := r.Log.WithValues("request", req)
log.Info("reconciling operator")
podSet := &pixiuv1alpha1.PodSet{}
if err := r.Get(ctx, req.NamespacedName, podSet); err != nil {
if apierrors.IsNotFound(err) {
// Req object not found, Created objects are automatically garbage collected.
// For additional cleanup logic use finalizers.
// Return and don't requeue
return reconcile.Result{}, nil
} else {
log.Error(err, "error requesting pod set operator")
// Error reading the object - requeue the request.
return reconcile.Result{Requeue: true}, nil
}
}
...
docker build -f Dockerfile . -t jacky06/podset-operator:v0.0.1
docker push jacky06/podset-operator:v0.0.1
CRD 来自 podset-operator