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
16 changes: 5 additions & 11 deletions cmd/argocd/commands/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,11 @@ func NewApplicationCreateCommand(clientOpts *argocdclient.ClientOptions) *cobra.
},
}
}
if appOpts.destServer != "" || appOpts.destNamespace != "" {
app.Spec.Destination = &argoappv1.ApplicationDestination{
Server: appOpts.destServer,
Namespace: appOpts.destNamespace,
}
if appOpts.destServer != "" {
app.Spec.Destination.Server = appOpts.destServer
}
if appOpts.destNamespace != "" {
app.Spec.Destination.Namespace = appOpts.destNamespace
}
setParameterOverrides(&app, appOpts.parameters)
conn, appIf := argocdclient.NewClientOrDie(clientOpts).NewApplicationClientOrDie()
Expand Down Expand Up @@ -200,14 +200,8 @@ func NewApplicationSetCommand(clientOpts *argocdclient.ClientOptions) *cobra.Com
case "revision":
app.Spec.Source.TargetRevision = appOpts.revision
case "dest-server":
if app.Spec.Destination == nil {
app.Spec.Destination = &argoappv1.ApplicationDestination{}
}
app.Spec.Destination.Server = appOpts.destServer
case "dest-namespace":
if app.Spec.Destination == nil {
app.Spec.Destination = &argoappv1.ApplicationDestination{}
}
app.Spec.Destination.Namespace = appOpts.destNamespace
}
})
Expand Down
3 changes: 1 addition & 2 deletions controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
"github.com/argoproj/argo-cd/server/cluster"
apireposerver "github.com/argoproj/argo-cd/server/repository"
"github.com/argoproj/argo-cd/util"
argoutil "github.com/argoproj/argo-cd/util/argo"
"github.com/argoproj/argo-cd/util/kube"
log "github.com/sirupsen/logrus"
"k8s.io/api/apps/v1"
Expand Down Expand Up @@ -288,7 +287,7 @@ func (ctrl *ApplicationController) tryRefreshAppStatus(app *appv1.Application) (
targetObjs[i] = &obj
}

