Skip to content
This repository has been archived by the owner on Nov 1, 2022. It is now read-only.

Commit

Permalink
Integrate GitOps Engine into Flux
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Matyushentsev authored and 2opremio committed Mar 1, 2020
1 parent 1520e0f commit 8b0f4f6
Show file tree
Hide file tree
Showing 15 changed files with 766 additions and 1,948 deletions.
46 changes: 19 additions & 27 deletions cmd/fluxd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,12 @@ import (
"syscall"
"time"

"github.com/argoproj/argo-cd/engine/pkg/utils/io"
"github.com/go-kit/kit/log"
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/spf13/pflag"
crd "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset"
k8serrors "k8s.io/apimachinery/pkg/api/errors"
k8sruntime "k8s.io/apimachinery/pkg/util/runtime"
k8sclientdynamic "k8s.io/client-go/dynamic"
k8sclient "k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
Expand Down Expand Up @@ -404,6 +403,8 @@ func main() {
}()

// Cluster component.
fileinfo, err := os.Stat(k8sInClusterSecretsBaseDir)
isInCluster := err == nil && fileinfo.IsDir()

var restClientConfig *rest.Config
{
Expand Down Expand Up @@ -436,11 +437,6 @@ func main() {
logger.Log("err", err)
os.Exit(1)
}
dynamicClientset, err := k8sclientdynamic.NewForConfig(restClientConfig)
if err != nil {
logger.Log("err", err)
os.Exit(1)
}

fhrClientset, err := hrclient.NewForConfig(restClientConfig)
if err != nil {
Expand All @@ -454,22 +450,13 @@ func main() {
os.Exit(1)
}

crdClient, err := crd.NewForConfig(restClientConfig)
if err != nil {
logger.Log("error", fmt.Sprintf("Error building API extensions (CRD) clientset: %v", err))
os.Exit(1)
}
discoClientset := kubernetes.MakeCachedDiscovery(clientset.Discovery(), crdClient, shutdown)

serverVersion, err := clientset.ServerVersion()
if err != nil {
logger.Log("err", err)
os.Exit(1)
}
clusterVersion = "kubernetes-" + serverVersion.GitVersion

fileinfo, err := os.Stat(k8sInClusterSecretsBaseDir)
isInCluster := err == nil && fileinfo.IsDir()
if isInCluster && !httpGitURL {
namespace, err := ioutil.ReadFile(filepath.Join(k8sInClusterSecretsBaseDir, "serviceaccount/namespace"))
if err != nil {
Expand Down Expand Up @@ -502,6 +489,7 @@ func main() {

logger.Log("host", restClientConfig.Host, "version", clusterVersion)

// FIXME: This is currently not honored by the GitOps Engine
kubectl := *kubernetesKubectl
if kubectl == "" {
kubectl, err = exec.LookPath("kubectl")
Expand All @@ -514,17 +502,22 @@ func main() {
}
logger.Log("kubectl", kubectl)

client := kubernetes.MakeClusterClientset(clientset, dynamicClientset, fhrClientset, hrClientset, discoClientset)
kubectlApplier := kubernetes.NewKubectl(kubectl, restClientConfig)
allowedNamespaces := make(map[string]struct{})
for _, n := range append(*k8sNamespaceWhitelist, *k8sAllowNamespace...) {
allowedNamespaces[n] = struct{}{}
}

client := kubernetes.MakeClusterClientset(clientset, fhrClientset, hrClientset)
allowedNamespaces := append(*k8sNamespaceWhitelist, *k8sAllowNamespace...)
imageIncluder := cluster.ExcludeIncludeGlob{Exclude: *registryExcludeImage, Include: *registryIncludeImage}
k8sInst := kubernetes.NewCluster(client, kubectlApplier, sshKeyRing, logger, allowedNamespaces, imageIncluder, *k8sExcludeResource)
k8sInst, err := kubernetes.NewCluster(restClientConfig, *k8sDefaultNamespace, client, sshKeyRing, logger, allowedNamespaces, imageIncluder, *k8sExcludeResource)
if err != nil {
logger.Log("err", err)
os.Exit(1)
}
k8sInst.GC = *syncGC
k8sInst.DryGC = *dryGC
closer, err := k8sInst.Run()
if err != nil {
logger.Log("error", "Failed to initialize cluster", "err", err)
os.Exit(1)
}
defer io.Close(closer)

if err := k8sInst.Ping(); err != nil {
logger.Log("ping", err)
Expand All @@ -536,15 +529,14 @@ func main() {
imageCreds = k8sInst.ImagesToFetch
// There is only one way we currently interpret a repo of
// files as manifests, and that's as Kubernetes yamels.
namespacer, err := kubernetes.NewNamespacer(discoClientset, *k8sDefaultNamespace)
if err != nil {
logger.Log("err", err)
os.Exit(1)
}
if *sopsEnabled {
k8sManifests = kubernetes.NewSopsManifests(namespacer, logger)
k8sManifests = kubernetes.NewSopsManifests(k8sInst.Namespacer(), logger)
} else {
k8sManifests = kubernetes.NewManifests(namespacer, logger)
k8sManifests = kubernetes.NewManifests(k8sInst.Namespacer(), logger)
}
}

Expand Down
34 changes: 30 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,48 @@ replace (
github.com/fluxcd/helm-operator => github.com/fluxcd/helm-operator v1.0.0-rc6
)

// to be removed after https://github.com/argoproj/argo-cd/pull/3066 is merged
replace (
github.com/argoproj/argo-cd => github.com/argoproj/argo-cd v0.8.1-0.20200227223151-3cf5640c92f8 // gitops-engine branch
github.com/argoproj/argo-cd/engine => github.com/argoproj/argo-cd/engine v0.0.0-20200227223151-3cf5640c92f8 // gitops-engine branch
)

// Pin kubernetes dependencies to 1.16.2
replace (
k8s.io/api => k8s.io/api v0.0.0-20191016110408-35e52d86657a // kubernetes-1.16.2
k8s.io/apiextensions-apiserver => k8s.io/apiextensions-apiserver v0.0.0-20191016113550-5357c4baaf65 // kubernetes-1.16.2
k8s.io/apimachinery => k8s.io/apimachinery v0.0.0-20191004115801-a2eda9f80ab8

// To be removed, added by @alexmt to integrate with the gitops engine
k8s.io/apiserver => k8s.io/apiserver v0.16.6
k8s.io/cli-runtime => k8s.io/cli-runtime v0.16.6
k8s.io/client-go => k8s.io/client-go v0.0.0-20191016111102-bec269661e48 // kubernetes-1.16.2
k8s.io/cloud-provider => k8s.io/cloud-provider v0.16.6
k8s.io/cluster-bootstrap => k8s.io/cluster-bootstrap v0.16.6
k8s.io/code-generator => k8s.io/code-generator v0.16.5-beta.1 // kubernetes-1.16.2
k8s.io/component-base => k8s.io/component-base v0.16.6
k8s.io/cri-api => k8s.io/cri-api v0.16.6
k8s.io/csi-translation-lib => k8s.io/csi-translation-lib v0.16.6
k8s.io/kube-aggregator => k8s.io/kube-aggregator v0.16.6
k8s.io/kube-controller-manager => k8s.io/kube-controller-manager v0.16.6
k8s.io/kube-proxy => k8s.io/kube-proxy v0.16.6
k8s.io/kube-scheduler => k8s.io/kube-scheduler v0.16.6
k8s.io/kubectl => k8s.io/kubectl v0.16.6
k8s.io/kubelet => k8s.io/kubelet v0.16.6
k8s.io/legacy-cloud-providers => k8s.io/legacy-cloud-providers v0.16.6
k8s.io/metrics => k8s.io/metrics v0.16.6
k8s.io/sample-apiserver => k8s.io/sample-apiserver v0.16.6
)

// github.com/fluxcd/flux/pkg/install lives in this very repository, so use that
replace github.com/fluxcd/flux/pkg/install => ./pkg/install

require (
github.com/Jeffail/gabs v1.4.0
github.com/Masterminds/semver v1.5.0 // indirect
github.com/Masterminds/semver/v3 v3.0.3
github.com/Masterminds/sprig v2.22.0+incompatible // indirect
github.com/VividCortex/gohistogram v1.0.0 // indirect
github.com/argoproj/argo-cd/engine v1.4.2
github.com/aws/aws-sdk-go v1.27.1
github.com/bradfitz/gomemcache v0.0.0-20190329173943-551aad21a668
github.com/cheggaaa/pb/v3 v3.0.2
Expand All @@ -52,9 +76,10 @@ require (
github.com/gorilla/websocket v1.4.0
github.com/imdario/mergo v0.3.8
github.com/justinbarrick/go-k8s-portforward v1.0.4-0.20190722134107-d79fe1b9d79d
github.com/k0kubun/colorstring v0.0.0-20150214042306-9440f1994b88 // indirect
github.com/opencontainers/go-digest v1.0.0-rc1
github.com/opentracing/opentracing-go v1.1.0 // indirect
github.com/pkg/errors v0.8.1
github.com/pkg/errors v0.9.1
github.com/pkg/term v0.0.0-20190109203006-aa71e9d9e942
github.com/prometheus/client_golang v1.2.1
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4
Expand All @@ -69,13 +94,14 @@ require (
github.com/weaveworks/promrus v1.2.0 // indirect
github.com/whilp/git-urls v0.0.0-20160530060445-31bac0d230fa
github.com/xeipuuv/gojsonschema v1.1.0
github.com/yudai/pp v2.0.1+incompatible // indirect
go.mozilla.org/sops/v3 v3.5.0
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45
golang.org/x/sys v0.0.0-20191028164358-195ce5e7f934
golang.org/x/time v0.0.0-20191024005414-555d28b269f0
gopkg.in/yaml.v2 v2.2.4
gopkg.in/yaml.v2 v2.2.8
k8s.io/api v0.17.0
k8s.io/apiextensions-apiserver v0.0.0-20191016113550-5357c4baaf65
k8s.io/apiextensions-apiserver v0.16.6
k8s.io/apimachinery v0.17.0
k8s.io/client-go v11.0.0+incompatible
k8s.io/helm v2.16.1+incompatible
Expand Down
Loading

0 comments on commit 8b0f4f6

Please sign in to comment.