Skip to content

Instantly share code, notes, and snippets.

View gallettilance's full-sized avatar

Lance Galletti gallettilance

View GitHub Profile
# Requires
# OPM
# podman or docker, skopeo
import os
import re
import time
import json
import random
import sqlite3
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
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
}
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{}
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"
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
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{}
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')
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")
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")