forked from harvester/harvester
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move built-in templates to the public namespace Restructure built-in resource creation code
- Loading branch information
1 parent
46ee218
commit d2ba5fa
Showing
7 changed files
with
81 additions
and
30 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package data | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/harvester/harvester/pkg/config" | ||
) | ||
|
||
// Init adds built-in resources | ||
func Init(ctx context.Context, mgmtCtx *config.Management) error { | ||
if err := createCRDs(ctx, mgmtCtx.RestConfig); err != nil { | ||
return err | ||
} | ||
if err := createPublicNamespace(mgmtCtx); err != nil { | ||
return err | ||
} | ||
if err := createTemplates(mgmtCtx, publicNamespace); err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} |
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,49 @@ | ||
package data | ||
|
||
import ( | ||
v1 "k8s.io/api/core/v1" | ||
rbacv1 "k8s.io/api/rbac/v1" | ||
"k8s.io/apimachinery/pkg/api/errors" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
|
||
"github.com/harvester/harvester/pkg/config" | ||
) | ||
|
||
const ( | ||
publicNamespace = "harvester-public" | ||
) | ||
|
||
func createPublicNamespace(mgmtCtx *config.Management) error { | ||
namespaces := mgmtCtx.CoreFactory.Core().V1().Namespace() | ||
roleBindings := mgmtCtx.RbacFactory.Rbac().V1().RoleBinding() | ||
|
||
// Create harvester-public namespace | ||
if _, err := namespaces.Create(&v1.Namespace{ | ||
ObjectMeta: metav1.ObjectMeta{Name: publicNamespace}, | ||
}); err != nil && !errors.IsAlreadyExists(err) { | ||
return err | ||
} | ||
// All authenticated users are readable in the public namespace | ||
if _, err := roleBindings.Create(&rbacv1.RoleBinding{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "harvester-public", | ||
Namespace: publicNamespace, | ||
}, | ||
RoleRef: rbacv1.RoleRef{ | ||
APIGroup: rbacv1.GroupName, | ||
Kind: "ClusterRole", | ||
Name: "view", | ||
}, | ||
Subjects: []rbacv1.Subject{ | ||
{ | ||
APIGroup: rbacv1.GroupName, | ||
Kind: rbacv1.GroupKind, | ||
Name: "system:authenticated", | ||
}, | ||
}, | ||
}); err != nil && !errors.IsAlreadyExists(err) { | ||
return err | ||
} | ||
|
||
return nil | ||
} |
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