Skip to content
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
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ RUN curl -L -o /usr/local/bin/kubectl -LO https://storage.googleapis.com/kuberne
# Option 1: build ksonnet ourselves
#RUN go get -v -u github.com/ksonnet/ksonnet && mv ${GOPATH}/bin/ksonnet /usr/local/bin/ks
# Option 2: use official tagged ksonnet release
ENV KSONNET_VERSION=0.11.0
ENV KSONNET_VERSION=0.13.0
RUN wget https://github.com/ksonnet/ksonnet/releases/download/v${KSONNET_VERSION}/ks_${KSONNET_VERSION}_linux_amd64.tar.gz && \
tar -C /tmp/ -xf ks_${KSONNET_VERSION}_linux_amd64.tar.gz && \
mv /tmp/ks_${KSONNET_VERSION}_linux_amd64/ks /usr/local/bin/ks
Expand Down
92 changes: 8 additions & 84 deletions Gopkg.lock

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

14 changes: 0 additions & 14 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,6 @@ required = [
branch = "release-1.10"
name = "k8s.io/api"

# override ksonnet dependency
[[override]]
branch = "release-1.10"
name = "k8s.io/apimachinery"

[[constraint]]
name = "k8s.io/apiextensions-apiserver"
branch = "release-1.10"
Expand All @@ -58,19 +53,10 @@ required = [
name = "github.com/stretchr/testify"
version = "1.2.1"

[[constraint]]
name = "github.com/ksonnet/ksonnet"
version = "v0.11.0"

[[constraint]]
name = "github.com/gobuffalo/packr"
version = "v1.11.0"

# override ksonnet's logrus dependency
[[override]]
name = "github.com/sirupsen/logrus"
revision = "ea8897e79973357ba785ac2533559a6297e83c44"

[[constraint]]
branch = "master"
name = "github.com/argoproj/pkg"
18 changes: 8 additions & 10 deletions reposerver/repository/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"time"

"github.com/google/go-jsonnet"
"github.com/ksonnet/ksonnet/pkg/app"
log "github.com/sirupsen/logrus"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
Expand Down Expand Up @@ -196,13 +195,13 @@ func (s *Service) GenerateManifest(c context.Context, q *ManifestRequest) (*Mani
func generateManifests(appPath string, q *ManifestRequest) (*ManifestResponse, error) {
var targetObjs []*unstructured.Unstructured
var params []*v1alpha1.ComponentParameter
var env *app.EnvironmentSpec
var dest *v1alpha1.ApplicationDestination
var err error

appSourceType := IdentifyAppSourceTypeByAppDir(appPath)
switch appSourceType {
case AppSourceKsonnet:
targetObjs, params, env, err = ksShow(appPath, q.Environment, q.ComponentParameterOverrides)
targetObjs, params, dest, err = ksShow(appPath, q.Environment, q.ComponentParameterOverrides)
case AppSourceHelm:
h := helm.NewHelmApp(appPath)
err = h.DependencyBuild()
Expand Down Expand Up @@ -266,9 +265,9 @@ func generateManifests(appPath string, q *ManifestRequest) (*ManifestResponse, e
Manifests: manifests,
Params: params,
}
if env != nil {
res.Namespace = env.Destination.Namespace
res.Server = env.Destination.Server
if dest != nil {
res.Namespace = dest.Namespace
res.Server = dest.Server
}
return &res, nil
}
Expand Down Expand Up @@ -335,7 +334,7 @@ func getFileCacheKey(commitSHA string, q *GetFileRequest) string {
}

// ksShow runs `ks show` in an app directory after setting any component parameter overrides
func ksShow(appPath, envName string, overrides []*v1alpha1.ComponentParameter) ([]*unstructured.Unstructured, []*v1alpha1.ComponentParameter, *app.EnvironmentSpec, error) {
func ksShow(appPath, envName string, overrides []*v1alpha1.ComponentParameter) ([]*unstructured.Unstructured, []*v1alpha1.ComponentParameter, *v1alpha1.ApplicationDestination, error) {
ksApp, err := ksonnet.NewKsonnetApp(appPath)
if err != nil {
return nil, nil, nil, status.Errorf(codes.FailedPrecondition, "unable to load application from %s: %v", appPath, err)
Expand All @@ -352,16 +351,15 @@ func ksShow(appPath, envName string, overrides []*v1alpha1.ComponentParameter) (
}
}
}
appSpec := ksApp.App()
env, err := appSpec.Environment(envName)
dest, err := ksApp.Destination(envName)
if err != nil {
return nil, nil, nil, status.Errorf(codes.NotFound, "environment %q does not exist in ksonnet app", envName)
}
targetObjs, err := ksApp.Show(envName)
if err != nil {
return nil, nil, nil, err
}
return targetObjs, params, env, nil
return targetObjs, params, dest, nil
}

var manifestFile = regexp.MustCompile(`^.*\.(yaml|yml|json|jsonnet)$`)
Expand Down
2 changes: 1 addition & 1 deletion server/application/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -809,7 +809,7 @@ func (s *Server) TerminateOperation(ctx context.Context, termOpReq *OperationTer
if !apierr.IsConflict(err) {
return nil, err
}
log.Warnf("Failed to set operation for app '%s' due to update conflict. Retrying again...", termOpReq.Name)
log.Warnf("Failed to set operation for app '%s' due to update conflict. Retrying again...", *termOpReq.Name)
time.Sleep(100 * time.Millisecond)
a, err = s.appclientset.ArgoprojV1alpha1().Applications(s.ns).Get(*termOpReq.Name, metav1.GetOptions{})
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion server/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func (c *appCollector) Describe(ch chan<- *prometheus.Desc) {
func (c *appCollector) Collect(ch chan<- prometheus.Metric) {
apps, err := c.store.List(labels.NewSelector())
if err != nil {
log.Warn("Failed to collect applications: %v", err)
log.Warnf("Failed to collect applications: %v", err)
return
}
for _, app := range apps {
Expand Down
72 changes: 29 additions & 43 deletions util/argo/argo.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import (
"strings"
"time"

"github.com/ghodss/yaml"
"github.com/ksonnet/ksonnet/pkg/app"
log "github.com/sirupsen/logrus"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
Expand All @@ -29,6 +27,7 @@ import (
"github.com/argoproj/argo-cd/util"
"github.com/argoproj/argo-cd/util/db"
"github.com/argoproj/argo-cd/util/git"
"github.com/argoproj/argo-cd/util/ksonnet"
)

const (
Expand Down Expand Up @@ -223,9 +222,13 @@ func GetSpecErrors(
} else {
switch appSourceType {
case repository.AppSourceKsonnet:
appYamlConditions := verifyAppYAML(ctx, repoRes, spec, repoClient)
if len(appYamlConditions) > 0 {
conditions = append(conditions, appYamlConditions...)
err := verifyAppYAML(ctx, repoRes, spec, repoClient)
if err != nil {
conditions = append(conditions, argoappv1.ApplicationCondition{
Type: argoappv1.ApplicationConditionInvalidSpecError,
Message: err.Error(),
})

}
case repository.AppSourceHelm:
helmConditions := verifyHelmChart(ctx, repoRes, spec, repoClient)
Expand Down Expand Up @@ -321,7 +324,12 @@ func queryAppSourceType(ctx context.Context, spec *argoappv1.ApplicationSpec, re
}

// verifyAppYAML verifies that a ksonnet app.yaml is functional
func verifyAppYAML(ctx context.Context, repoRes *argoappv1.Repository, spec *argoappv1.ApplicationSpec, repoClient repository.RepositoryServiceClient) []argoappv1.ApplicationCondition {
func verifyAppYAML(ctx context.Context, repoRes *argoappv1.Repository, spec *argoappv1.ApplicationSpec, repoClient repository.RepositoryServiceClient) error {
// Default revision to HEAD if unspecified
if spec.Source.TargetRevision == "" {
spec.Source.TargetRevision = "HEAD"
}

req := repository.GetFileRequest{
Repo: &argoappv1.Repository{
Repo: spec.Source.RepoURL,
Expand All @@ -335,47 +343,25 @@ func verifyAppYAML(ctx context.Context, repoRes *argoappv1.Repository, spec *arg
req.Repo.SSHPrivateKey = repoRes.SSHPrivateKey
}
getRes, err := repoClient.GetFile(ctx, &req)
var conditions []argoappv1.ApplicationCondition
if err != nil {
conditions = append(conditions, argoappv1.ApplicationCondition{
Type: argoappv1.ApplicationConditionInvalidSpecError,
Message: fmt.Sprintf("Unable to load app.yaml: %v", err),
})
} else {
var appSpec app.Spec
err = yaml.Unmarshal(getRes.Data, &appSpec)
if err != nil {
conditions = append(conditions, argoappv1.ApplicationCondition{
Type: argoappv1.ApplicationConditionInvalidSpecError,
Message: "app.yaml is not a valid ksonnet app spec",
})
} else {
// Default revision to HEAD if unspecified
if spec.Source.TargetRevision == "" {
spec.Source.TargetRevision = "HEAD"
}
return fmt.Errorf("Unable to load app.yaml: %v", err)
}

// Verify the specified environment is defined in it
envSpec, ok := appSpec.Environments[spec.Source.Environment]
if !ok || envSpec == nil {
conditions = append(conditions, argoappv1.ApplicationCondition{
Type: argoappv1.ApplicationConditionInvalidSpecError,
Message: fmt.Sprintf("environment '%s' does not exist in ksonnet app", spec.Source.Environment),
})
}
// Verify the specified environment is defined in the app spec
dest, err := ksonnet.Destination(getRes.Data, spec.Source.Environment)
if err != nil {
return err
}

if envSpec != nil {
// If server and namespace are not supplied, pull it from the app.yaml
if spec.Destination.Server == "" {
spec.Destination.Server = envSpec.Destination.Server
}
if spec.Destination.Namespace == "" {
spec.Destination.Namespace = envSpec.Destination.Namespace
}
}
}
// If server and namespace are not supplied, pull it from the app.yaml
if spec.Destination.Server == "" {
spec.Destination.Server = dest.Server
}
return conditions
if spec.Destination.Namespace == "" {
spec.Destination.Namespace = dest.Namespace
}

return nil
}

// verifyHelmChart verifies a helm chart is functional
Expand Down
Loading