-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
gen2 profiles aka "AppProfiles" (design proposal 3) (#335)
Design doc: https://github.com/arlonproj/arlon/blob/private/leb/multiprofiles/docs/gen2_profiles_proposal_3.md Testing: - unit test located at pkg/appprofile/appprofile_test.go - E2E test: make e2e-appprofiles ------ squashed commits ------ * gen2 profiles * update gen2 profiles doc * use applicationset apis from argo-cd repo * initial AppProfile API, needs 'make' to regenerate code * after make generate * initial implementation of AppProfiles - untested * fix circular import loop * appprofiles reconciliation started working * appprofiles reconciliation - improvements * add application (cluster) and applicationset (app) reconciliation * doc for gen2 profles - proposal 2 * Update gen2_profiles_proposal_2.md * Update gen2_profiles_proposal_2.md * Update gen2_profiles_proposal_2.md * Update gen2_profiles_proposal_2.md * Update gen2_profiles_proposal_2.md * Update gen2_profiles_proposal_2.md * Update gen2_profiles_proposal_2.md * add arlon-gen2-profiles-reconc-algo.png * Update gen2_profiles_proposal_2.md * Update gen2_profiles_proposal_2.md * Update gen2_profiles_proposal_2.md * Update gen2_profiles_proposal_2.md * fix reconciliation bug: don't take address of temp loop variable * Update gen2_profiles_proposal_2.md * multiple profiles support: initial implementation * fixes ... seems to work now * use a better time encoder for zap logger * more logging tweaks to make log lines shorter * unit test, first iteration * unit test enhancements * more unit test enhancements * even more unit test enhancements * add 'appprofile list' command * display app-profiles in 'app list' command output * 'appprofile list' and 'app create' commands, display app-profiles in 'app list' command output * fix unit test * new 'app delete' command * display appprofiles in 'cluster list' command * fix nil pointer deref bug in reconciliation * new 'cluster setappprofiles' command * new document for proposal 3 of gen2 profiles * Update gen2_profiles_proposal_3.md * Update gen2_profiles_proposal_3.md * set CONTROLLER_TOOLS_VERSION to v0.10.0 * remove ngprofile and app/[add_to|remove_from]_profile commands * Makefile: add unittests target * add unit tests to github CI workflow * set arlon image version to 0.10.0 in deployment yaml * RBAC settings for appprofile * add examples/declarative and examples/clustertemplates * remove sshKeyName field from example cluster manifest * rename my-cluster -> mycluster * prepare base cluster files for examples/clustertemplates/eks-managed-mpool/manifest.yaml * rename my-cluster -> mycluster in cluster.yaml * consolidate example apps into single file * raise arlon controller memory request and limit * again raise arlon controller (the other one) memory request and limit * fix repoUrl for redis example app * (WIP) add e2e test for appprofiles * fix relative path to example manifests * fix relative path to example manifests again * e2e-appprofiles: fix the expected values for MachinePool * e2e-appprofiles: fix the API version for MachinePool * Update .github/workflows/ci.yml Co-authored-by: Rohit Rajak <[email protected]> * Update cmd/app/create.go remove null import of 'embed' Co-authored-by: Rohit Rajak <[email protected]> * Update cmd/app/delete.go remove null import of 'embed' Co-authored-by: Rohit Rajak <[email protected]> * remove unittests target because pkgtest does same thing * remove unused constant Co-authored-by: Bich Le <[email protected]> Co-authored-by: arlon automation <[email protected]> Co-authored-by: Rohit Rajak <[email protected]>
- Loading branch information
Showing
59 changed files
with
3,105 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
Copyright 2021. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package v1 | ||
|
||
import ( | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN! | ||
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized. | ||
|
||
// AppProfileSpec defines the desired state of AppProfile | ||
type AppProfileSpec struct { | ||
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster | ||
// Important: Run "make" to regenerate code after modifying this file | ||
|
||
AppNames []string `json:"appNames,omitempty"` | ||
} | ||
|
||
// AppProfileStatus defines the observed state of AppProfile | ||
type AppProfileStatus struct { | ||
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster | ||
// Important: Run "make" to regenerate code after modifying this file | ||
|
||
// Health values: healthy, degraded | ||
Health string `json:"health,omitempty"` | ||
// Names of apps that don't exist | ||
InvalidAppNames []string `json:"invalidAppNames,omitempty"` | ||
} | ||
|
||
//+kubebuilder:object:root=true | ||
//+kubebuilder:subresource:status | ||
|
||
// AppProfile is the Schema for the appprofiles API | ||
type AppProfile struct { | ||
metav1.TypeMeta `json:",inline"` | ||
metav1.ObjectMeta `json:"metadata,omitempty"` | ||
|
||
Spec AppProfileSpec `json:"spec,omitempty"` | ||
Status AppProfileStatus `json:"status,omitempty"` | ||
} | ||
|
||
//+kubebuilder:object:root=true | ||
|
||
// AppProfileList contains a list of AppProfile | ||
type AppProfileList struct { | ||
metav1.TypeMeta `json:",inline"` | ||
metav1.ListMeta `json:"metadata,omitempty"` | ||
Items []AppProfile `json:"items"` | ||
} | ||
|
||
func init() { | ||
SchemeBuilder.Register(&AppProfile{}, &AppProfileList{}) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package app | ||
|
||
import "github.com/spf13/cobra" | ||
|
||
func NewCommand() *cobra.Command { | ||
command := &cobra.Command{ | ||
Use: "app", | ||
Short: "Manage apps", | ||
Long: "Manage apps", | ||
DisableAutoGenTag: true, | ||
Run: func(c *cobra.Command, args []string) { | ||
c.Usage() | ||
}, | ||
} | ||
command.AddCommand(listAppsCommand()) | ||
command.AddCommand(createAppCommand()) | ||
command.AddCommand(deleteAppCommand()) | ||
return command | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package app | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
appset "github.com/argoproj/argo-cd/v2/pkg/apis/applicationset/v1alpha1" | ||
"github.com/arlonproj/arlon/pkg/app" | ||
"github.com/arlonproj/arlon/pkg/ctrlruntimeclient" | ||
"os" | ||
|
||
"github.com/argoproj/argo-cd/v2/util/cli" | ||
"github.com/spf13/cobra" | ||
"k8s.io/apimachinery/pkg/runtime" | ||
"k8s.io/apimachinery/pkg/runtime/serializer/json" | ||
"k8s.io/client-go/tools/clientcmd" | ||
) | ||
|
||
func createAppCommand() *cobra.Command { | ||
var clientConfig clientcmd.ClientConfig | ||
var argocdNs string | ||
var repoUrl string | ||
var repoRevision string | ||
var repoPath string | ||
var appName string | ||
var destNs string | ||
var project string | ||
var outputYaml bool | ||
var autoSync bool | ||
var autoPrune bool | ||
command := &cobra.Command{ | ||
Use: "create appName repoUrl repoPath [--repo-revision revision][--output-yaml][--autosync][--autoprune][other flags]", | ||
Short: "create new Arlon app", | ||
Long: "create new Arlon app, which is represented as a specialized ArgoCD ApplicationSet resource", | ||
Args: cobra.ExactArgs(3), | ||
RunE: func(c *cobra.Command, args []string) error { | ||
appName = args[0] | ||
repoUrl = args[1] | ||
repoPath = args[2] | ||
app := app.Create(argocdNs, appName, destNs, project, repoPath, repoUrl, repoRevision, autoSync, autoPrune) | ||
if outputYaml { | ||
scheme := runtime.NewScheme() | ||
if err := appset.AddToScheme(scheme); err != nil { | ||
return fmt.Errorf("failed to add scheme: %s", err) | ||
} | ||
s := json.NewSerializerWithOptions(json.DefaultMetaFactory, | ||
scheme, scheme, json.SerializerOptions{ | ||
Yaml: true, | ||
Pretty: true, | ||
Strict: false, | ||
}) | ||
err := s.Encode(&app, os.Stdout) | ||
if err != nil { | ||
return fmt.Errorf("failed to encode arlon app: %s", err) | ||
} | ||
} else { | ||
config, err := clientConfig.ClientConfig() | ||
if err != nil { | ||
return fmt.Errorf("failed to get k8s client config: %s", err) | ||
} | ||
cli, err := ctrlruntimeclient.NewClient(config) | ||
if err != nil { | ||
return fmt.Errorf("failed to get controller runtime client: %s", err) | ||
} | ||
err = cli.Create(context.Background(), &app) | ||
if err != nil { | ||
return fmt.Errorf("failed to create resource: %s", err) | ||
} | ||
} | ||
return nil | ||
}, | ||
} | ||
clientConfig = cli.AddKubectlFlagsToCmd(command) | ||
command.Flags().StringVar(&argocdNs, "argocd-ns", "argocd", "the argocd namespace") | ||
command.Flags().StringVar(&repoRevision, "repo-revision", "HEAD", "the git revision for app template") | ||
command.Flags().StringVar(&destNs, "dest-ns", "default", "destination namespace in target cluster(s)") | ||
command.Flags().StringVar(&project, "project", "default", "ArgoCD project for ApplicationSet representing Arlon app") | ||
command.Flags().BoolVar(&outputYaml, "output-yaml", false, "output YAML instead of deploying to management cluster") | ||
command.Flags().BoolVar(&autoSync, "autosync", true, "enable ArgoCD auto-sync") | ||
command.Flags().BoolVar(&autoPrune, "autoprune", true, "enable ArgoCD auto-prune, only meaningful if auto-sync enabled") | ||
return command | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package app | ||
|
||
import ( | ||
"fmt" | ||
"github.com/argoproj/argo-cd/v2/util/cli" | ||
"github.com/arlonproj/arlon/pkg/app" | ||
"github.com/spf13/cobra" | ||
"k8s.io/client-go/tools/clientcmd" | ||
) | ||
|
||
func deleteAppCommand() *cobra.Command { | ||
var clientConfig clientcmd.ClientConfig | ||
var argocdNs string | ||
var appName string | ||
command := &cobra.Command{ | ||
Use: "delete appName", | ||
Short: "delete existing Arlon app", | ||
Long: "delete existing Arlon app", | ||
Args: cobra.ExactArgs(1), | ||
RunE: func(c *cobra.Command, args []string) error { | ||
appName = args[0] | ||
config, err := clientConfig.ClientConfig() | ||
if err != nil { | ||
return fmt.Errorf("failed to get k8s client config: %s", err) | ||
} | ||
if err = app.Delete(config, argocdNs, appName); err != nil { | ||
return fmt.Errorf("failed to delete arlon app: %s", err) | ||
} | ||
return nil | ||
}, | ||
} | ||
clientConfig = cli.AddKubectlFlagsToCmd(command) | ||
command.Flags().StringVar(&argocdNs, "argocd-ns", "argocd", "the argocd namespace") | ||
return command | ||
} |
Oops, something went wrong.