-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: kubelet checks via config resource
Signed-off-by: chenk <[email protected]>
- Loading branch information
1 parent
ca4eec1
commit 4c34653
Showing
8 changed files
with
204 additions
and
70 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 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,63 @@ | ||
package jobs | ||
|
||
import ( | ||
corev1 "k8s.io/api/core/v1" | ||
rbacv1 "k8s.io/api/rbac/v1" | ||
"sigs.k8s.io/yaml" | ||
) | ||
|
||
const ( | ||
clusterRole = "node-collector-cr" | ||
roleBinding = "node-collector-rb" | ||
serviceAccount = "node-collector-sa" | ||
) | ||
|
||
type AuthOption func(*AuthBuilder) | ||
|
||
func WithServiceAccountNamespace(namespace string) AuthOption { | ||
return func(a *AuthBuilder) { | ||
a.namespace = namespace | ||
} | ||
} | ||
|
||
func GetAuth(opts ...AuthOption) (*rbacv1.ClusterRole, *rbacv1.ClusterRoleBinding, *corev1.ServiceAccount, error) { | ||
ab := &AuthBuilder{} | ||
for _, opt := range opts { | ||
opt(ab) | ||
} | ||
return ab.build() | ||
} | ||
|
||
type AuthBuilder struct { | ||
namespace string | ||
} | ||
|
||
func (b *AuthBuilder) build() (*rbacv1.ClusterRole, *rbacv1.ClusterRoleBinding, *corev1.ServiceAccount, error) { | ||
// load ClusterRole, ClusterRoleBinding, ServiceAccount | ||
template := getTemplate(clusterRole) | ||
var cr rbacv1.ClusterRole | ||
err := yaml.Unmarshal([]byte(template), &cr) | ||
if err != nil { | ||
return nil, nil, nil, err | ||
} | ||
template = getTemplate(roleBinding) | ||
var rb rbacv1.ClusterRoleBinding | ||
err = yaml.Unmarshal([]byte(template), &rb) | ||
if err != nil { | ||
return nil, nil, nil, err | ||
} | ||
if len(b.namespace) > 0 { | ||
rb.Subjects[0].Namespace = b.namespace | ||
} | ||
template = getTemplate(serviceAccount) | ||
var sa corev1.ServiceAccount | ||
err = yaml.Unmarshal([]byte(template), &sa) | ||
if err != nil { | ||
return nil, nil, nil, err | ||
} | ||
if len(b.namespace) > 0 { | ||
sa.Namespace = b.namespace | ||
} | ||
return &cr, &rb, &sa, 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
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,12 @@ | ||
--- | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: ClusterRole | ||
metadata: | ||
name: node-collector-cr | ||
rules: | ||
- apiGroups: | ||
- "" | ||
resources: | ||
- nodes/proxy | ||
verbs: | ||
- get |
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,16 @@ | ||
--- | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: ClusterRoleBinding | ||
metadata: | ||
name: node-collector-rb | ||
labels: | ||
app.kubernetes.io/version: 0.17.1 | ||
app.kubernetes.io/managed-by: kubectl | ||
roleRef: | ||
apiGroup: rbac.authorization.k8s.io | ||
kind: ClusterRole | ||
name: node-collector-cr | ||
subjects: | ||
- kind: ServiceAccount | ||
name: node-collector-sa | ||
namespace: trivy-temp |
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,8 @@ | ||
--- | ||
apiVersion: v1 | ||
kind: ServiceAccount | ||
metadata: | ||
name: node-collector-sa | ||
namespace: trivy-temp | ||
labels: | ||
app.kubernetes.io/managed-by: kubectl |