server, namespace := argoutil.ResolveServerNamespace(app.Spec.Destination, manifestInfo)
server, namespace := app.Spec.Destination.Server, app.Spec.Destination.Namespace
comparisonResult, err := ctrl.appComparator.CompareAppState(server, namespace, targetObjs, app)
if err != nil {
return nil, nil, nil, err
Expand Down
235 changes: 114 additions & 121 deletions pkg/apis/application/v1alpha1/generated.pb.go

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion pkg/apis/application/v1alpha1/generated.proto

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

3 changes: 1 addition & 2 deletions pkg/apis/application/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ type ApplicationSpec struct {
// Source is a reference to the location ksonnet application definition
Source ApplicationSource `json:"source" protobuf:"bytes,1,opt,name=source"`
// Destination overrides the kubernetes server and namespace defined in the environment ksonnet app.yaml
// This field is optional. If omitted, uses the server and namespace defined in the environment
Destination *ApplicationDestination `json:"destination,omitempty" protobuf:"bytes,2,opt,name=destination"`
Destination ApplicationDestination `json:"destination" protobuf:"bytes,2,name=destination"`
// SyncPolicy dictates whether we auto-sync based on the delta between the tracked branch and live state
SyncPolicy string `json:"syncPolicy,omitempty" protobuf:"bytes,3,opt,name=syncPolicy"`
}
Expand Down
10 changes: 1 addition & 9 deletions pkg/apis/application/v1alpha1/zz_generated.deepcopy.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,15 +110,7 @@ func (in *ApplicationSource) DeepCopy() *ApplicationSource {
func (in *ApplicationSpec) DeepCopyInto(out *ApplicationSpec) {
*out = *in
in.Source.DeepCopyInto(&out.Source)
if in.Destination != nil {
in, out := &in.Destination, &out.Destination
if *in == nil {
*out = nil
} else {
*out = new(ApplicationDestination)
**out = **in
}
}
out.Destination = in.Destination
return
}

Expand Down
26 changes: 4 additions & 22 deletions server/application/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"github.com/argoproj/argo-cd/server/cluster"
apirepository "github.com/argoproj/argo-cd/server/repository"
"github.com/argoproj/argo-cd/util"
argoutil "github.com/argoproj/argo-cd/util/argo"
"github.com/argoproj/argo-cd/util/git"
"github.com/argoproj/argo-cd/util/kube"
"github.com/ghodss/yaml"
Expand Down Expand Up @@ -247,7 +246,7 @@ func (s *Server) validateApp(ctx context.Context, spec *appv1.ApplicationSpec) e
// Ensure the k8s cluster the app is referencing, is configured in ArgoCD
// NOTE: need to check if it was overridden in the destination spec
clusterURL := envSpec.Destination.Server
if spec.Destination != nil && spec.Destination.Server != "" {
if spec.Destination.Server != "" {
clusterURL = spec.Destination.Server
}
_, err = s.clusterService.Get(ctx, &cluster.ClusterQuery{Server: clusterURL})
Expand Down Expand Up @@ -485,26 +484,9 @@ func (s *Server) getApplicationDestination(ctx context.Context, name string) (st
app, err := s.appclientset.ArgoprojV1alpha1().Applications(s.ns).Get(name, metav1.GetOptions{})
if err != nil {
return "", "", err
} else {
repo := s.getRepo(ctx, app.Spec.Source.RepoURL)
conn, repoClient, err := s.repoClientset.NewRepositoryClient()
if err != nil {
return "", "", err
}
defer util.Close(conn)
manifestInfo, err := repoClient.GenerateManifest(ctx, &repository.ManifestRequest{
Repo: repo,
Environment: app.Spec.Source.Environment,
Path: app.Spec.Source.Path,
Revision: app.Spec.Source.TargetRevision,
AppLabel: app.Name,
})
if err != nil {
return "", "", err
}
server, namespace := argoutil.ResolveServerNamespace(app.Spec.Destination, manifestInfo)
return server, namespace, nil
}
server, namespace := app.Spec.Destination.Server, app.Spec.Destination.Namespace
return server, namespace, nil
}

func (s *Server) getRepo(ctx context.Context, repoURL string) *appv1.Repository {
Expand Down Expand Up @@ -557,7 +539,7 @@ func (s *Server) deploy(
targetObjs[i] = obj
}

server, namespace := argoutil.ResolveServerNamespace(app.Spec.Destination, manifestInfo)
server, namespace := app.Spec.Destination.Server, app.Spec.Destination.Namespace

comparison, err := s.appComparator.CompareAppState(server, namespace, targetObjs, app)
if err != nil {
Expand Down
19 changes: 0 additions & 19 deletions util/argo/argo.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,13 @@ import (
"time"

"github.com/argoproj/argo-cd/common"
appv1 "github.com/argoproj/argo-cd/pkg/apis/application/v1alpha1"
argoappv1 "github.com/argoproj/argo-cd/pkg/apis/application/v1alpha1"
"github.com/argoproj/argo-cd/pkg/client/clientset/versioned/typed/application/v1alpha1"
"github.com/argoproj/argo-cd/reposerver/repository"
log "github.com/sirupsen/logrus"
apierr "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/types"
)

// ResolveServerNamespace resolves server and namespace to use given an application spec,
// and a manifest response. It looks to explicit server/namespace overridden in the app CRD spec
// and falls back to the server/namespace defined in the ksonnet environment
func ResolveServerNamespace(destination *appv1.ApplicationDestination, manifestInfo *repository.ManifestResponse) (string, string) {
server := manifestInfo.Server
namespace := manifestInfo.Namespace
if destination != nil {
if destination.Server != "" {
server = destination.Server
}
if destination.Namespace != "" {
namespace = destination.Namespace
}
}
return server, namespace
}

// RefreshApp updates the refresh annotation of an application to coerce the controller to process it
func RefreshApp(appIf v1alpha1.ApplicationInterface, name string) (*argoappv1.Application, error) {
refreshString := time.Now().UTC().Format(time.RFC3339)
Expand Down