Skip to content
This repository has been archived by the owner on Oct 12, 2023. It is now read-only.

Add item list CRD Spec #1

Merged
merged 5 commits into from Jun 12, 2020
Merged

Conversation

xianlubird
Copy link
Member

# The list generator specifies a literal list of argument values to the app spec template.
apiVersion: argoproj.io/v1alpha1
kind: ApplicationSet
metadata:
  name: guestbook
spec:
  generators:
  - list:
      items:
      - cluster: engineering-dev
        url: https://1.2.3.4
      - cluster: engineering-prod
        url: https://2.4.6.8
      - cluster: finance-preprod
        url: https://9.8.7.6
  template:
    metadata:
      name: '{{name}}-guestbook'
    spec:
      source:
        repoURL: https://github.com/infra-team/cluster-deployments.git
        targetRevision: HEAD
        path: guestbook/{{cluster}}
      destination:
        server: '{{url}}'
        namespace: guestbook

First crd implement list item function

@CLAassistant
Copy link

CLAassistant commented Jun 5, 2020

CLA assistant check
All committers have signed the CLA.

@xianlubird xianlubird requested a review from jessesuen June 5, 2020 04:09
Makefile Outdated

.PHONY: image
image:
docker build -t registry.cn-hangzhou.aliyuncs.com/appcenter/argocd-aplicationset:$(IMAGE_TAG) .
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we make the registry configurable as well, $IMAGE perhaps?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree. Can make it such that it builds a local image (without a registry), but will prepend IMAGE_PREFIX if it is defined?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Makefile Outdated

.PHONY: image
image:
docker build -t registry.cn-hangzhou.aliyuncs.com/appcenter/argocd-aplicationset:$(IMAGE_TAG) .
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree. Can make it such that it builds a local image (without a registry), but will prepend IMAGE_PREFIX if it is defined?

type ApplicationSetSpec struct {
Generators ApplicationSetGenerators `json:"generators"`
Template ApplicationSetTemplate `json:"template"`
Operation *v1alpha1.SyncOperation `json:"operation,omitempty"`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regarding the operation field:

  1. Reusing the SyncOperation from the Applications APIs probably doesn't make sense here, since that object deals with a single git revision. But ApplicationSets may deal with many revisions, and even many repositories. If we do decide to have operation, we will need a new data structure.

  2. In fact, we're not sure what a sync operation even means for an AppSet. Currently, I think it would only be used as a convenience field which carries forward setting the operation field for all the Applications in the ApplicationSet. But this could be done as a convenience in the API server instead.

  3. We've had some regrets about introducing this operation field in Applications, since a better alternative might have been to introduce an SyncOperation CRD and controller to perform the logic. This CRD would act like a Job object and finish Successfully or Failed.

So with the above, I think we should leave out operation, until we think about how we want to do operations (if at all).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agree

type SyncPolicyAutomated struct {
// Prune will prune resources automatically as part of automated sync (default: false)
Prune bool `json:"prune,omitempty"`
InitialSync bool `json:"initialSync,omitempty"`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm thinking the word sync is redundant in the initialSync, since it's already part of a syncPolicy. How about:

spec:
  syncPolicy:
    automated:
      prune: true
      initial: true

Let's also comment this to explain what this option is for:

// Initial will perform an initial sync for any newly created Applications which do not have automated sync turned on.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link
Contributor

@dgoodwin dgoodwin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a couple quick thoughts on naming the structs, please disregard if this doesn't look better to you.

}

// GeneratorsList include items info
type GeneratorsList struct {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GeneratorsList implies this is a list of all generators, what do you think about ListGenerator to more clearly indicate what this is?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree

}

// GeneratorsItems include cluster and url info
type GeneratorsItems struct {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggest ListGeneratorItem


// ApplicationSetGenerators include list item info
type ApplicationSetGenerators struct {
List GeneratorsList `json:"list, omitempty"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feels like this should be *GeneratorsList as it is optional.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes

main.go Outdated

if err = (&controllers.ApplicationSetReconciler{
Client: mgr.GetClient(),
Log: ctrl.Log.WithName("controllers").WithName("ApplicationSet"),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor compile error here as the reconciler has no Log field.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix

@xianlubird xianlubird requested a review from dgoodwin June 12, 2020 02:59

// ApplicationSetSpec represents a class of application set state.
type ApplicationSetSpec struct {
Generators ApplicationSetGenerators `json:"generators"`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Per spec, it should be an array of ApplicationSetGenerator:

spec:
  generators:
  - clusters: {}
    Generators []ApplicationSetGenerator  `json:"generators"`

}

// ApplicationSetGenerators include list item info
type ApplicationSetGenerators struct {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should remove s from ApplicationSetGenerators since this should be a single generator

type ApplicationSetGenerator struct {
	List *ListGenerator `json:"list, omitempty"`
}

Also, we should remove s from ListGenerators as well.

}

// ItemGenerators include cluster and url info
type ItemGenerators struct {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

type ListGeneratorItem struct

}

// ListGenerators include items info
type ListGenerators struct {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be:

type ListGenerator struct {

(no s)

// ApplicationSetTemplate represents argocd ApplicationSpec
type ApplicationSetTemplate struct {
metav1.ObjectMeta `json:"metadata"`
TemplateSpec v1alpha1.ApplicationSpec `json:"spec"`
Copy link
Member

@jessesuen jessesuen Jun 12, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the field name needs to be named Spec, otherwise this may be an K8s API violation since the golang field name does not match the json field name.

@xianlubird xianlubird merged commit 24cdcc2 into argoproj:master Jun 12, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants