This file contains 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 ( | |
"fmt" | |
"sync" | |
"time" | |
) | |
func main() { | |
fmt.Println("Starting program...") |
This file contains 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
$ kubectl create ns imgpullpolicy | |
$ kubectl apply -f pod_k8s_1_9.yaml -n imgpullpolicy | |
$ kubectl get po -n imgpullpolicy test-image-pull-policy -o jsonpath="{.spec.containers[0].imagePullPolicy}" | |
Always |
This file contains 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
apiVersion: v1 | |
kind: Pod | |
metadata: | |
name: test-image-pull-policy | |
spec: | |
containers: | |
- name: nginx | |
image: nginx:1.13 | |
imagePullPolicy: IfNotPresent |
This file contains 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
// get the Kubernetes client for connectivity | |
client := getKubernetesClient() | |
// create the informer so that we can not only list resources | |
// but also watch them for all pods in the default namespace | |
informer := cache.NewSharedIndexInformer( | |
// the ListWatch contains two different functions that our | |
// informer requires: ListFunc to take care of listing and watching | |
// the resources we want to handle | |
&cache.ListWatch{ |
This file contains 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
apiVersion: trstringer.com/v1 | |
kind: MyResource | |
metadata: | |
name: example-myresource | |
spec: | |
message: hello world | |
someValue: 13 |
This file contains 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
apiVersion: apiextensions.k8s.io/v1beta1 | |
kind: CustomResourceDefinition | |
metadata: | |
name: myresources.trstringer.com | |
spec: | |
group: trstringer.com | |
version: v1 | |
names: | |
kind: MyResource | |
plural: myresources |
This file contains 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 main() { | |
// get the Kubernetes client for connectivity | |
client, myresourceClient := getKubernetesClient() | |
// retrieve our custom resource informer which was generated from | |
// the code generator and pass it the custom resource client, specifying | |
// we should be looking through all namespaces for listing and watching | |
informer := myresourceinformer_v1.NewMyResourceInformer( | |
myresourceClient, | |
meta_v1.NamespaceAll, |
This file contains 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
// retrieve the Kubernetes cluster client from outside of the cluster | |
func getKubernetesClient() (kubernetes.Interface, myresourceclientset.Interface) { | |
// construct the path to resolve to `~/.kube/config` | |
kubeConfigPath := os.Getenv("HOME") + "/.kube/config" | |
// create the config from the path | |
config, err := clientcmd.BuildConfigFromFlags("", kubeConfigPath) | |
if err != nil { | |
log.Fatalf("getClusterConfig: %v", err) | |
} |
This file contains 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 v1 | |
import ( | |
meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1" | |
"k8s.io/apimachinery/pkg/runtime" | |
"k8s.io/apimachinery/pkg/runtime/schema" | |
"github.com/trstringer/k8s-controller-core-resource/pkg/apis/myresource" | |
) |
This file contains 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
// +k8s:deepcopy-gen=package | |
// +groupName=trstringer.com | |
package v1 |