mirror of
https://github.com/stakater/Reloader.git
synced 2026-08-27 14:37:17 +00:00
Added initial implementation to detect changes
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
package kube
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
"k8s.io/client-go/kubernetes"
|
||||
"k8s.io/client-go/rest"
|
||||
"k8s.io/client-go/tools/clientcmd"
|
||||
)
|
||||
|
||||
// gets the client for k8s, if ~/.kube/config exists so get that config else incluster config
|
||||
func GetClient() (*kubernetes.Clientset, error) {
|
||||
var config *rest.Config
|
||||
var err error
|
||||
kubeconfigPath := os.Getenv("KUBECONFIG")
|
||||
if kubeconfigPath == "" {
|
||||
kubeconfigPath = os.Getenv("HOME") + "/.kube/config"
|
||||
}
|
||||
//If file exists so use that config settings
|
||||
if _, err := os.Stat(kubeconfigPath); err == nil {
|
||||
config, err = clientcmd.BuildConfigFromFlags("", kubeconfigPath)
|
||||
} else { //Use Incluster Configuration
|
||||
config, err = rest.InClusterConfig()
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return kubernetes.NewForConfig(config)
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package kube
|
||||
|
||||
import (
|
||||
"k8s.io/api/core/v1"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
)
|
||||
|
||||
const (
|
||||
DefaultResource = "default"
|
||||
)
|
||||
|
||||
// MapToRuntimeObject maps the resource type string to the actual resource
|
||||
func MapToRuntimeObject(resourceType string) runtime.Object {
|
||||
rType, ok := ResourceMap[resourceType]
|
||||
if !ok {
|
||||
return ResourceMap[DefaultResource]
|
||||
}
|
||||
return rType
|
||||
}
|
||||
|
||||
// ResourceMap are resources from where changes are going to be detected
|
||||
var ResourceMap = map[string]runtime.Object{
|
||||
"configMaps": &v1.ConfigMap{},
|
||||
"secrets": &v1.Secret{},
|
||||
"default": nil,
|
||||
}
|
||||
Reference in New Issue
Block a user