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

Update ksonnet and begin using it as library instead of parsing stdout #69

Merged
merged 1 commit into from
Apr 4, 2018
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
19 changes: 13 additions & 6 deletions Dockerfile-argocd
Original file line number Diff line number Diff line change
Expand Up @@ -39,22 +39,29 @@ RUN cd ${GOPATH}/src/dummy && \
mv vendor/* ${GOPATH}/src/ && \
rmdir vendor

ARG MAKE_TARGET

# Perform the build
ARG MAKE_TARGET
WORKDIR /root/go/src/github.com/argoproj/argo-cd
COPY . .
RUN make ${MAKE_TARGET}
RUN wget https://github.com/ksonnet/ksonnet/releases/download/v0.9.1/ks_0.9.1_linux_amd64.tar.gz && tar -C /tmp/ -xf ks_0.9.1_linux_amd64.tar.gz


##############################################################
FROM golang:1.10 as ksonnet-builder

# Install ksonnet
# TODO(jessesuen): remove this docker build stage this once we have an official prebuilt 1.10+ release
RUN go get -v -u github.com/ksonnet/ksonnet


##############################################################
FROM debian:9.3
RUN apt-get update && apt-get install -y git && \
apt-get clean && \
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
ARG BINARY
COPY --from=builder /root/go/src/github.com/argoproj/argo-cd/dist/${BINARY} /${BINARY}
COPY --from=builder /tmp/ks_0.9.1_linux_amd64/ks /usr/local/bin/ks
# workaround ksonnet issue https://github.com/ksonnet/ksonnet/issues/298
ENV USER=root
COPY --from=ksonnet-builder /go/bin/ksonnet /usr/local/bin/ks

ENV BINARY=$BINARY
CMD /$BINARY
2 changes: 1 addition & 1 deletion Gopkg.lock

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

26 changes: 11 additions & 15 deletions util/ksonnet/ksonnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

"github.com/argoproj/argo-cd/pkg/apis/application/v1alpha1"
"github.com/ghodss/yaml"
"github.com/ksonnet/ksonnet/component"
"github.com/ksonnet/ksonnet/metadata"
"github.com/ksonnet/ksonnet/metadata/app"
log "github.com/sirupsen/logrus"
Expand All @@ -17,7 +18,6 @@ import (

var (
diffSeparator = regexp.MustCompile(`\n---`)
lineSeparator = regexp.MustCompile(`\n`)
)

// KsonnetApp represents a ksonnet application directory and provides wrapper functionality around
Expand Down Expand Up @@ -113,27 +113,23 @@ func (k *ksonnetApp) Show(environment string) ([]*unstructured.Unstructured, err

// ListEnvParams returns list of environment parameters
func (k *ksonnetApp) ListEnvParams(environment string) ([]*v1alpha1.ComponentParameter, error) {
// count of rows to skip in command-line output
const skipRows = 2
out, err := k.ksCmd("param", "list", "--env", environment)
mod, err := component.DefaultManager.Module(k.app, "")
if err != nil {
return nil, err
}
ksParams, err := mod.Params(environment)
if err != nil {
return nil, err
}
var params []*v1alpha1.ComponentParameter
rows := lineSeparator.Split(out, -1)
for _, row := range rows[skipRows:] {
if strings.TrimSpace(row) == "" {
continue
}
fields := strings.Fields(row)
component, param, rawValue := fields[0], fields[1], fields[2]
value, err := strconv.Unquote(rawValue)
for _, ksParam := range ksParams {
value, err := strconv.Unquote(ksParam.Value)
if err != nil {
value = rawValue
value = ksParam.Value
}
componentParam := v1alpha1.ComponentParameter{
Component: component,
Name: param,
Component: ksParam.Component,
Name: ksParam.Key,
Value: value,
}
params = append(params, &componentParam)
Expand Down