-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds a new package to generate the default agent configuration Related #250 Signed-off-by: wenlin <wenlin.yi@jetstack.io>
- Loading branch information
Showing
3 changed files
with
249 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package configs | ||
|
||
import ( | ||
"fmt" | ||
"io/ioutil" | ||
"path/filepath" | ||
|
||
"github.com/jetstack/preflight/pkg/agent" | ||
"gopkg.in/yaml.v2" | ||
) | ||
|
||
func GetDefaultDataGatherers() ([]agent.DataGatherer, error) { | ||
// This will read the default.yaml and call the getDataGatherers() | ||
filename, err := filepath.Abs("./default.yaml") | ||
if err != nil { | ||
fmt.Print("fail to read the path") | ||
} | ||
|
||
defaultYAML, err := ioutil.ReadFile(filename) | ||
if err != nil { | ||
fmt.Print("fail to read the file") | ||
} | ||
|
||
var dataGatherer []agent.DataGatherer | ||
err = yaml.Unmarshal(defaultYAML, &dataGatherer) | ||
|
||
return dataGatherer, err | ||
} | ||
|
||
func getDataGatherers(yamlFile []byte) ([]agent.DataGatherer, error) { | ||
// this will unmarshal the data gatherer | ||
|
||
// defaultYAML, err := ioutil.ReadFile(yamlFile) | ||
// if err != nil { | ||
// fmt.Print("fail to read the file") | ||
// } | ||
|
||
type ConfigAgentRBACManifests struct { | ||
ClusterRoles []rbac.ClusterRole | ||
// ClusterRoleBindings is a list of crbs for resources which have no include/exclude ns configured | ||
ClusterRoleBindings []rbac.ClusterRoleBinding | ||
// RoleBindings is a list of namespaced bindings to grant permissions when include/exclude ns set | ||
RoleBindings []rbac.RoleBinding | ||
} | ||
|
||
var configAgentRBACManifests ConfigAgentRBACManifests | ||
yaml.Unmarshal(yamlFile, configAgentRBACManifests) | ||
} |
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,144 @@ | ||
# gather k8s apiserver version information | ||
- kind: "k8s-discovery" | ||
name: "k8s-discovery" | ||
# pods data is used in the pods and application_versions packages | ||
- kind: "k8s-dynamic" | ||
name: "k8s/pods" | ||
config: | ||
resource-type: | ||
resource: pods | ||
version: v1 | ||
# gather services for pod readiness probe rules | ||
- kind: "k8s-dynamic" | ||
name: "k8s/services" | ||
config: | ||
resource-type: | ||
resource: services | ||
version: v1 | ||
# gather higher level resources to ensure data to determine ownership is present | ||
- kind: "k8s-dynamic" | ||
name: "k8s/deployments" | ||
config: | ||
resource-type: | ||
version: v1 | ||
resource: deployments | ||
group: apps | ||
- kind: "k8s-dynamic" | ||
name: "k8s/replicasets" | ||
config: | ||
resource-type: | ||
version: v1 | ||
resource: replicasets | ||
group: apps | ||
- kind: "k8s-dynamic" | ||
name: "k8s/statefulsets" | ||
config: | ||
resource-type: | ||
version: v1 | ||
resource: statefulsets | ||
group: apps | ||
- kind: "k8s-dynamic" | ||
name: "k8s/daemonsets" | ||
config: | ||
resource-type: | ||
version: v1 | ||
resource: daemonsets | ||
group: apps | ||
- kind: "k8s-dynamic" | ||
name: "k8s/jobs" | ||
config: | ||
resource-type: | ||
version: v1 | ||
resource: jobs | ||
group: batch | ||
- kind: "k8s-dynamic" | ||
name: "k8s/cronjobs" | ||
config: | ||
resource-type: | ||
version: v1beta1 | ||
resource: cronjobs | ||
group: batch | ||
# gather resources for cert-manager package | ||
- kind: "k8s-dynamic" | ||
name: "k8s/secrets" | ||
config: | ||
resource-type: | ||
version: v1 | ||
resource: secrets | ||
- kind: "k8s-dynamic" | ||
name: "k8s/certificates" | ||
config: | ||
resource-type: | ||
group: cert-manager.io | ||
version: v1 | ||
resource: certificates | ||
- kind: "k8s-dynamic" | ||
name: "k8s/ingresses" | ||
config: | ||
resource-type: | ||
group: networking.k8s.io | ||
version: v1 | ||
resource: ingresses | ||
- kind: "k8s-dynamic" | ||
name: "k8s/certificaterequests" | ||
config: | ||
resource-type: | ||
group: cert-manager.io | ||
version: v1 | ||
resource: certificaterequests | ||
- kind: "k8s-dynamic" | ||
name: "k8s/issuers" | ||
config: | ||
resource-type: | ||
group: cert-manager.io | ||
version: v1 | ||
resource: issuers | ||
- kind: "k8s-dynamic" | ||
name: "k8s/clusterissuers" | ||
config: | ||
resource-type: | ||
group: cert-manager.io | ||
version: v1 | ||
resource: clusterissuers | ||
- kind: "k8s-dynamic" | ||
name: "k8s/googlecasissuers" | ||
config: | ||
resource-type: | ||
group: cas-issuer.jetstack.io | ||
version: v1beta1 | ||
resource: googlecasissuers | ||
- kind: "k8s-dynamic" | ||
name: "k8s/googlecasclusterissuers" | ||
config: | ||
resource-type: | ||
group: cas-issuer.jetstack.io | ||
version: v1beta1 | ||
resource: googlecasclusterissuers | ||
- kind: "k8s-dynamic" | ||
name: "k8s/awspcaissuer" | ||
config: | ||
resource-type: | ||
group: awspca.cert-manager.io | ||
version: v1beta1 | ||
resource: awspcaissuers | ||
- kind: "k8s-dynamic" | ||
name: "k8s/awspcaclusterissuers" | ||
config: | ||
resource-type: | ||
group: awspca.cert-manager.io | ||
version: v1beta1 | ||
resource: awspcaclusterissuers | ||
- kind: "k8s-dynamic" | ||
name: "k8s/mutatingwebhookconfigurations" | ||
config: | ||
resource-type: | ||
group: admissionregistration.k8s.io | ||
version: v1 | ||
resource: mutatingwebhookconfigurations | ||
- kind: "k8s-dynamic" | ||
name: "k8s/validatingwebhookconfigurations" | ||
config: | ||
resource-type: | ||
group: admissionregistration.k8s.io | ||
version: v1 | ||
resource: validatingwebhookconfigurations |
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,57 @@ | ||
package configs | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/jetstack/preflight/pkg/agent" | ||
"github.com/maxatome/go-testdeep/td" | ||
) | ||
|
||
func TestParseDatagatherers(t *testing.T) { | ||
testCases := []struct { | ||
description string | ||
expectedAgentDataGatherers []agent.DataGatherer | ||
inputYaml string | ||
}{ | ||
{ | ||
description: "simple data gatherer unmarshal", | ||
inputYaml: ` | ||
- kind: "k8s-dynamic" | ||
name: "k8s/pods" | ||
config: | ||
resource-type: | ||
resource: pods | ||
version: v1 | ||
# gather services for pod readiness probe rules | ||
- kind: "k8s-dynamic" | ||
name: "k8s/services" | ||
config: | ||
resource-type: | ||
resource: services | ||
version: v1`, | ||
expectedAgentDataGatherers: []agent.DataGatherer{ | ||
{ | ||
Kind: "k8s-dynamic", | ||
Name: "k8s/pods", | ||
DataPath: "", | ||
Config: nil, | ||
}, | ||
{ | ||
Kind: "k8s-dynamic", | ||
Name: "k8s/services", | ||
DataPath: "", | ||
Config: nil, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
for _, input := range testCases { | ||
got, err := getDataGatherers(([]byte(input.inputYaml))) | ||
if err != nil { | ||
|
||
} | ||
|
||
td.Cmp(t, input.expectedAgentDataGatherers, got) | ||
} | ||
} |