-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enabling interoperability between cluster install and cli install (#514)
* Enabling interoperability between cluster install and cli install * Added kapp rule * Since we can't pause by default, we use 10y as syncPeriod * Adding used config to educates-config configmap * Adding command to view config to be applied
- Loading branch information
1 parent
583386c
commit 652f0e3
Showing
12 changed files
with
237 additions
and
36 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
17 changes: 17 additions & 0 deletions
17
carvel-packages/installer/bundle/config/kapp/kapp-config-installer-labels.yaml
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,17 @@ | ||
apiVersion: kapp.k14s.io/v1alpha1 | ||
kind: Config | ||
rebaseRules: | ||
- paths: | ||
- [spec, selector, matchLabels] | ||
type: copy | ||
sources: [existing, new] | ||
resourceMatchers: | ||
- apiVersionKindMatcher: { apiVersion: apps/v1, kind: DaemonSet } | ||
- apiVersionKindMatcher: { apiVersion: apps/v1, kind: Deployment } | ||
- paths: | ||
- [spec, selector] | ||
type: copy | ||
sources: [existing, new] | ||
resourceMatchers: | ||
- apiVersionKindMatcher: { apiVersion: v1, kind: Service } | ||
- apiVersionKindMatcher: { apiVersion: apps/v1, kind: Deployment } |
17 changes: 17 additions & 0 deletions
17
carvel-packages/installer/bundle/config/ytt/_ytt_lib/config/functions.star
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,17 @@ | ||
load("@ytt:struct", "struct") | ||
|
||
def removeNulls(data): | ||
# Iterate over a struct of scalar values and return only those where value is not null | ||
filtered_data = {} | ||
for key in struct.decode(data): | ||
value = getattr(data, key, None) | ||
if type(value) == "struct": | ||
value = removeNulls(value) | ||
end | ||
if value: #! This means that value is not an empty string, dict, struct, ... | ||
filtered_data[key] = value | ||
end | ||
end | ||
return struct.encode(filtered_data) | ||
end | ||
|
11 changes: 8 additions & 3 deletions
11
carvel-packages/installer/bundle/config/ytt/_ytt_lib/config/save-config-overlay.yaml
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 |
---|---|---|
@@ -1,17 +1,22 @@ | ||
#@ load("@ytt:overlay", "overlay") | ||
#@ load("@ytt:data", "data") | ||
#@ load("@ytt:yaml", "yaml") | ||
#@ load("functions.star", "removeNulls") | ||
|
||
#! We create educates namespace in case educates package is not enabled | ||
#@ if/end not data.values.values.clusterPackages.educates.enabled: | ||
--- | ||
apiVersion: v1 | ||
kind: Namespace | ||
metadata: | ||
name: educates-config | ||
name: educates | ||
|
||
--- | ||
apiVersion: v1 | ||
kind: ConfigMap | ||
metadata: | ||
name: educates-config | ||
namespace: educates-config | ||
namespace: educates | ||
data: | ||
values.yaml: #@ yaml.encode(data.values) | ||
config.yaml: #@ yaml.encode(removeNulls(data.values.config)) | ||
values.yaml: #@ yaml.encode(data.values.values) |
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 was deleted.
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
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,133 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/spf13/cobra" | ||
|
||
"github.com/vmware-tanzu-labs/educates-training-platform/client-programs/pkg/config" | ||
"github.com/vmware-tanzu-labs/educates-training-platform/client-programs/pkg/installer" | ||
) | ||
|
||
var ( | ||
adminPlatformConfigExample = ` | ||
# Show configuration config for local deployment | ||
educates admin platform config --local-config | ||
# Show configuration config for specific config file | ||
educates admin platform config --config config.yaml | ||
# Get configuration used to deploy to the current cluster | ||
educates admin platform config --from-cluster | ||
educates admin platform config --from-cluster --kubeconfig /path/to/kubeconfig --context my-cluster | ||
# Get configuration config using locally built educates package (version latest does the same and skips image resolution) | ||
educates admin platform config --config config.yaml --package-repository localhost:5001 --version 0.0.1 | ||
educates admin platform config --config config.yaml --version latest | ||
# Get configuration config with different domain (to make copies of the config) | ||
educates admin platform config --local-config --domain cluster1.dev.educates.io > cluster1-config.yaml | ||
educates admin platform config --config config.yaml --domain cluster2.dev.educates.io > cluster2-config.yaml | ||
` | ||
) | ||
|
||
type PkatformConfigOptions struct { | ||
KubeconfigOptions | ||
Domain string | ||
Version string | ||
PackageRepository string | ||
LocalConfig bool | ||
FromCluster bool | ||
Verbose bool | ||
} | ||
|
||
func (o *PkatformConfigOptions) Run() error { | ||
installer := installer.NewInstaller() | ||
|
||
if o.FromCluster { | ||
config, err := installer.GetConfigFromCluster(o.Kubeconfig, o.Context) | ||
if err != nil { | ||
return err | ||
} | ||
fmt.Println(config) | ||
} else { | ||
fullConfig, err := config.ConfigForLocalClusters("", o.Domain, o.LocalConfig) | ||
|
||
if err != nil { | ||
return err | ||
} | ||
|
||
config.PrintConfigToStdout(fullConfig) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (p *ProjectInfo) NewAdminPlatformConfigCmd() *cobra.Command { | ||
var o PkatformConfigOptions | ||
|
||
var c = &cobra.Command{ | ||
Args: cobra.NoArgs, | ||
Use: "config", | ||
Short: "Show config used when deploying the platform", | ||
RunE: func(cmd *cobra.Command, _ []string) error { | ||
return o.Run() | ||
}, | ||
Example: adminPlatformConfigExample, | ||
} | ||
|
||
c.Flags().StringVar( | ||
&o.Kubeconfig, | ||
"kubeconfig", | ||
"", | ||
"kubeconfig file to use instead of $KUBECONFIG or $HOME/.kube/config", | ||
) | ||
c.Flags().StringVar( | ||
&o.Context, | ||
"context", | ||
"", | ||
"Context to use from Kubeconfig", | ||
) | ||
c.Flags().StringVar( | ||
&o.Domain, | ||
"domain", | ||
"", | ||
"wildcard ingress subdomain name for Educates", | ||
) | ||
c.Flags().BoolVar( | ||
&o.Verbose, | ||
"verbose", | ||
false, | ||
"print verbose output", | ||
) | ||
c.Flags().StringVar( | ||
&o.PackageRepository, | ||
"package-repository", | ||
p.ImageRepository, | ||
"image repository hosting package bundles", | ||
) | ||
c.Flags().StringVar( | ||
&o.Version, | ||
"version", | ||
p.Version, | ||
"version to be installed", | ||
) | ||
c.Flags().BoolVar( | ||
&o.LocalConfig, | ||
"local-config", | ||
false, | ||
"Use local configuration. When used, --config and --domain flags are ignored", | ||
) | ||
// TODO: From cluster | ||
c.Flags().BoolVar( | ||
&o.FromCluster, | ||
"from-cluster", | ||
false, | ||
"Show the configuration (from the cluster) used when the plaform was deployed", | ||
) | ||
|
||
c.MarkFlagsMutuallyExclusive("local-config", "from-cluster") | ||
c.MarkFlagsOneRequired("local-config", "from-cluster") | ||
|
||
return c | ||
} |
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