This file contains hidden or 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
| # Requires | |
| # OPM | |
| # podman or docker, skopeo | |
| import os | |
| import re | |
| import time | |
| import json | |
| import random | |
| import sqlite3 |
This file contains hidden or 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
| const myKindFinalizer = "grp.example.com/finalizer" | |
| // DeletionReconciler controls the reconciliation of deleted resources | |
| func (r *MykindReconciler) deletionReconciler(ctx context.Context, cr *grpv1alpha1.Mykind) (ctrl.Result, error) { | |
| // Finalizer logic here | |
| // More on finalizers: https://kubernetes.io/docs/tasks/extend-kubernetes/custom-resources/custom-resource-definitions/#finalizers | |
| if controllerutil.ContainsFinalizer(cr, myKindFinalizer) { | |
| // our finalizer is present, so lets handle any external dependency | |
| if err := r.doCleanup(cr); err != nil { | |
| // if fail to delete the external dependency here, return with error |
This file contains hidden or 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
| func (h *mykindHandler) manageSuccess(ctx context.Context, crInstance *grpv1alpha1.Mykind, reason string) (ctrl.Result, error) { | |
| crInstance.Status.LastUpdate = metav1.Now() | |
| crInstance.Status.Reason = reason | |
| crInstance.Status.Status = metav1.StatusSuccess | |
| updateErr := h.Status().Update(ctx, crInstance) | |
| if updateErr != nil { | |
| log.Info("Error when updating status. Requeued") | |
| return ctrl.Result{RequeueAfter: time.Second * 3}, updateErr | |
| } |
This file contains hidden or 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
| var log = ctrl.Log.WithName("controllers").WithName("mykind") | |
| type MykindReconciler struct { | |
| client.Client | |
| Scheme *runtime.Scheme | |
| } | |
| func (r *MykindReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) { | |
| log.WithValues(req.Name, req.Namespace) | |
| cr := &grpv1alpha1.Mykind{} |
This file contains hidden or 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
| package main | |
| import ( | |
| "os" | |
| _ "k8s.io/client-go/plugin/pkg/client/auth" | |
| "k8s.io/apimachinery/pkg/runtime" | |
| utilruntime "k8s.io/apimachinery/pkg/util/runtime" | |
| clientgoscheme "k8s.io/client-go/kubernetes/scheme" |
This file contains hidden or 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
| func (r *MykindReconciler) CreateOrUpdateReconciler(ctx context.Context, req ctrl.Request, crInstance *grpv1alpha1.Mykind) (ctrl.Result, error) { | |
| desiredNumPods := crInstance.Spec.NumPods | |
| actualNumPods := 0 | |
| if crInstance.Status.Pods == nil { | |
| crInstance.Status.Pods = make(map[string]string) | |
| } else { | |
| podList, err = h.getRunningPodsOwnedBy(ctx, crInstance) | |
| if err != nil { | |
| return ctrl.Result{}, err |
This file contains hidden or 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
| var log = ctrl.Log.WithName("controllers").WithName("mykind") | |
| type MykindReconciler struct { | |
| client.Client | |
| Scheme *runtime.Scheme | |
| } | |
| func (r *MykindReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) { | |
| log.WithValues(req.Name, req.Namespace) | |
| cr := &grpv1alpha1.Mykind{} |
This file contains hidden or 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
| import numpy as np | |
| from tensorflow import keras, norm | |
| RANK = 10 | |
| def custom_loss(y_true, y_pred): | |
| return norm(y_true - y_pred, ord='euclidean') | |
| boat = np.loadtxt('boat.dat') |
This file contains hidden or 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
| from tensorflow import keras | |
| model = keras.models.Sequential() | |
| model.add(keras.layers.Dense(4, input_dim=1, activation='relu')) | |
| model.add(keras.layers.Dense(1)) | |
| model.compile(loss="mean_squared_error") |
This file contains hidden or 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
| from tensorflow import keras | |
| def custom_act(x): | |
| return x**2 | |
| model = keras.models.Sequential() | |
| model.add(keras.layers.Dense(1, input_dim=1, use_bias=False, activation=custom_act)) | |
| model.add(keras.layers.Dense(1)) | |
| model.compile(loss="mean_squared_error") |
NewerOlder