Skip to content

Commit

Permalink
iteration
Browse files Browse the repository at this point in the history
  • Loading branch information
jkhelil committed Feb 5, 2024
1 parent d42f2af commit e4c177c
Show file tree
Hide file tree
Showing 18 changed files with 33 additions and 1,627 deletions.
6 changes: 2 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@ require (
sigs.k8s.io/controller-runtime v0.14.6
)

require (
github.com/manifestival/client-go-client v0.5.0
knative.dev/pkg v0.0.0-20230320014357-4c84b1b51ee8
)
require github.com/manifestival/client-go-client v0.5.0

require (
contrib.go.opencensus.io/exporter/ocagent v0.7.1-0.20200907061046-05415f1de66d // indirect
Expand Down Expand Up @@ -97,6 +94,7 @@ require (
k8s.io/klog/v2 v2.90.1 // indirect
k8s.io/kube-openapi v0.0.0-20230308215209-15aac26d736a // indirect
k8s.io/utils v0.0.0-20230313181309-38a27ef9d749 // indirect
knative.dev/pkg v0.0.0-20230320014357-4c84b1b51ee8 // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect
sigs.k8s.io/yaml v1.3.0 // indirect
Expand Down
33 changes: 31 additions & 2 deletions pkg/common/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,19 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime"
"knative.dev/pkg/injection"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
"sigs.k8s.io/controller-runtime/pkg/client"
)

// SetupManifestival instantiates a Manifestival instance for the provided file or directory
func SetupManifestival(client client.Client, fileOrDir string, recurse bool, logger logr.Logger) (manifestival.Manifest, error) {
mfclient, err := mfc.NewClient(injection.GetConfig(context.TODO()))
kubeRestConfig, err := GetConfig()
if err != nil {
return manifestival.Manifest{}, fmt.Errorf("Error creating kubernetes rest client %v", err)
}

mfclient, err := mfc.NewClient(kubeRestConfig)
if err != nil {
return manifestival.Manifest{}, fmt.Errorf("Error creating client from injected config %v", err)
}
Expand Down Expand Up @@ -206,3 +212,26 @@ func itemInSlice(item string, items []string) bool {
func IsOpenShiftPlatform() bool {
return os.Getenv("PLATFORM") == "openshift"
}

// GetConfig creates a *rest.Config for talking to a Kubernetes apiserver.
// Otherwise will assume running in cluster and use the cluster provided kubeconfig.
//
// # Config precedence
//
// * KUBECONFIG environment variable pointing at a file
//
// * In-cluster config if running in cluster
//
// * $HOME/.kube/config if exists
func GetConfig() (*rest.Config, error) {
// If an env variable is specified with the config locaiton, use that
if len(os.Getenv("KUBECONFIG")) > 0 {
return clientcmd.BuildConfigFromFlags("", os.Getenv("KUBECONFIG"))
}
// If no explicit location, try the in-cluster config
if c, err := rest.InClusterConfig(); err == nil {
return c, nil
}

return nil, fmt.Errorf("could not locate a kubeconfig")
}
86 changes: 0 additions & 86 deletions vendor/knative.dev/pkg/environment/client_config.go

This file was deleted.

Loading

0 comments on commit e4c177c

Please sign in to comment.