Skip to content

Commit

Permalink
Merge pull request rancher#258 from kinarashah/env2
Browse files Browse the repository at this point in the history
add env vars to agent manifest
  • Loading branch information
kinarashah authored Feb 3, 2021
2 parents b7fdba6 + 981611e commit 44af155
Show file tree
Hide file tree
Showing 11 changed files with 435 additions and 42 deletions.
65 changes: 65 additions & 0 deletions charts/fleet-crd/templates/crds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1415,6 +1415,71 @@ spec:
properties:
spec:
properties:
agentEnvVars:
items:
properties:
name:
nullable: true
type: string
value:
nullable: true
type: string
valueFrom:
nullable: true
properties:
configMapKeyRef:
nullable: true
properties:
key:
nullable: true
type: string
name:
nullable: true
type: string
optional:
nullable: true
type: boolean
type: object
fieldRef:
nullable: true
properties:
apiVersion:
nullable: true
type: string
fieldPath:
nullable: true
type: string
type: object
resourceFieldRef:
nullable: true
properties:
containerName:
nullable: true
type: string
divisor:
nullable: true
type: string
resource:
nullable: true
type: string
type: object
secretKeyRef:
nullable: true
properties:
key:
nullable: true
type: string
name:
nullable: true
type: string
optional:
nullable: true
type: boolean
type: object
type: object
type: object
nullable: true
type: array
clientID:
nullable: true
type: string
Expand Down
18 changes: 9 additions & 9 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ module github.com/rancher/fleet
go 1.14

replace (
github.com/Azure/go-autorest => github.com/Azure/go-autorest v14.0.0+incompatible
github.com/rancher/fleet/pkg/apis => ./pkg/apis
helm.sh/helm/v3 => github.com/ibuildthecloud/helm/v3 v3.1.0-rc.1.0.20200829031744-19e92760f498
k8s.io/client-go => github.com/rancher/client-go v0.18.8-fleet1
helm.sh/helm/v3 => github.com/rancher/helm/v3 v3.3.3-fleet1
k8s.io/client-go => github.com/rancher/client-go v0.20.0-fleet1
)

require (
Expand All @@ -20,14 +19,15 @@ require (
github.com/rancher/wrangler v0.7.3-0.20201002224307-4303c423125a
github.com/rancher/wrangler-cli v0.0.0-20200815040857-81c48cf8ab43
github.com/sirupsen/logrus v1.6.0
github.com/spf13/cobra v1.0.0
github.com/spf13/cobra v1.1.1
go.mozilla.org/sops/v3 v3.6.1
golang.org/x/sync v0.0.0-20200317015054-43a5402ce75a
helm.sh/helm/v3 v3.0.0
k8s.io/api v0.18.8
k8s.io/apimachinery v0.18.8
k8s.io/cli-runtime v0.18.4
k8s.io/client-go v0.18.8
helm.sh/helm/v3 v3.5.1
k8s.io/api v0.20.0
k8s.io/apimachinery v0.20.0
k8s.io/cli-runtime v0.20.0
k8s.io/client-go v0.20.0
k8s.io/kubectl v0.20.0 // indirect
rsc.io/letsencrypt v0.0.3 // indirect
sigs.k8s.io/cli-utils v0.16.0
sigs.k8s.io/kustomize/api v0.6.0
Expand Down
299 changes: 273 additions & 26 deletions go.sum

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion modules/cli/agentmanifest/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
fleetcontrollers "github.com/rancher/fleet/pkg/generated/controllers/fleet.cattle.io/v1alpha1"
"github.com/rancher/wrangler/pkg/kubeconfig"
"github.com/rancher/wrangler/pkg/yaml"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/watch"
Expand All @@ -40,6 +41,7 @@ type Options struct {
ClientID string
Generation string
CheckinInterval string
AgentEnvVars []v1.EnvVar
}

func AgentToken(ctx context.Context, controllerNamespace string, client *client.Client, tokenName string, opts *Options) ([]runtime.Object, error) {
Expand Down Expand Up @@ -123,7 +125,7 @@ func AgentManifest(ctx context.Context, systemNamespace, controllerNamespace str
return err
}

objs = append(objs, agent.Manifest(controllerNamespace, cfg.AgentImage, cfg.AgentImagePullPolicy, opts.Generation, opts.CheckinInterval)...)
objs = append(objs, agent.Manifest(controllerNamespace, cfg.AgentImage, cfg.AgentImagePullPolicy, opts.Generation, opts.CheckinInterval, opts.AgentEnvVars)...)

data, err := yaml.Export(objs...)
if err != nil {
Expand Down
5 changes: 4 additions & 1 deletion pkg/agent/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const (
DefaultName = "fleet-agent"
)

func Manifest(namespace, image, pullPolicy, generation, checkInInterval string) []runtime.Object {
func Manifest(namespace, image, pullPolicy, generation, checkInInterval string, agentEnvVars []corev1.EnvVar) []runtime.Object {
if image == "" {
image = config.DefaultAgentImage
}
Expand Down Expand Up @@ -42,6 +42,9 @@ func Manifest(namespace, image, pullPolicy, generation, checkInInterval string)
Name: "GENERATION",
Value: generation,
})
if agentEnvVars != nil {
dep.Spec.Template.Spec.Containers[0].Env = append(dep.Spec.Template.Spec.Containers[0].Env, agentEnvVars...)
}
dep.Spec.Template.Spec.Affinity = &corev1.Affinity{
NodeAffinity: &corev1.NodeAffinity{
PreferredDuringSchedulingIgnoredDuringExecution: []corev1.PreferredSchedulingTerm{
Expand Down
2 changes: 2 additions & 0 deletions pkg/apis/fleet.cattle.io/v1alpha1/target.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package v1alpha1

import (
"github.com/rancher/wrangler/pkg/genericcondition"
"k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

Expand Down Expand Up @@ -64,6 +65,7 @@ type ClusterSpec struct {
ClientID string `json:"clientID,omitempty"`
KubeConfigSecret string `json:"kubeConfigSecret,omitempty"`
RedeployAgentGeneration int64 `json:"redeployAgentGeneration,omitempty"`
AgentEnvVars []v1.EnvVar `json:"agentEnvVars,omitempty"`
}

type ClusterStatus struct {
Expand Down
10 changes: 9 additions & 1 deletion pkg/apis/fleet.cattle.io/v1alpha1/zz_generated_deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion pkg/apis/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ go 1.14

require (
github.com/rancher/wrangler v0.6.2-0.20200829053106-7e1dd4260224
k8s.io/apimachinery v0.18.8
k8s.io/api v0.20.0
k8s.io/apimachinery v0.20.0
)
Loading

0 comments on commit 44af155

Please sign in to comment.