Skip to content

Commit

Permalink
Moving status to new structure (#475)
Browse files Browse the repository at this point in the history
  • Loading branch information
luizbafilho committed Jul 14, 2021
1 parent 1a994fa commit 8bfd658
Show file tree
Hide file tree
Showing 24 changed files with 712 additions and 674 deletions.
5 changes: 5 additions & 0 deletions api/v1alpha1/application_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,13 @@ type ApplicationSpec struct {
URL string `json:"url,omitempty"`
// Path is the path in the repository where the k8s yaml files for this application are stored.
Path string `json:"path,omitempty"`
// DeploymentType is the deployment method used to apply the manifests
DeploymentType DeploymentType `json:"deployment_type,omitempty"`
}

// +kubebuilder:validation:Enum=helm;kustomize
type DeploymentType string

// ApplicationStatus defines the observed state of Application
type ApplicationStatus struct {
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
Expand Down
51 changes: 42 additions & 9 deletions cmd/wego/app/status/cmd.go
Original file line number Diff line number Diff line change
@@ -1,20 +1,53 @@
package status

import (
"fmt"
"os"

"github.com/spf13/cobra"
"github.com/weaveworks/weave-gitops/pkg/cmdimpl"
"github.com/weaveworks/weave-gitops/pkg/flux"
"github.com/weaveworks/weave-gitops/pkg/git"
"github.com/weaveworks/weave-gitops/pkg/gitproviders"
"github.com/weaveworks/weave-gitops/pkg/kube"
"github.com/weaveworks/weave-gitops/pkg/logger"
"github.com/weaveworks/weave-gitops/pkg/runner"
"github.com/weaveworks/weave-gitops/pkg/services/app"
)

var Cmd = &cobra.Command{
Use: "status <app-name>",
Short: "Get status of an app",
Args: cobra.MinimumNArgs(1),
Example: "wego app status podinfo",
Use: "status <app-name>",
Short: "Get status of an app",
Args: cobra.MinimumNArgs(1),
SilenceUsage: true,
SilenceErrors: true,
Example: "wego app status podinfo",
RunE: func(cmd *cobra.Command, args []string) error {
params.Namespace, _ = cmd.Parent().Parent().Flags().GetString("namespace")
params := app.StatusParams{}

params.Name = args[0]
return cmdimpl.Status(params)
params.Namespace, _ = cmd.Parent().Parent().Flags().GetString("namespace")

cliRunner := &runner.CLIRunner{}
fluxClient := flux.New(cliRunner)
kubeClient, err := kube.NewKubeHTTPClient()
if err != nil {
return fmt.Errorf("error initializing kube client: %w", err)
}

gitClient := git.New(nil)
gitProviders := gitproviders.New()
logger := logger.New(os.Stdout)

appService := app.New(logger, gitClient, fluxClient, kubeClient, gitProviders)

fluxOutput, lastSuccessReconciliation, err := appService.Status(params)
if err != nil {
return fmt.Errorf("failed getting application status: %w", err)
}

logger.Printf("Last successful reconciliation: %s\n\n", lastSuccessReconciliation)
logger.Println(fluxOutput)

return nil
},
}

var params cmdimpl.StatusParams
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ require (
github.com/fluxcd/go-git-providers v0.2.0
github.com/fluxcd/helm-controller/api v0.11.1
github.com/fluxcd/kustomize-controller/api v0.13.0
github.com/fluxcd/pkg/apis/meta v0.10.0 // indirect
github.com/fluxcd/source-controller/api v0.15.2
github.com/go-git/go-billy/v5 v5.3.1
github.com/go-git/go-git/v5 v5.4.1
Expand Down Expand Up @@ -37,6 +38,7 @@ require (
k8s.io/apimachinery v0.21.2
k8s.io/client-go v0.21.2
sigs.k8s.io/controller-runtime v0.9.1
sigs.k8s.io/controller-tools v0.4.1 // indirect
sigs.k8s.io/yaml v1.2.0

)
Expand Down
130 changes: 130 additions & 0 deletions go.sum

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions manifests/crds/wego.weave.works_apps.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ spec:
spec:
description: ApplicationSpec defines the desired state of Application
properties:
deployment_type:
description: DeploymentType is the deployment method used to apply
the manifests
enum:
- helm
- kustomize
type: string
path:
description: Path is the path in the repository where the k8s yaml
files for this application are stored.
Expand Down
13 changes: 0 additions & 13 deletions pkg/cmdimpl/common_test.go

This file was deleted.

38 changes: 0 additions & 38 deletions pkg/cmdimpl/manifests/app-crd.yaml

This file was deleted.

97 changes: 0 additions & 97 deletions pkg/cmdimpl/status.go

This file was deleted.

0 comments on commit 8bfd658

Please sign in to comment.