Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into pr/Aryakoste/874
Browse files Browse the repository at this point in the history
  • Loading branch information
kosmoz committed Jul 1, 2024
2 parents cb0aff6 + ddd0e07 commit 62fc685
Show file tree
Hide file tree
Showing 89 changed files with 4,813 additions and 1,612 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/semantic-pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ jobs:
semantic-message:
runs-on: ubuntu-latest
steps:
- uses: amannn/action-semantic-pull-request@e32d7e603df1aa1ba07e981f2a23455dee596825 # v5
- uses: amannn/action-semantic-pull-request@0723387faaf9b38adef4775cd42cfd5155ed6017 # v5
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2 changes: 1 addition & 1 deletion .release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
".": "0.10.1"
".": "0.11.0"
}
28 changes: 28 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,33 @@
# Changelog

## [0.11.0](https://github.com/glasskube/glasskube/compare/v0.10.1...v0.11.0) (2024-06-27)


### Features

* **cli:** add ascii art on glasskube version ([#879](https://github.com/glasskube/glasskube/issues/879)) ([3040ab1](https://github.com/glasskube/glasskube/commit/3040ab10f156a551c1bcbbaa06c79e819460dad3))


### Bug Fixes

* **cli:** standardize usage texts ([#848](https://github.com/glasskube/glasskube/issues/848)) ([7d23c1e](https://github.com/glasskube/glasskube/commit/7d23c1e638c406e827a25388a56efd0707eeecac))
* **deps:** update module github.com/yuin/goldmark to v1.7.4 ([#868](https://github.com/glasskube/glasskube/issues/868)) ([d7ce5fa](https://github.com/glasskube/glasskube/commit/d7ce5fa72434e93720a9681279e8ad3e5e058cfe))
* **open:** fix typo in service name candidate ([#885](https://github.com/glasskube/glasskube/issues/885)) ([921d049](https://github.com/glasskube/glasskube/commit/921d049ff4f3575ee863a1f2ed3f5b78ea94bf47))


### Other

* **website:** configure eslint with docusaurus, react-ts and prettier plugins ([#858](https://github.com/glasskube/glasskube/issues/858)) ([613cbb7](https://github.com/glasskube/glasskube/commit/613cbb728da7cd1329b75b3148b17c2cb01ea50b))


### Docs

* exchange static image with gif ([#862](https://github.com/glasskube/glasskube/issues/862)) ([946baf4](https://github.com/glasskube/glasskube/commit/946baf46f4872ed2b45188dfb378ed0f2df6cb24))
* **website:** exchange repo mockup with actual screenshots ([#852](https://github.com/glasskube/glasskube/issues/852)) ([8adf8fb](https://github.com/glasskube/glasskube/commit/8adf8fb8e20f29e635eb9ce812338dd068f297bb))
* **website:** fix broken link ([#886](https://github.com/glasskube/glasskube/issues/886)) ([146dc25](https://github.com/glasskube/glasskube/commit/146dc25b11771cb81aa782fa9ec4895bccdd4a07))
* **website:** fix typo ([#878](https://github.com/glasskube/glasskube/issues/878)) ([e6ebb8c](https://github.com/glasskube/glasskube/commit/e6ebb8c16b3f41976e41b86ed5d4d130ed80fa32))
* **website:** glasskube is backed by Y Combinator ([#853](https://github.com/glasskube/glasskube/issues/853)) ([05e2ef7](https://github.com/glasskube/glasskube/commit/05e2ef7ce37af1ee31618dbb49258ab45d3a8a37))

## [0.10.1](https://github.com/glasskube/glasskube/compare/v0.10.0...v0.10.1) (2024-06-24)


Expand Down
8 changes: 8 additions & 0 deletions api/v1alpha1/package_manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,14 @@ func (PackageScope) JSONSchema() *jsonschema.Schema {
}
}

func (s *PackageScope) IsCluster() bool {
return s == nil || *s == ScopeCluster
}

func (s *PackageScope) IsNamespaced() bool {
return s != nil && *s == ScopeNamespaced
}

type PackageManifest struct {
// Scope is optional (default is Cluster)
Scope *PackageScope `json:"scope,omitempty"`
Expand Down
109 changes: 84 additions & 25 deletions cmd/glasskube/cmd/auto-update.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,24 @@ import (
"github.com/glasskube/glasskube/api/v1alpha1"
"github.com/glasskube/glasskube/internal/cliutils"
"github.com/glasskube/glasskube/internal/config"
"github.com/glasskube/glasskube/internal/controller/ctrlpkg"
"github.com/glasskube/glasskube/pkg/statuswriter"
"github.com/glasskube/glasskube/pkg/update"
"github.com/spf13/cobra"
"go.uber.org/multierr"
)

var autoUpdateEnabledDisabledOptions = struct{ Yes, All bool }{}
var autoUpdateEnabledDisabledOptions = struct {
Yes, All bool
KindOptions
NamespaceOptions
}{
KindOptions: DefaultKindOptions(),
}

var autoUpdateEnableCmd = &cobra.Command{
Use: "enable [...package]",
Short: "Enable automatic updates for packages",
Short: "Enable automatic updates for packages:",
PreRun: cliutils.SetupClientContext(true, &rootCmdOptions.SkipUpdateCheck),
ValidArgsFunction: completeInstalledPackageNames,
Run: runAutoUpdateEnableOrDisable(true,
Expand All @@ -27,8 +34,8 @@ var autoUpdateEnableCmd = &cobra.Command{

var autoUpdateDisableCmd = &cobra.Command{
Use: "disable [...package]",
Short: "Disable automatic updates for packages",
PreRun: cliutils.SetupClientContext(true, &rootCmdOptions.SkipUpdateCheck),
Short: "Disable automatic updates for packages:",
PreRun: cliutils.SetupClientContext(false, &rootCmdOptions.SkipUpdateCheck),
ValidArgsFunction: completeInstalledPackageNames,
Run: runAutoUpdateEnableOrDisable(false,
"Enable automatic updates for the following packages", "Automatic updates disabled"),
Expand All @@ -38,38 +45,68 @@ func runAutoUpdateEnableOrDisable(enabled bool, confirmMsg, successMsg string) f
return func(cmd *cobra.Command, args []string) {
ctx := cmd.Context()
client := cliutils.PackageClient(ctx)
var pkgs []v1alpha1.ClusterPackage
var pkgs []ctrlpkg.Package
if autoUpdateEnabledDisabledOptions.All {
if len(args) > 0 {
fmt.Fprintf(os.Stderr, "Too many arguments: %v\n", args)
cliutils.ExitWithError()
}
var pkgList v1alpha1.ClusterPackageList
if err := client.ClusterPackages().GetAll(ctx, &pkgList); err != nil {
fmt.Fprintf(os.Stderr, "Could not list packages: %v", err)
cliutils.ExitWithError()
if autoUpdateEnabledDisabledOptions.Kind != KindPackage && autoUpdateEnabledDisabledOptions.Namespace == "" {
var pkgList v1alpha1.ClusterPackageList
if err := client.ClusterPackages().GetAll(ctx, &pkgList); err != nil {
fmt.Fprintf(os.Stderr, "Could not list packages: %v", err)
cliutils.ExitWithError()
}
for i := range pkgList.Items {
pkgs = append(pkgs, &pkgList.Items[i])
}
}
if autoUpdateEnabledDisabledOptions.Kind != KindClusterPackage {
var pkgList v1alpha1.PackageList
if err := client.Packages(autoUpdateEnabledDisabledOptions.Namespace).
GetAll(ctx, &pkgList); err != nil {
fmt.Fprintf(os.Stderr, "Could not list packages: %v", err)
cliutils.ExitWithError()
}
for i := range pkgList.Items {
pkgs = append(pkgs, &pkgList.Items[i])
}
}
pkgs = pkgList.Items
for _, pkg := range pkgs {
args = append(args, pkg.Name)
args = append(args, pkg.GetName())
}
} else {
if len(args) == 0 {
fmt.Fprintln(os.Stderr, "Please specify at least one package")
cliutils.ExitWithError()
}
pkgs = make([]v1alpha1.ClusterPackage, len(args))
pkgs = make([]ctrlpkg.Package, len(args))
for i, name := range args {
var pkg v1alpha1.ClusterPackage
if err := client.ClusterPackages().Get(ctx, name, &pkg); err != nil {
pkg, err := getPackageOrClusterPackage(ctx, name,
autoUpdateEnabledDisabledOptions.KindOptions,
autoUpdateEnabledDisabledOptions.NamespaceOptions)
if err != nil {
fmt.Fprintf(os.Stderr, "Could not get package %v: %v", name, err)
cliutils.ExitWithError()
}
pkgs[i] = pkg
}
}

fmt.Fprintf(os.Stderr, "%v: %v\n", confirmMsg, strings.Join(args, ", "))
if len(pkgs) == 0 {
fmt.Fprintln(os.Stderr, "Nothing to do")
cliutils.ExitSuccess()
}

fmt.Fprintln(os.Stderr, confirmMsg)
for _, pkg := range pkgs {
if pkg.IsNamespaceScoped() {
fmt.Fprintf(os.Stderr, " * %v (Package in namespace %v with type %v)\n",
pkg.GetName(), pkg.GetNamespace(), pkg.GetSpec().PackageInfo.Name)
} else {
fmt.Fprintf(os.Stderr, " * %v (ClusterPackage)\n", pkg.GetName())
}
}
if !autoUpdateEnabledDisabledOptions.Yes && !cliutils.YesNoPrompt("Continue?", true) {
cancel()
}
Expand All @@ -78,7 +115,14 @@ func runAutoUpdateEnableOrDisable(enabled bool, confirmMsg, successMsg string) f
for _, pkg := range pkgs {
if pkg.AutoUpdatesEnabled() != enabled {
pkg.SetAutoUpdatesEnabled(enabled)
multierr.AppendInto(&err, client.ClusterPackages().Update(ctx, &pkg))
switch pkg := pkg.(type) {
case *v1alpha1.ClusterPackage:
multierr.AppendInto(&err, client.ClusterPackages().Update(ctx, pkg))
case *v1alpha1.Package:
multierr.AppendInto(&err, client.Packages(pkg.Namespace).Update(ctx, pkg))
default:
panic("unexpected type")
}
}
}
if err != nil {
Expand Down Expand Up @@ -107,36 +151,49 @@ func runAutoUpdate(cmd *cobra.Command, args []string) {
updater := update.NewUpdater(ctx).
WithStatusWriter(statuswriter.Stderr())

var pkgs v1alpha1.ClusterPackageList
if err := client.ClusterPackages().GetAll(ctx, &pkgs); err != nil {
var pkgs []ctrlpkg.Package

var cpkgList v1alpha1.ClusterPackageList
if err := client.ClusterPackages().GetAll(ctx, &cpkgList); err != nil {
panic(err)
}

for i, pkg := range cpkgList.Items {
if pkg.AutoUpdatesEnabled() {
pkgs = append(pkgs, &cpkgList.Items[i])
}
}

var pkgList v1alpha1.PackageList
if err := client.Packages("").GetAll(ctx, &pkgList); err != nil {
panic(err)
}

var packageNames []string
for _, pkg := range pkgs.Items {
for i, pkg := range pkgList.Items {
if pkg.AutoUpdatesEnabled() {
packageNames = append(packageNames, pkg.Name)
pkgs = append(pkgs, &pkgList.Items[i])
}
}
if len(packageNames) == 0 {

if len(pkgs) == 0 {
fmt.Fprintln(os.Stderr, "Automatic updates must be enabled for at least one package")
cliutils.ExitSuccess()
}

tx, err := updater.Prepare(ctx, packageNames)
tx, err := updater.Prepare(ctx, update.GetExact(pkgs))
if err != nil {
fmt.Fprintf(os.Stderr, "Error preparing update: %v\n", err)
cliutils.ExitWithError()
}
printTransaction(*tx)

if updated, err := updater.Apply(ctx, tx); err != nil {
if updated, err := updater.ApplyBlocking(ctx, tx); err != nil {
fmt.Fprintf(os.Stderr, "Error applying update: %v\n", err)
cliutils.ExitWithError()
} else {
updatedNames := make([]string, len(updated))
for i := range updated {
updatedNames[i] = updated[i].Name
updatedNames[i] = updated[i].GetName()
}
fmt.Fprintf(os.Stderr, "Updated packages: %v\n", strings.Join(updatedNames, ", "))
}
Expand All @@ -150,6 +207,8 @@ func init() {
autoUpdateEnabledDisabledOptions.Yes, "do not ask for confirmation")
cmd.Flags().BoolVar(&autoUpdateEnabledDisabledOptions.All, "all",
autoUpdateEnabledDisabledOptions.All, "set for all packages")
autoUpdateEnabledDisabledOptions.KindOptions.AddFlagsToCommand(cmd)
autoUpdateEnabledDisabledOptions.NamespaceOptions.AddFlagsToCommand(cmd)
autoUpdateCmd.AddCommand(cmd)
}
RootCmd.AddCommand(autoUpdateCmd)
Expand Down
14 changes: 12 additions & 2 deletions cmd/glasskube/cmd/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type bootstrapOptions struct {
force bool
createDefaultRepository bool
yes bool
dryRun bool
OutputOptions
}

Expand Down Expand Up @@ -76,14 +77,20 @@ var bootstrapCmd = &cobra.Command{
}
}

if bootstrapCmdOptions.dryRun {
fmt.Fprintln(os.Stderr,
"🔎 Dry-run mode is enabled. "+
"Nothing will be changed in your cluster, but validations will still be run.")
}

verifyLegalUpdate(ctx, installedVersion, targetVersion)

manifests, err := client.Bootstrap(ctx, bootstrapCmdOptions.asBootstrapOptions())
if err != nil {
fmt.Fprintf(os.Stderr, "\nAn error occurred during bootstrap:\n%v\n", err)
cliutils.ExitWithError()
}
if err := printBootsrap(
if err := printBootstrap(
manifests,
bootstrapCmdOptions.Output,
); err != nil {
Expand All @@ -101,10 +108,11 @@ func (o bootstrapOptions) asBootstrapOptions() bootstrap.BootstrapOptions {
DisableTelemetry: o.disableTelemetry,
Force: o.force,
CreateDefaultRepository: o.createDefaultRepository,
DryRun: o.dryRun,
}
}

func printBootsrap(manifests []unstructured.Unstructured, output OutputFormat) error {
func printBootstrap(manifests []unstructured.Unstructured, output OutputFormat) error {
if output != "" {
if err := convertAndPrintManifests(manifests, output); err != nil {
return err
Expand Down Expand Up @@ -221,6 +229,8 @@ func init() {
bootstrapCmd.Flags().BoolVar(&bootstrapCmdOptions.createDefaultRepository, "create-default-repository",
bootstrapCmdOptions.createDefaultRepository,
"Toggle creation of the default glasskube package repository")
bootstrapCmd.PersistentFlags().BoolVar(&bootstrapCmdOptions.dryRun, "dry-run", false,
"Do not make any changes but run all validations")
bootstrapCmd.Flags().BoolVar(&bootstrapCmdOptions.yes, "yes", false, "Skip confirmation prompt")
bootstrapCmd.MarkFlagsMutuallyExclusive("url", "type")
bootstrapCmd.MarkFlagsMutuallyExclusive("url", "latest")
Expand Down
7 changes: 3 additions & 4 deletions cmd/glasskube/cmd/configure.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ var configureCmdOptions = struct {
}

var configureCmd = &cobra.Command{
Use: "configure [package-name]",
Use: "configure <package-name>",
Short: "Configure a package",
Args: cobra.ExactArgs(1),
PreRun: cliutils.SetupClientContext(true, &rootCmdOptions.SkipUpdateCheck),
Expand Down Expand Up @@ -132,8 +132,7 @@ func runConfigure(cmd *cobra.Command, args []string) {
func init() {
configureCmdOptions.ValuesOptions.AddFlagsToCommand(configureCmd)
configureCmdOptions.OutputOptions.AddFlagsToCommand(configureCmd)
// TODO: Enable these flags to support namespaced packages
// configureCmdOptions.NamespaceOptions.AddFlagsToCommand(configureCmd)
// configureCmdOptions.KindOptions.AddFlagsToCommand(configureCmd)
configureCmdOptions.NamespaceOptions.AddFlagsToCommand(configureCmd)
configureCmdOptions.KindOptions.AddFlagsToCommand(configureCmd)
RootCmd.AddCommand(configureCmd)
}
Loading

0 comments on commit 62fc685

Please sign in to comment.