Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Support daemonset target kind #455

Merged
merged 7 commits into from
Feb 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 19 additions & 4 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ jobs:
- run: test/e2e-istio.sh
- run: test/e2e-tests.sh

e2e-kubernetes-testing:
e2e-kubernetes-daemonset-testing:
machine: true
steps:
- checkout
Expand All @@ -91,7 +91,18 @@ jobs:
- run: test/container-build.sh
- run: test/e2e-kind.sh v1.17.0
- run: test/e2e-kubernetes.sh
- run: test/e2e-kubernetes-tests.sh
- run: test/e2e-kubernetes-tests-daemonset.sh

e2e-kubernetes-deployment-testing:
machine: true
steps:
- checkout
- attach_workspace:
at: /tmp/bin
- run: test/container-build.sh
- run: test/e2e-kind.sh v1.17.0
- run: test/e2e-kubernetes.sh
- run: test/e2e-kubernetes-tests-deployment.sh

e2e-kubernetes-svc-testing:
machine: true
Expand Down Expand Up @@ -215,7 +226,10 @@ workflows:
- e2e-istio-testing:
requires:
- build-binary
- e2e-kubernetes-testing:
- e2e-kubernetes-daemonset-testing:
requires:
- build-binary
- e2e-kubernetes-deployment-testing:
requires:
- build-binary
- e2e-gloo-testing:
Expand All @@ -234,7 +248,8 @@ workflows:
requires:
- build-binary
- e2e-istio-testing
- e2e-kubernetes-testing
- e2e-kubernetes-daemonset-testing
- e2e-kubernetes-deployment-testing
- e2e-gloo-testing
- e2e-nginx-testing
- e2e-linkerd-testing
Expand Down
1 change: 1 addition & 0 deletions artifacts/flagger/account.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ rules:
- apiGroups:
- apps
resources:
- daemonsets
- deployments
verbs: ["*"]
- apiGroups:
Expand Down
1 change: 1 addition & 0 deletions artifacts/flagger/crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ spec:
kind:
type: string
enum:
- DaemonSet
- Deployment
- Service
name:
Expand Down
1 change: 1 addition & 0 deletions charts/flagger/crds/crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ spec:
kind:
type: string
enum:
- DaemonSet
- Deployment
- Service
name:
Expand Down
1 change: 1 addition & 0 deletions charts/flagger/templates/rbac.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ rules:
- apiGroups:
- apps
resources:
- daemonsets
- deployments
verbs: ["*"]
- apiGroups:
Expand Down
1 change: 1 addition & 0 deletions kustomize/base/flagger/crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ spec:
kind:
type: string
enum:
- DaemonSet
- Deployment
- Service
name:
Expand Down
1 change: 1 addition & 0 deletions kustomize/base/flagger/rbac.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ rules:
- apiGroups:
- apps
resources:
- daemonsets
- deployments
verbs: ["*"]
- apiGroups:
Expand Down
34 changes: 27 additions & 7 deletions pkg/canary/config_tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,16 +93,36 @@ func (ct *ConfigTracker) getRefFromSecret(name string, namespace string) (*Confi
func (ct *ConfigTracker) GetTargetConfigs(cd *flaggerv1.Canary) (map[string]ConfigRef, error) {
res := make(map[string]ConfigRef)
targetName := cd.Spec.TargetRef.Name
targetDep, err := ct.KubeClient.AppsV1().Deployments(cd.Namespace).Get(targetName, metav1.GetOptions{})
if err != nil {
if errors.IsNotFound(err) {
return res, fmt.Errorf("deployment %s.%s not found", targetName, cd.Namespace)

var vs []corev1.Volume
var cs []corev1.Container
switch cd.Spec.TargetRef.Kind {
case "Deployment":
targetDep, err := ct.KubeClient.AppsV1().Deployments(cd.Namespace).Get(targetName, metav1.GetOptions{})
if err != nil {
if errors.IsNotFound(err) {
return res, fmt.Errorf("deployment %s.%s not found", targetName, cd.Namespace)
}
return res, fmt.Errorf("deployment %s.%s query error %v", targetName, cd.Namespace, err)
}
vs = targetDep.Spec.Template.Spec.Volumes
cs = targetDep.Spec.Template.Spec.Containers
case "DaemonSet":
targetDae, err := ct.KubeClient.AppsV1().DaemonSets(cd.Namespace).Get(targetName, metav1.GetOptions{})
if err != nil {
if errors.IsNotFound(err) {
return res, fmt.Errorf("daemonset %s.%s not found", targetName, cd.Namespace)
}
return res, fmt.Errorf("daemonset %s.%s query error %v", targetName, cd.Namespace, err)
}
return res, fmt.Errorf("deployment %s.%s query error %v", targetName, cd.Namespace, err)
vs = targetDae.Spec.Template.Spec.Volumes
cs = targetDae.Spec.Template.Spec.Containers
default:
return nil, fmt.Errorf("TargetRef.Kind invalid: %s", cd.Spec.TargetRef.Kind)
}

// scan volumes
for _, volume := range targetDep.Spec.Template.Spec.Volumes {
for _, volume := range vs {
if cmv := volume.ConfigMap; cmv != nil {
config, err := ct.getRefFromConfigMap(cmv.Name, cd.Namespace)
if err != nil {
Expand Down Expand Up @@ -152,7 +172,7 @@ func (ct *ConfigTracker) GetTargetConfigs(cd *flaggerv1.Canary) (map[string]Conf
}
}
// scan containers
for _, container := range targetDep.Spec.Template.Spec.Containers {
for _, container := range cs {
// scan env
for _, env := range container.Env {
if env.ValueFrom != nil {
Expand Down
Loading