Skip to content

Commit

Permalink
Merge pull request #850 from jlandowner/Domain
Browse files Browse the repository at this point in the history
  • Loading branch information
oruharo authored Jul 21, 2024
2 parents 32a4f82 + a6686d0 commit 853598c
Show file tree
Hide file tree
Showing 12 changed files with 18 additions and 34 deletions.
2 changes: 2 additions & 0 deletions cmd/controller-manager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ MIT 2023 cosmo-workspace/cosmo
Client: mgr.GetClient(),
Recorder: mgr.GetEventRecorderFor(instController),
Scheme: mgr.GetScheme(),
Domain: o.TraefikIngressRouteCfg.Domain,
}).SetupWithManager(mgr, controllerFieldManager); err != nil {
setupLog.Error(err, "unable to create controller", "controller", instController)
os.Exit(1)
Expand All @@ -132,6 +133,7 @@ MIT 2023 cosmo-workspace/cosmo
Client: mgr.GetClient(),
Recorder: mgr.GetEventRecorderFor(clusterInstController),
Scheme: mgr.GetScheme(),
Domain: o.TraefikIngressRouteCfg.Domain,
}).SetupWithManager(mgr, controllerFieldManager); err != nil {
setupLog.Error(err, "unable to create controller", "controller", clusterInstController)
os.Exit(1)
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/template/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ func (o *validateOption) RunE(cmd *cobra.Command, args []string) error {
o.Logr.Info("smoke test: create dummy instance to apply each resources", "instance", dummyInst.GetName())
o.Logr.Debug().DumpObject(o.KosmoClient.Scheme(), &dummyInst, "test instance")

builts, err := template.BuildObjects(o.tmpl.Spec, &dummyInst)
builts, err := template.BuildObjects(o.tmpl.Spec, &dummyInst, "dummy.example.com")
if err != nil {
return fmt.Errorf("failed to build test instance: %w", err)
}
Expand Down
3 changes: 2 additions & 1 deletion internal/controllers/cluster_instance_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type ClusterInstanceReconciler struct {
client.Client
Recorder record.EventRecorder
Scheme *runtime.Scheme
Domain string

impl instanceReconciler
}
Expand Down Expand Up @@ -53,7 +54,7 @@ func (r *ClusterInstanceReconciler) Reconcile(ctx context.Context, req ctrl.Requ
inst.Status.TemplateResourceVersion = tmpl.ResourceVersion

// 1. Build Unstructured objects
objects, err := template.BuildObjects(tmpl.Spec, &inst)
objects, err := template.BuildObjects(tmpl.Spec, &inst, r.Domain)
if err != nil {
kosmo.InstanceEventf(r.Recorder, &inst, corev1.EventTypeWarning, "BuildFailed", "Failed to build manifests from Template: %v", err)
return ctrl.Result{}, err
Expand Down
3 changes: 2 additions & 1 deletion internal/controllers/instance_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type InstanceReconciler struct {
client.Client
Recorder record.EventRecorder
Scheme *runtime.Scheme
Domain string

impl instanceReconciler
}
Expand Down Expand Up @@ -63,7 +64,7 @@ func (r *InstanceReconciler) Reconcile(ctx context.Context, req ctrl.Request) (c
inst.Status.TemplateResourceVersion = tmpl.ResourceVersion

// 1. Build Unstructured objects
objects, err := template.BuildObjects(tmpl.Spec, &inst)
objects, err := template.BuildObjects(tmpl.Spec, &inst, r.Domain)
if err != nil {
kosmo.InstanceEventf(r.Recorder, &inst, corev1.EventTypeWarning, "BuildFailed", "Failed to build manifests from Template: %v", err)
return ctrl.Result{}, err
Expand Down
2 changes: 1 addition & 1 deletion internal/webhooks/instance_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ func (h *InstanceValidationWebhookHandler) Handle(ctx context.Context, req admis
func dryrunReconcile(ctx context.Context, c client.Client, fieldManager string, inst cosmov1alpha1.InstanceObject, tmpl cosmov1alpha1.TemplateObject) []error {
log := clog.FromContext(ctx).WithCaller()

objects, err := template.BuildObjects(*tmpl.GetSpec(), inst)
objects, err := template.BuildObjects(*tmpl.GetSpec(), inst, "dummy.example.com")
if err != nil {
return []error{err}
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/template/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ type Builder interface {
Build() ([]unstructured.Unstructured, error)
}

func BuildObjects(tmplSpec cosmov1alpha1.TemplateSpec, inst cosmov1alpha1.InstanceObject) (objects []unstructured.Unstructured, err error) {
func BuildObjects(tmplSpec cosmov1alpha1.TemplateSpec, inst cosmov1alpha1.InstanceObject, domain string) (objects []unstructured.Unstructured, err error) {
if tmplSpec.RawYaml != "" {
objects, err = NewRawYAMLBuilder(tmplSpec.RawYaml).
ReplaceDefaultVars(inst).
ReplaceDefaultVars(inst, domain).
ReplaceCustomVars(inst).
Build()
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/template/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ spec:
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
gotObjects, err := BuildObjects(tt.args.tmplSpec, tt.args.inst)
gotObjects, err := BuildObjects(tt.args.tmplSpec, tt.args.inst, "dummy.example.com")
if (err != nil) != tt.wantErr {
t.Errorf("BuildObjects() error = %v, wantErr %v", err, tt.wantErr)
return
Expand Down
4 changes: 3 additions & 1 deletion pkg/template/rawyaml.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const (
DefaultVarsInstance = "{{INSTANCE}}"
DefaultVarsNamespace = "{{NAMESPACE}}"
DefaultVarsTemplate = "{{TEMPLATE}}"
DefaultVarsDomain = "{{DOMAIN}}"
)

var (
Expand Down Expand Up @@ -47,9 +48,10 @@ func (t *RawYAMLBuilder) Build() ([]unstructured.Unstructured, error) {
return resources, nil
}

func (t *RawYAMLBuilder) ReplaceDefaultVars(inst cosmov1alpha1.InstanceObject) *RawYAMLBuilder {
func (t *RawYAMLBuilder) ReplaceDefaultVars(inst cosmov1alpha1.InstanceObject, domain string) *RawYAMLBuilder {
t.rawYaml = strings.ReplaceAll(t.rawYaml, DefaultVarsInstance, inst.GetName())
t.rawYaml = strings.ReplaceAll(t.rawYaml, DefaultVarsTemplate, inst.GetSpec().Template.Name)
t.rawYaml = strings.ReplaceAll(t.rawYaml, DefaultVarsDomain, domain)

if inst.GetScope() == meta.RESTScopeNamespace {
t.rawYaml = strings.ReplaceAll(t.rawYaml, DefaultVarsNamespace, inst.GetNamespace())
Expand Down
2 changes: 1 addition & 1 deletion pkg/template/rawyaml_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ func TestRawYAMLBuilder_ReplaceDefaultVars(t *testing.T) {
tr := &RawYAMLBuilder{
rawYaml: tt.fields.rawYaml,
}
if got := tr.ReplaceDefaultVars(tt.fields.inst); !reflect.DeepEqual(got, tt.want) {
if got := tr.ReplaceDefaultVars(tt.fields.inst, "dummy.example.com"); !reflect.DeepEqual(got, tt.want) {
t.Errorf("RawYAMLBuilder.ReplaceDefaultVars() = %v, want %v", got, tt.want)
}
})
Expand Down
9 changes: 3 additions & 6 deletions web/dashboard-ui/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { ProgressProvider } from "./components/ProgressProvider";
import { AuthenticatorManageDialogContext } from "./views/organisms/AuthenticatorManageDialog";
import { EventDetailDialogContext } from "./views/organisms/EventDetailDialog";
import { PasswordChangeDialogContext } from "./views/organisms/PasswordChangeDialog";
import { UserAddonChangeDialogContext } from "./views/organisms/UserAddonsChangeDialog";
import { UserInfoDialogContext } from "./views/organisms/UserInfoDialog";
import { UserContext } from "./views/organisms/UserModule";
import { UserNameChangeDialogContext } from "./views/organisms/UserNameChangeDialog";
Expand Down Expand Up @@ -102,11 +101,9 @@ function App() {
<UserInfoDialogContext.Provider>
<AuthenticatorManageDialogContext.Provider>
<UserNameChangeDialogContext.Provider>
<UserAddonChangeDialogContext.Provider>
<PasswordChangeDialogContext.Provider>
<SwitchApp />
</PasswordChangeDialogContext.Provider>
</UserAddonChangeDialogContext.Provider>
<PasswordChangeDialogContext.Provider>
<SwitchApp />
</PasswordChangeDialogContext.Provider>
</UserNameChangeDialogContext.Provider>
</AuthenticatorManageDialogContext.Provider>
</UserInfoDialogContext.Provider>
Expand Down
1 change: 0 additions & 1 deletion web/dashboard-ui/src/views/pages/UserPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ const UserMenu: React.VFC<{ user: User }> = ({ user: us }) => {
<Box>
<IconButton
color="inherit"
disabled={loginUser?.name === us.name}
onClick={(e) => setAnchorEl(e.currentTarget)}
>
<MoreVert fontSize="small" />
Expand Down
18 changes: 0 additions & 18 deletions web/dashboard-ui/src/views/templates/PageTemplate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
Menu as MenuIcon,
Notifications,
ReportProblem,
Settings,
SupervisorAccountTwoTone,
VpnKey,
Warning,
Expand Down Expand Up @@ -51,7 +50,6 @@ import { AuthenticatorManageDialogContext } from "../organisms/AuthenticatorMana
import { EventDetailDialogContext } from "../organisms/EventDetailDialog";
import { latestTime } from "../organisms/EventModule";
import { PasswordChangeDialogContext } from "../organisms/PasswordChangeDialog";
import { UserAddonChangeDialogContext } from "../organisms/UserAddonsChangeDialog";
import { UserInfoDialogContext } from "../organisms/UserInfoDialog";
import {
isAdminRole,
Expand Down Expand Up @@ -101,8 +99,6 @@ export const PageTemplate: React.FC<
AuthenticatorManageDialogContext.useDispatch();
const passwordChangeDialogDispach = PasswordChangeDialogContext.useDispatch();
const userNameChangeDialogDispach = UserNameChangeDialogContext.useDispatch();
const userAddonChangeDialogDispatch =
UserAddonChangeDialogContext.useDispatch();
const userInfoDialogDispatch = UserInfoDialogContext.useDispatch();
const isAdmin = isAdminUser(loginUser);
const isSignIn = Boolean(loginUser);
Expand Down Expand Up @@ -132,12 +128,6 @@ export const PageTemplate: React.FC<
setAnchorEl(null);
};

const changeAddons = () => {
console.log("changeAddons");
userAddonChangeDialogDispatch(true, { user: loginUser! });
setAnchorEl(null);
};

const openUserInfoDialog = () => {
console.log("openUserInfoDialog");
userInfoDialogDispatch(true, {
Expand Down Expand Up @@ -443,14 +433,6 @@ export const PageTemplate: React.FC<
<ListItemText>Change DisplayName...</ListItemText>
</MenuItem>
)}
{isSignIn && isAdmin && (
<MenuItem onClick={() => changeAddons()}>
<ListItemIcon>
<Settings fontSize="small" />
</ListItemIcon>
<ListItemText>Change Addons...</ListItemText>
</MenuItem>
)}
<Divider />
{isSignIn && (
<MenuItem onClick={() => logout()}>
Expand Down

0 comments on commit 853598c

Please sign in to comment.