Skip to content

Commit 853598c

Browse files
authoredJul 21, 2024
Merge pull request #850 from jlandowner/Domain
2 parents 32a4f82 + a6686d0 commit 853598c

File tree

12 files changed

+18
-34
lines changed

12 files changed

+18
-34
lines changed
 

‎cmd/controller-manager/main.go

+2
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ MIT 2023 cosmo-workspace/cosmo
115115
Client: mgr.GetClient(),
116116
Recorder: mgr.GetEventRecorderFor(instController),
117117
Scheme: mgr.GetScheme(),
118+
Domain: o.TraefikIngressRouteCfg.Domain,
118119
}).SetupWithManager(mgr, controllerFieldManager); err != nil {
119120
setupLog.Error(err, "unable to create controller", "controller", instController)
120121
os.Exit(1)
@@ -132,6 +133,7 @@ MIT 2023 cosmo-workspace/cosmo
132133
Client: mgr.GetClient(),
133134
Recorder: mgr.GetEventRecorderFor(clusterInstController),
134135
Scheme: mgr.GetScheme(),
136+
Domain: o.TraefikIngressRouteCfg.Domain,
135137
}).SetupWithManager(mgr, controllerFieldManager); err != nil {
136138
setupLog.Error(err, "unable to create controller", "controller", clusterInstController)
137139
os.Exit(1)

‎internal/cmd/template/validate.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ func (o *validateOption) RunE(cmd *cobra.Command, args []string) error {
169169
o.Logr.Info("smoke test: create dummy instance to apply each resources", "instance", dummyInst.GetName())
170170
o.Logr.Debug().DumpObject(o.KosmoClient.Scheme(), &dummyInst, "test instance")
171171

172-
builts, err := template.BuildObjects(o.tmpl.Spec, &dummyInst)
172+
builts, err := template.BuildObjects(o.tmpl.Spec, &dummyInst, "dummy.example.com")
173173
if err != nil {
174174
return fmt.Errorf("failed to build test instance: %w", err)
175175
}

‎internal/controllers/cluster_instance_controller.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ type ClusterInstanceReconciler struct {
2424
client.Client
2525
Recorder record.EventRecorder
2626
Scheme *runtime.Scheme
27+
Domain string
2728

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

5556
// 1. Build Unstructured objects
56-
objects, err := template.BuildObjects(tmpl.Spec, &inst)
57+
objects, err := template.BuildObjects(tmpl.Spec, &inst, r.Domain)
5758
if err != nil {
5859
kosmo.InstanceEventf(r.Recorder, &inst, corev1.EventTypeWarning, "BuildFailed", "Failed to build manifests from Template: %v", err)
5960
return ctrl.Result{}, err

‎internal/controllers/instance_controller.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ type InstanceReconciler struct {
2929
client.Client
3030
Recorder record.EventRecorder
3131
Scheme *runtime.Scheme
32+
Domain string
3233

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

6566
// 1. Build Unstructured objects
66-
objects, err := template.BuildObjects(tmpl.Spec, &inst)
67+
objects, err := template.BuildObjects(tmpl.Spec, &inst, r.Domain)
6768
if err != nil {
6869
kosmo.InstanceEventf(r.Recorder, &inst, corev1.EventTypeWarning, "BuildFailed", "Failed to build manifests from Template: %v", err)
6970
return ctrl.Result{}, err

‎internal/webhooks/instance_webhook.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ func (h *InstanceValidationWebhookHandler) Handle(ctx context.Context, req admis
203203
func dryrunReconcile(ctx context.Context, c client.Client, fieldManager string, inst cosmov1alpha1.InstanceObject, tmpl cosmov1alpha1.TemplateObject) []error {
204204
log := clog.FromContext(ctx).WithCaller()
205205

206-
objects, err := template.BuildObjects(*tmpl.GetSpec(), inst)
206+
objects, err := template.BuildObjects(*tmpl.GetSpec(), inst, "dummy.example.com")
207207
if err != nil {
208208
return []error{err}
209209
}

‎pkg/template/builder.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ type Builder interface {
1515
Build() ([]unstructured.Unstructured, error)
1616
}
1717

18-
func BuildObjects(tmplSpec cosmov1alpha1.TemplateSpec, inst cosmov1alpha1.InstanceObject) (objects []unstructured.Unstructured, err error) {
18+
func BuildObjects(tmplSpec cosmov1alpha1.TemplateSpec, inst cosmov1alpha1.InstanceObject, domain string) (objects []unstructured.Unstructured, err error) {
1919
if tmplSpec.RawYaml != "" {
2020
objects, err = NewRawYAMLBuilder(tmplSpec.RawYaml).
21-
ReplaceDefaultVars(inst).
21+
ReplaceDefaultVars(inst, domain).
2222
ReplaceCustomVars(inst).
2323
Build()
2424
if err != nil {

‎pkg/template/builder_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ spec:
122122
}
123123
for _, tt := range tests {
124124
t.Run(tt.name, func(t *testing.T) {
125-
gotObjects, err := BuildObjects(tt.args.tmplSpec, tt.args.inst)
125+
gotObjects, err := BuildObjects(tt.args.tmplSpec, tt.args.inst, "dummy.example.com")
126126
if (err != nil) != tt.wantErr {
127127
t.Errorf("BuildObjects() error = %v, wantErr %v", err, tt.wantErr)
128128
return

‎pkg/template/rawyaml.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ const (
1515
DefaultVarsInstance = "{{INSTANCE}}"
1616
DefaultVarsNamespace = "{{NAMESPACE}}"
1717
DefaultVarsTemplate = "{{TEMPLATE}}"
18+
DefaultVarsDomain = "{{DOMAIN}}"
1819
)
1920

2021
var (
@@ -47,9 +48,10 @@ func (t *RawYAMLBuilder) Build() ([]unstructured.Unstructured, error) {
4748
return resources, nil
4849
}
4950

50-
func (t *RawYAMLBuilder) ReplaceDefaultVars(inst cosmov1alpha1.InstanceObject) *RawYAMLBuilder {
51+
func (t *RawYAMLBuilder) ReplaceDefaultVars(inst cosmov1alpha1.InstanceObject, domain string) *RawYAMLBuilder {
5152
t.rawYaml = strings.ReplaceAll(t.rawYaml, DefaultVarsInstance, inst.GetName())
5253
t.rawYaml = strings.ReplaceAll(t.rawYaml, DefaultVarsTemplate, inst.GetSpec().Template.Name)
54+
t.rawYaml = strings.ReplaceAll(t.rawYaml, DefaultVarsDomain, domain)
5355

5456
if inst.GetScope() == meta.RESTScopeNamespace {
5557
t.rawYaml = strings.ReplaceAll(t.rawYaml, DefaultVarsNamespace, inst.GetNamespace())

‎pkg/template/rawyaml_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ func TestRawYAMLBuilder_ReplaceDefaultVars(t *testing.T) {
375375
tr := &RawYAMLBuilder{
376376
rawYaml: tt.fields.rawYaml,
377377
}
378-
if got := tr.ReplaceDefaultVars(tt.fields.inst); !reflect.DeepEqual(got, tt.want) {
378+
if got := tr.ReplaceDefaultVars(tt.fields.inst, "dummy.example.com"); !reflect.DeepEqual(got, tt.want) {
379379
t.Errorf("RawYAMLBuilder.ReplaceDefaultVars() = %v, want %v", got, tt.want)
380380
}
381381
})

‎web/dashboard-ui/src/App.tsx

+3-6
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import { ProgressProvider } from "./components/ProgressProvider";
1111
import { AuthenticatorManageDialogContext } from "./views/organisms/AuthenticatorManageDialog";
1212
import { EventDetailDialogContext } from "./views/organisms/EventDetailDialog";
1313
import { PasswordChangeDialogContext } from "./views/organisms/PasswordChangeDialog";
14-
import { UserAddonChangeDialogContext } from "./views/organisms/UserAddonsChangeDialog";
1514
import { UserInfoDialogContext } from "./views/organisms/UserInfoDialog";
1615
import { UserContext } from "./views/organisms/UserModule";
1716
import { UserNameChangeDialogContext } from "./views/organisms/UserNameChangeDialog";
@@ -102,11 +101,9 @@ function App() {
102101
<UserInfoDialogContext.Provider>
103102
<AuthenticatorManageDialogContext.Provider>
104103
<UserNameChangeDialogContext.Provider>
105-
<UserAddonChangeDialogContext.Provider>
106-
<PasswordChangeDialogContext.Provider>
107-
<SwitchApp />
108-
</PasswordChangeDialogContext.Provider>
109-
</UserAddonChangeDialogContext.Provider>
104+
<PasswordChangeDialogContext.Provider>
105+
<SwitchApp />
106+
</PasswordChangeDialogContext.Provider>
110107
</UserNameChangeDialogContext.Provider>
111108
</AuthenticatorManageDialogContext.Provider>
112109
</UserInfoDialogContext.Provider>

‎web/dashboard-ui/src/views/pages/UserPage.tsx

-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ const UserMenu: React.VFC<{ user: User }> = ({ user: us }) => {
102102
<Box>
103103
<IconButton
104104
color="inherit"
105-
disabled={loginUser?.name === us.name}
106105
onClick={(e) => setAnchorEl(e.currentTarget)}
107106
>
108107
<MoreVert fontSize="small" />

‎web/dashboard-ui/src/views/templates/PageTemplate.tsx

-18
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import {
99
Menu as MenuIcon,
1010
Notifications,
1111
ReportProblem,
12-
Settings,
1312
SupervisorAccountTwoTone,
1413
VpnKey,
1514
Warning,
@@ -51,7 +50,6 @@ import { AuthenticatorManageDialogContext } from "../organisms/AuthenticatorMana
5150
import { EventDetailDialogContext } from "../organisms/EventDetailDialog";
5251
import { latestTime } from "../organisms/EventModule";
5352
import { PasswordChangeDialogContext } from "../organisms/PasswordChangeDialog";
54-
import { UserAddonChangeDialogContext } from "../organisms/UserAddonsChangeDialog";
5553
import { UserInfoDialogContext } from "../organisms/UserInfoDialog";
5654
import {
5755
isAdminRole,
@@ -101,8 +99,6 @@ export const PageTemplate: React.FC<
10199
AuthenticatorManageDialogContext.useDispatch();
102100
const passwordChangeDialogDispach = PasswordChangeDialogContext.useDispatch();
103101
const userNameChangeDialogDispach = UserNameChangeDialogContext.useDispatch();
104-
const userAddonChangeDialogDispatch =
105-
UserAddonChangeDialogContext.useDispatch();
106102
const userInfoDialogDispatch = UserInfoDialogContext.useDispatch();
107103
const isAdmin = isAdminUser(loginUser);
108104
const isSignIn = Boolean(loginUser);
@@ -132,12 +128,6 @@ export const PageTemplate: React.FC<
132128
setAnchorEl(null);
133129
};
134130

135-
const changeAddons = () => {
136-
console.log("changeAddons");
137-
userAddonChangeDialogDispatch(true, { user: loginUser! });
138-
setAnchorEl(null);
139-
};
140-
141131
const openUserInfoDialog = () => {
142132
console.log("openUserInfoDialog");
143133
userInfoDialogDispatch(true, {
@@ -443,14 +433,6 @@ export const PageTemplate: React.FC<
443433
<ListItemText>Change DisplayName...</ListItemText>
444434
</MenuItem>
445435
)}
446-
{isSignIn && isAdmin && (
447-
<MenuItem onClick={() => changeAddons()}>
448-
<ListItemIcon>
449-
<Settings fontSize="small" />
450-
</ListItemIcon>
451-
<ListItemText>Change Addons...</ListItemText>
452-
</MenuItem>
453-
)}
454436
<Divider />
455437
{isSignIn && (
456438
<MenuItem onClick={() => logout()}>

0 commit comments

Comments
 (0)