Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prep for merge #3801

Closed
wants to merge 38 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
11ccaec
rollouts: added top level directory
droot Dec 12, 2022
e7b4b02
rollouts: scaffolded the project using kubebuilder (#3689)
droot Dec 13, 2022
3d05ffd
rollouts: added cluster discovery and selection (#3696)
droot Dec 17, 2022
f03c104
Rollouts package discovery (#3697)
ChristopherFry Dec 21, 2022
10c67e8
rollouts: added remoterootsync API (#3698)
droot Dec 21, 2022
0d08336
rollouts: add package cluster matcher (#3700)
ChristopherFry Dec 22, 2022
f687278
rollouts: add AllAtOnce strategy (#3703)
droot Dec 23, 2022
dc5fd53
rollouts: allow packages to be discovered from multiple repositories …
ChristopherFry Dec 23, 2022
b0ddddd
rollouts: rename packages git source to github (#3708)
ChristopherFry Jan 3, 2023
5186d27
rollouts: allow the root directory of a repository to be synced (#3709)
ChristopherFry Jan 4, 2023
7d70e8b
rollouts: add caching for discovered packages (#3706)
ChristopherFry Jan 5, 2023
64c9b22
rollouts: add rolling update strategy (#3714)
ChristopherFry Jan 6, 2023
3611ff9
rollouts: added API for ProgressiveRolloutStrategy (#3716)
droot Jan 7, 2023
21b5d27
rollouts: refine package to cluster matcher (#3720)
droot Jan 10, 2023
24d5f61
rollouts: implement progressive strategy (#3719)
ChristopherFry Jan 10, 2023
17c121d
rollouts: update progressive strategy to pause after wave (#3721)
ChristopherFry Jan 11, 2023
9b66acd
rollouts: added skeleton CLI (#3724)
droot Jan 11, 2023
cfd0bb1
rollouts: add rollout summary status (#3725)
ChristopherFry Jan 11, 2023
563afce
rollouts: tidy up go.mod/sum (#3726)
droot Jan 12, 2023
e981607
rollouts: duplicate target fix (#3727)
ChristopherFry Jan 12, 2023
ec5e40d
rollouts: sort cluster status list (#3728)
ChristopherFry Jan 12, 2023
c58c4b9
rollouts: conditionally show wave status (#3729)
ChristopherFry Jan 13, 2023
1dd0983
rollouts: CLI now supports displaying waves and progress counts (#3730)
droot Jan 13, 2023
53849a9
rollouts: cli can now advance waves on progressive rollouts (#3731)
ChristopherFry Jan 13, 2023
247cb0d
rollouts: enable server side throttling for cli (#3732)
ChristopherFry Jan 13, 2023
2620f2d
rollouts: add container cluster watch (#3738)
ChristopherFry Jan 19, 2023
7bcd132
rollouts: delete remote root sync when no longer needed (#3742)
ChristopherFry Jan 23, 2023
568a594
Rollouts rebase kpt main (#3750)
droot Jan 24, 2023
54a1390
kpt cli: added rollouts subcommand (#3752)
droot Jan 25, 2023
19c88bf
rollouts: added cluster discovery types (#3753)
droot Jan 25, 2023
29d8cf8
rollouts: added sync template to the rollout API (#3754)
droot Jan 26, 2023
ac90248
rollouts: refactor logic for generating cluster client (#3790)
ChristopherFry Feb 7, 2023
ccb0caa
rollouts: update dockerfile (#3789)
ChristopherFry Feb 7, 2023
f16704c
rollouts: update core logic to be agnostic of exact cluster type (#3791)
ChristopherFry Feb 7, 2023
28f46ec
rollouts: filter wave clusters in process (#3793)
ChristopherFry Feb 7, 2023
1a28e2f
rollouts: implement cluster discovery for gcp fleet (#3792)
ChristopherFry Feb 7, 2023
cba3d75
rollouts: cache gcp fleet rest config host (#3798)
ChristopherFry Feb 8, 2023
469165e
resolved go.mod error
droot Feb 8, 2023
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: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.

go.work
go.work.sum
.DS_Store
.idea/
*.iml
Expand Down
2 changes: 2 additions & 0 deletions commands/alpha/alphacmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"github.com/GoogleContainerTools/kpt/commands/alpha/license"
"github.com/GoogleContainerTools/kpt/commands/alpha/live"
"github.com/GoogleContainerTools/kpt/commands/alpha/repo"
"github.com/GoogleContainerTools/kpt/commands/alpha/rollouts"
"github.com/GoogleContainerTools/kpt/commands/alpha/rpkg"
"github.com/GoogleContainerTools/kpt/commands/alpha/sync"
"github.com/GoogleContainerTools/kpt/commands/alpha/wasm"
Expand Down Expand Up @@ -54,6 +55,7 @@ func GetCommand(ctx context.Context, name, version string) *cobra.Command {
wasm.NewCommand(ctx, version),
live.GetCommand(ctx, "", version),
license.NewCommand(ctx, version),
rollouts.NewCommand(ctx),
)

return alpha
Expand Down
103 changes: 103 additions & 0 deletions commands/alpha/rollouts/advance/advance.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
// Copyright 2023 Google LLC
//
// 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 advance

import (
"context"
"fmt"

"github.com/GoogleContainerTools/kpt/commands/alpha/rollouts/rolloutsclient"
"github.com/GoogleContainerTools/kpt/rollouts/api/v1alpha1"
"github.com/spf13/cobra"
)

func newRunner(ctx context.Context) *runner {
r := &runner{
ctx: ctx,
}
c := &cobra.Command{
Use: "advance rollout-name wave-name",
Short: "advances the wave of a progressive rollout",
Long: "advances the wave of a progressive rollout",
Example: "advances the wave of a progressive rollout",
RunE: r.runE,
}
r.Command = c
return r
}

func NewCommand(ctx context.Context) *cobra.Command {
return newRunner(ctx).Command
}

type runner struct {
ctx context.Context
Command *cobra.Command
}

func (r *runner) runE(cmd *cobra.Command, args []string) error {
rlc, err := rolloutsclient.New()
if err != nil {
fmt.Printf("%s\n", err)
return err
}

if len(args) == 0 {
return fmt.Errorf("must provide rollout name")
}

if len(args) == 1 {
return fmt.Errorf("must provide wave name")
}

rolloutName := args[0]
waveName := args[1]

rollout, err := rlc.Get(r.ctx, rolloutName)
if err != nil {
fmt.Printf("%s\n", err)
return err
}

if rollout.Spec.Strategy.Type != v1alpha1.Progressive {
return fmt.Errorf("rollout must be using the progressive strategy to use this command")
}

if rollout.Status.WaveStatuses != nil {
waveFound := false

for _, waveStatus := range rollout.Status.WaveStatuses {
if waveStatus.Name == waveName {
waveFound = true
break
}
}

if !waveFound {
return fmt.Errorf("wave %q not found in this rollout", waveName)
}
}

rollout.Spec.Strategy.Progressive.PauseAfterWave.WaveName = waveName

err = rlc.Update(r.ctx, rollout)
if err != nil {
fmt.Printf("%s\n", err)
return err
}

fmt.Println("done")
return nil
}
87 changes: 87 additions & 0 deletions commands/alpha/rollouts/get/get.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
// Copyright 2023 Google LLC
//
// 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 get

import (
"context"
"fmt"

"github.com/GoogleContainerTools/kpt/commands/alpha/rollouts/rolloutsclient"
rolloutsapi "github.com/GoogleContainerTools/kpt/rollouts/api/v1alpha1"
"github.com/jedib0t/go-pretty/v6/table"
"github.com/spf13/cobra"
)

func NewCommand(ctx context.Context) *cobra.Command {
return newRunner(ctx).Command
}

func newRunner(ctx context.Context) *runner {
r := &runner{
ctx: ctx,
}
c := &cobra.Command{
Use: "get",
Short: "lists rollouts",
Long: "lists rollouts",
Example: "lists rollouts",
RunE: r.runE,
}
r.Command = c
return r
}

type runner struct {
ctx context.Context
Command *cobra.Command
}

func (r *runner) runE(cmd *cobra.Command, args []string) error {
rlc, err := rolloutsclient.New()
if err != nil {
fmt.Printf("%s\n", err)
return err
}

rollouts, err := rlc.List(r.ctx, "")
if err != nil {
fmt.Printf("%s\n", err)
return err
}
renderRolloutsAsTable(cmd, rollouts)
return nil
}

func renderRolloutsAsTable(cmd *cobra.Command, rollouts *rolloutsapi.RolloutList) {
t := table.NewWriter()
t.SetOutputMirror(cmd.OutOrStdout())
t.AppendHeader(table.Row{"ROLLOUT", "STATUS", "CLUSTERS (READY/TOTAL)"})
for _, rollout := range rollouts.Items {
readyCount := 0
for _, cluster := range rollout.Status.ClusterStatuses {
if cluster.PackageStatus.Status == "Synced" {
readyCount++
}
}
t.AppendRow([]interface{}{
rollout.Name,
rollout.Status.Overall,
fmt.Sprintf("%d/%d", readyCount, len(rollout.Status.ClusterStatuses))})
}
t.AppendSeparator()
// t.AppendRow([]interface{}{300, "Tyrion", "Lannister", 5000})
// t.AppendFooter(table.Row{"", "", "Total", 10000})
t.Render()
}
123 changes: 123 additions & 0 deletions commands/alpha/rollouts/rolloutsclient/client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
// Copyright 2023 Google LLC
//
// 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 rolloutsclient

import (
"context"
"fmt"
"time"

rolloutsapi "github.com/GoogleContainerTools/kpt/rollouts/api/v1alpha1"
coreapi "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/rest"
"sigs.k8s.io/cli-utils/pkg/flowcontrol"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/client/config"
)

// Client implments client for the rollouts API.
type Client struct {
client client.Client
}

func New() (*Client, error) {
scheme, err := createScheme()
if err != nil {
return nil, err
}

config := useServerSideThrottling(config.GetConfigOrDie())
cl, err := client.New(config, client.Options{
Scheme: scheme,
})
if err != nil {
return nil, err
}
return &Client{client: cl}, nil
}

func createScheme() (*runtime.Scheme, error) {
scheme := runtime.NewScheme()

for _, api := range (runtime.SchemeBuilder{
rolloutsapi.AddToScheme,
coreapi.AddToScheme,
metav1.AddMetaToScheme,
}) {
if err := api(scheme); err != nil {
return nil, err
}
}
return scheme, nil
}

func (rlc *Client) List(ctx context.Context, ns string) (*rolloutsapi.RolloutList, error) {
if ns == "" {
ns = "default"
}

rollouts := &rolloutsapi.RolloutList{}
if err := rlc.client.List(context.Background(), rollouts, client.InNamespace(ns)); err != nil {
return nil, err
}

return rollouts, nil
}

func (rlc *Client) Get(ctx context.Context, name string) (*rolloutsapi.Rollout, error) {
if name == "" {
return nil, fmt.Errorf("must provide rollout name")
}

key := types.NamespacedName{
Namespace: "default",
Name: name,
}
rollout := &rolloutsapi.Rollout{}
if err := rlc.client.Get(context.Background(), key, rollout); err != nil {
return nil, err
}

return rollout, nil
}

func (rlc *Client) Update(ctx context.Context, rollout *rolloutsapi.Rollout) error {
if err := rlc.client.Update(context.Background(), rollout); err != nil {
return err
}

return nil
}

func useServerSideThrottling(config *rest.Config) *rest.Config {
// Timeout if the query takes too long
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()

enabled, err := flowcontrol.IsEnabled(ctx, config)
if err != nil {
fmt.Printf("Failed to query apiserver to check for flow control enablement: %v\n", err)
}

if enabled {
config.QPS = -1
config.Burst = -1
}

return config
}
49 changes: 49 additions & 0 deletions commands/alpha/rollouts/rolloutscmd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Copyright 2022 Google LLC
//
// 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 rollouts

import (
"context"

"github.com/GoogleContainerTools/kpt/commands/alpha/rollouts/advance"
"github.com/GoogleContainerTools/kpt/commands/alpha/rollouts/get"
"github.com/GoogleContainerTools/kpt/commands/alpha/rollouts/status"
"github.com/spf13/cobra"
)

func NewCommand(ctx context.Context) *cobra.Command {
rolloutsCmd := &cobra.Command{
Use: "rollouts",
Short: "rollouts",
Long: "rollouts",
RunE: func(cmd *cobra.Command, args []string) error {
h, err := cmd.Flags().GetBool("help")
if err != nil {
return err
}
if h {
return cmd.Help()
}
return cmd.Usage()
},
}

rolloutsCmd.AddCommand(
advance.NewCommand(ctx),
get.NewCommand(ctx),
status.NewCommand(ctx),
)
return rolloutsCmd
}
Loading